From 3d410e6d0be545046374de315e409cce859f6260 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Tue, 13 Jun 2023 08:25:57 +0800 Subject: [PATCH] fix --- app/chain/__init__.py | 12 ++++++-- app/chain/download.py | 3 ++ app/chain/user_message.py | 2 ++ app/modules/__init__.py | 43 +++++++++++++++++++--------- app/modules/qbittorrent/__init__.py | 11 ++++++- app/modules/subtitle/__init__.py | 30 +++++++++++++++++++ app/modules/transmission/__init__.py | 10 ++++++- app/modules/words/__init__.py | 30 +++++++++++++++++++ 8 files changed, 123 insertions(+), 18 deletions(-) create mode 100644 app/modules/subtitle/__init__.py create mode 100644 app/modules/words/__init__.py diff --git a/app/chain/__init__.py b/app/chain/__init__.py index aac9759d..d9f6c481 100644 --- a/app/chain/__init__.py +++ b/app/chain/__init__.py @@ -73,6 +73,9 @@ class ChainBase(AbstractSingleton, metaclass=Singleton): tmdbid: int = None) -> Optional[MediaInfo]: return self.run_module("recognize_media", meta=meta, mtype=mtype, tmdbid=tmdbid) + def obtain_image(self, mediainfo: MediaInfo) -> Optional[MediaInfo]: + return self.run_module("obtain_image", mediainfo=mediainfo) + def douban_info(self, doubanid: str) -> Optional[dict]: return self.run_module("douban_info", doubanid=doubanid) @@ -82,9 +85,6 @@ class ChainBase(AbstractSingleton, metaclass=Singleton): def webhook_parser(self, body: Any, form: Any, args: Any) -> Optional[dict]: return self.run_module("webhook_parser", body=body, form=form, args=args) - def obtain_image(self, mediainfo: MediaInfo) -> Optional[MediaInfo]: - return self.run_module("obtain_image", mediainfo=mediainfo) - def search_medias(self, meta: MetaBase) -> Optional[List[MediaInfo]]: return self.run_module("search_medias", meta=meta) @@ -103,6 +103,9 @@ class ChainBase(AbstractSingleton, metaclass=Singleton): episodes: Set[int] = None) -> Optional[Tuple[Optional[str], str]]: return self.run_module("download", torrent_path=torrent_path, cookie=cookie, episodes=episodes) + def download_added(self, context: Context, torrent_path: Path) -> None: + return self.run_module("download_added", context=context, torrent_path=torrent_path) + def list_torrents(self, status: TorrentStatus = None, hashs: Union[list, str] = None) -> Optional[List[dict]]: return self.run_module("list_torrents", status=status, hashs=hashs) @@ -112,6 +115,9 @@ class ChainBase(AbstractSingleton, metaclass=Singleton): def transfer_completed(self, hashs: Union[str, list], transinfo: dict) -> None: return self.run_module("transfer_completed", hashs=hashs, transinfo=transinfo) + def remove_torrents(self, hashs: Union[str, list]) -> bool: + return self.run_module("remove_torrents", hashs=hashs) + def media_exists(self, mediainfo: MediaInfo) -> Optional[dict]: return self.run_module("media_exists", mediainfo=mediainfo) diff --git a/app/chain/download.py b/app/chain/download.py index 5412bcc4..50ccb2b5 100644 --- a/app/chain/download.py +++ b/app/chain/download.py @@ -117,7 +117,10 @@ class DownloadChain(ChainBase): if _hash: # 下载成功 downloaded_list.append(_context) + # 发送消息 self.post_download_message(meta=_meta, mediainfo=_media, torrent=_torrent, userid=userid) + # 下载成功后处理 + self.download_added(context=_context, torrent_path=_torrent_file) else: # 下载失败 logger.error(f"{_media.get_title_string()} 添加下载任务失败:" diff --git a/app/chain/user_message.py b/app/chain/user_message.py index 97c1d100..3af815d1 100644 --- a/app/chain/user_message.py +++ b/app/chain/user_message.py @@ -203,6 +203,8 @@ class UserMessageChain(ChainBase): return # 下载成功,发送通知 self.downloadchain.post_download_message(meta=meta, mediainfo=self._current_media, torrent=torrent) + # 下载成功后处理 + self.download_added(context=context, torrent_path=torrent_file) elif text.lower() == "p": # 上一页 diff --git a/app/modules/__init__.py b/app/modules/__init__.py index 63aa9c1e..4f0d2ef6 100644 --- a/app/modules/__init__.py +++ b/app/modules/__init__.py @@ -35,7 +35,7 @@ class _ModuleBase(metaclass=ABCMeta): 识别前的预处理 :param title: 标题 :param subtitle: 副标题 - :return: 处理后的标题、副标题,注意如果返回None,有可能是没有对应的处理模块,应无视结果 + :return: 处理后的标题、副标题,该方法可被多个模块同时处理 """ pass @@ -51,6 +51,14 @@ class _ModuleBase(metaclass=ABCMeta): """ pass + def obtain_image(self, mediainfo: MediaInfo) -> Optional[MediaInfo]: + """ + 获取图片 + :param mediainfo: 识别的媒体信息 + :return: 更新后的媒体信息,该方法可被多个模块同时处理 + """ + pass + def douban_info(self, doubanid: str) -> Optional[dict]: """ 获取豆瓣信息 @@ -82,14 +90,6 @@ class _ModuleBase(metaclass=ABCMeta): """ pass - def obtain_image(self, mediainfo: MediaInfo) -> Optional[MediaInfo]: - """ - 获取图片 - :param mediainfo: 识别的媒体信息 - :return: 更新后的媒体信息,该方法可被多个模块同时处理 - """ - pass - def search_medias(self, meta: MetaBase) -> Optional[List[MediaInfo]]: """ 搜索媒体信息 @@ -98,6 +98,14 @@ class _ModuleBase(metaclass=ABCMeta): """ pass + def media_exists(self, mediainfo: MediaInfo) -> Optional[dict]: + """ + 判断媒体文件是否存在 + :param mediainfo: 识别的媒体信息 + :return: 如不存在返回None,存在时返回信息,包括每季已存在所有集{type: movie/tv, seasons: {season: [episodes]}} + """ + pass + def search_torrents(self, mediainfo: Optional[MediaInfo], sites: List[CommentedMap], keyword: str = None) -> Optional[List[TorrentInfo]]: """ @@ -138,6 +146,15 @@ class _ModuleBase(metaclass=ABCMeta): """ pass + def download_added(self, context: Context, torrent_path: Path) -> None: + """ + 添加下载任务后的处理 + :param context: 上下文,包括识别信息、媒体信息、种子信息 + :param torrent_path: 种子文件地址 + :return: None,该方法可被多个模块同时处理 + """ + pass + def list_torrents(self, status: TorrentStatus = None, hashs: Union[list, str] = None) -> Optional[List[dict]]: """ @@ -166,11 +183,11 @@ class _ModuleBase(metaclass=ABCMeta): """ pass - def media_exists(self, mediainfo: MediaInfo) -> Optional[dict]: + def remove_torrents(self, hashs: Union[str, list]) -> bool: """ - 判断媒体文件是否存在 - :param mediainfo: 识别的媒体信息 - :return: 如不存在返回None,存在时返回信息,包括每季已存在所有集{type: movie/tv, seasons: {season: [episodes]}} + 删除下载器种子 + :param hashs: 种子Hash + :return: bool """ pass diff --git a/app/modules/qbittorrent/__init__.py b/app/modules/qbittorrent/__init__.py index c648d2ba..04c7ec04 100644 --- a/app/modules/qbittorrent/__init__.py +++ b/app/modules/qbittorrent/__init__.py @@ -139,5 +139,14 @@ class QbittorrentModule(_ModuleBase): self.qbittorrent.set_torrents_tag(ids=hashs, tags=['已整理']) # 移动模式删除种子 if settings.TRANSFER_TYPE == "move": - if self.qbittorrent.delete_torrents(delete_file=True, ids=hashs): + if self.remove_torrents(hashs): logger.info(f"移动模式删除种子成功:{hashs} ") + + def remove_torrents(self, hashs: Union[str, list]) -> bool: + """ + 删除下载器种子 + :param hashs: 种子Hash + :return: bool + """ + return self.qbittorrent.delete_torrents(delete_file=True, ids=hashs) + diff --git a/app/modules/subtitle/__init__.py b/app/modules/subtitle/__init__.py new file mode 100644 index 00000000..2b3885aa --- /dev/null +++ b/app/modules/subtitle/__init__.py @@ -0,0 +1,30 @@ +from pathlib import Path +from typing import Tuple, Union + +from app.core.context import Context +from app.modules import _ModuleBase + + +class SubtitleModule(_ModuleBase): + """ + 字幕下载模块 + """ + + def init_module(self) -> None: + pass + + def init_setting(self) -> Tuple[str, Union[str, bool]]: + pass + + def stop(self) -> None: + pass + + def download_added(self, context: Context, torrent_path: Path) -> None: + """ + 添加下载任务成功后,从站点下载字幕 + :param context: 上下文,包括识别信息、媒体信息、种子信息 + :param torrent_path: 种子文件地址 + :return: None,该方法可被多个模块同时处理 + """ + pass + diff --git a/app/modules/transmission/__init__.py b/app/modules/transmission/__init__.py index 9c37cb30..3e05d7e5 100644 --- a/app/modules/transmission/__init__.py +++ b/app/modules/transmission/__init__.py @@ -122,5 +122,13 @@ class TransmissionModule(_ModuleBase): self.transmission.set_torrent_tag(ids=hashs, tags=['已整理']) # 移动模式删除种子 if settings.TRANSFER_TYPE == "move": - if self.transmission.delete_torrents(delete_file=True, ids=hashs): + if self.remove_torrents(hashs): logger.info(f"移动模式删除种子成功:{hashs} ") + + def remove_torrents(self, hashs: Union[str, list]) -> bool: + """ + 删除下载器种子 + :param hashs: 种子Hash + :return: bool + """ + return self.transmission.delete_torrents(delete_file=True, ids=hashs) diff --git a/app/modules/words/__init__.py b/app/modules/words/__init__.py new file mode 100644 index 00000000..204f7d66 --- /dev/null +++ b/app/modules/words/__init__.py @@ -0,0 +1,30 @@ +from pathlib import Path +from typing import Tuple, Union + +from app.core.context import Context +from app.modules import _ModuleBase + + +class WordseModule(_ModuleBase): + """ + 字幕下载模块 + """ + + def init_module(self) -> None: + pass + + def init_setting(self) -> Tuple[str, Union[str, bool]]: + pass + + def stop(self) -> None: + pass + + def prepare_recognize(self, title: str, + subtitle: str = None) -> Tuple[str, str]: + """ + 处理各类特别命名,以便识别 + :param title: 标题 + :param subtitle: 副标题 + :return: 处理后的标题、副标题,该方法可被多个模块同时处理 + """ + pass