diff --git a/app/chain/search.py b/app/chain/search.py index b9a03b2e..4d472b93 100644 --- a/app/chain/search.py +++ b/app/chain/search.py @@ -47,7 +47,7 @@ class SearchChain(ChainBase): return [] # 补充媒体信息 if not mediainfo.names: - mediainfo: MediaInfo = self.recognize_media(meta=MetaInfo(title=mediainfo.get_title_string()), + mediainfo: MediaInfo = self.recognize_media(meta=meta, mtype=mediainfo.type, tmdbid=mediainfo.tmdb_id) if not mediainfo: @@ -90,8 +90,14 @@ class SearchChain(ChainBase): logger.info(f'{mediainfo.title} 匹配到资源:{torrent.site_name} - {torrent.title}') _match_torrents.append(torrent) continue + # 识别前预处理 + result: Optional[tuple] = self.prepare_recognize(title=torrent.title, subtitle=torrent.description) + if result: + title, subtitle = result + else: + title, subtitle = torrent.title, torrent.description # 识别 - torrent_meta = MetaInfo(torrent.title, torrent.description) + torrent_meta = MetaInfo(title=title, subtitle=subtitle) # 比对年份 if torrent_meta.year and mediainfo.year: if mediainfo.type == MediaType.TV: diff --git a/app/chain/subscribe.py b/app/chain/subscribe.py index d573fb2a..5c0f95fe 100644 --- a/app/chain/subscribe.py +++ b/app/chain/subscribe.py @@ -62,7 +62,7 @@ class SubscribeChain(ChainBase): if not kwargs.get('total_episode'): if not mediainfo.seasons: # 补充媒体信息 - mediainfo: MediaInfo = self.recognize_media(meta=MetaInfo(title=mediainfo.get_title_string()), + mediainfo: MediaInfo = self.recognize_media(meta=metainfo, mtype=mediainfo.type, tmdbid=mediainfo.tmdb_id) if not mediainfo: @@ -188,8 +188,15 @@ class SubscribeChain(ChainBase): logger.warn(f'{indexer.get("name")} 没有符合过滤条件的资源') continue for torrent in torrents: + # 识别前预处理 + result: Optional[tuple] = self.prepare_recognize(title=torrent.title, + subtitle=torrent.description) + if result: + title, subtitle = result + else: + title, subtitle = torrent.title, torrent.description # 识别 - meta = MetaInfo(torrent.title, torrent.description) + meta = MetaInfo(title=title, subtitle=subtitle) # 识别媒体信息 mediainfo: MediaInfo = self.recognize_media(meta=meta) if not mediainfo: diff --git a/app/chain/transfer.py b/app/chain/transfer.py index 850112ee..25896047 100644 --- a/app/chain/transfer.py +++ b/app/chain/transfer.py @@ -47,8 +47,16 @@ class TransferChain(ChainBase): if not torrents: logger.error(f"没有获取到种子,参数:{arg_str}") return False + # 识别前预处理 + result: Optional[tuple] = self.prepare_recognize(title=torrents[0].get("title")) + if result: + title, subtitle = result + else: + title, subtitle = torrents[0].get("title"), None + # 识别 + meta = MetaInfo(title=title, subtitle=subtitle) # 查询媒体信息 - arg_mediainfo = self.recognize_media(meta=MetaInfo(torrents[0].get("title")), tmdbid=int(tmdbid)) + arg_mediainfo = self.recognize_media(meta=meta) else: arg_mediainfo = None logger.info("开始执行下载器文件转移 ...") @@ -61,13 +69,19 @@ class TransferChain(ChainBase): logger.info(f"获取到 {len(torrents)} 个已完成的下载任务") # 识别 for torrent in torrents: + # 识别前预处理 + result: Optional[tuple] = self.prepare_recognize(title=torrent.get("title")) + if result: + title, subtitle = result + else: + title, subtitle = torrent.get("title"), None # 识别元数据 - meta: MetaBase = MetaInfo(torrent.get("title")) + meta: MetaBase = MetaInfo(title=title, subtitle=subtitle) if not meta.get_name(): - logger.warn(f'未识别到元数据,标题:{torrent.get("title")}') + logger.warn(f'未识别到元数据,标题:{title}') continue - # 识别媒体信息 if not arg_mediainfo: + # 识别媒体信息 mediainfo: MediaInfo = self.recognize_media(meta=meta) if not mediainfo: logger.warn(f'未识别到媒体信息,标题:{torrent.get("title")}') @@ -95,9 +109,11 @@ class TransferChain(ChainBase): self.scrape_metadata(path=transferinfo.get('target_path'), mediainfo=mediainfo) # 移动模式删除种子 if settings.TRANSFER_TYPE == "move": - result = self.remove_torrents(hashs=torrent.get("hash")) - if result: + result2 = self.remove_torrents(hashs=torrent.get("hash")) + if result2: logger.info(f"移动模式删除种子成功:{torrent.get('title')} ") + # 刷新媒体库 + self.refresh_mediaserver(mediainfo=mediainfo, file_path=transferinfo.get('target_path')) # 发送通知 self.__send_transfer_message(meta=meta, mediainfo=mediainfo, transferinfo=transferinfo) diff --git a/app/chain/user_message.py b/app/chain/user_message.py index 2329d28f..422d0278 100644 --- a/app/chain/user_message.py +++ b/app/chain/user_message.py @@ -167,7 +167,15 @@ class UserMessageChain(ChainBase): context: Context = cache_list[int(text) - 1] torrent: TorrentInfo = context.torrent_info logger.info(f"开始下载种子:{torrent.title} - {torrent.enclosure}") - meta: MetaBase = MetaInfo(torrent.title) + # 识别前预处理 + result: Optional[tuple] = self.prepare_recognize(title=torrent.title, + subtitle=torrent.description) + if result: + title, subtitle = result + else: + title, subtitle = torrent.title, torrent.description + # 识别 + meta = MetaInfo(title=title, subtitle=subtitle) torrent_file, _, _, _, error_msg = self.torrent.download_torrent( url=torrent.enclosure, cookie=torrent.site_cookie, diff --git a/app/command.py b/app/command.py index 78f44f95..41c9cd6e 100644 --- a/app/command.py +++ b/app/command.py @@ -82,7 +82,7 @@ class Command(metaclass=Singleton): # 处理链 self.chain = CommandChian() # 广播注册命令 - self.chain.run_module("register_commands", commands=self.get_commands()) + self.chain.register_commands(commands=self.get_commands()) # 消息处理线程 self._thread = Thread(target=self.__run) # 启动事件处理线程