From 28db4881d7a7f7d09ddf2d9f2f1f8ec3956172a1 Mon Sep 17 00:00:00 2001 From: k1z <1911518271@qq.com> Date: Mon, 19 May 2025 10:05:39 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E8=AF=86=E5=88=AB=E7=BC=93=E5=AD=98=E7=A7=8D=E5=AD=90=E7=9A=84?= =?UTF-8?q?bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/chain/subscribe.py | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/app/chain/subscribe.py b/app/chain/subscribe.py index fb0f5176..e829ecf8 100644 --- a/app/chain/subscribe.py +++ b/app/chain/subscribe.py @@ -559,6 +559,16 @@ class SubscribeChain(ChainBase, metaclass=Singleton): with self._rlock: logger.debug(f"match lock acquired at {datetime.now()}") + + # 预处理:先识别所有未识别的种子 + for domain, contexts in torrents.items(): + for context in contexts: + torrent_meta = context.meta_info + torrent_mediainfo = context.media_info + # 如果种子未识别,先进行识别 + if not torrent_mediainfo or (not torrent_mediainfo.tmdb_id and not torrent_mediainfo.douban_id): + context.media_info = self.recognize_media(meta=torrent_meta) + # 所有订阅 subscribes = self.subscribeoper.list(self.get_states_for_search('R')) # 遍历订阅 @@ -641,30 +651,6 @@ class SubscribeChain(ChainBase, metaclass=Singleton): # 媒体信息需要重新识别 torrent_mediainfo = None - # 先判断是否有没识别的种子,否则重新识别 - if not torrent_mediainfo \ - or (not torrent_mediainfo.tmdb_id and not torrent_mediainfo.douban_id): - # 重新识别媒体信息 - torrent_mediainfo = self.recognize_media(meta=torrent_meta, - episode_group=subscribe.episode_group) - if torrent_mediainfo: - # 更新种子缓存 - context.media_info = torrent_mediainfo - else: - # 通过标题匹配兜底 - logger.warn( - f'{torrent_info.site_name} - {torrent_info.title} 重新识别失败,尝试通过标题匹配...') - if self.torrenthelper.match_torrent(mediainfo=mediainfo, - torrent_meta=torrent_meta, - torrent=torrent_info): - # 匹配成功 - logger.info( - f'{mediainfo.title_year} 通过标题匹配到可选资源:{torrent_info.site_name} - {torrent_info.title}') - torrent_mediainfo = mediainfo - context.media_info = torrent_mediainfo - else: - continue - # 直接比对媒体信息 if torrent_mediainfo and (torrent_mediainfo.tmdb_id or torrent_mediainfo.douban_id): if torrent_mediainfo.type != mediainfo.type: From 27d9f910ff8e1514166327f3326e35065c017c3e Mon Sep 17 00:00:00 2001 From: k1z <1911518271@qq.com> Date: Mon, 19 May 2025 10:35:09 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E8=AF=86=E5=88=AB=E7=BC=93=E5=AD=98=E7=A7=8D=E5=AD=90=E7=9A=84?= =?UTF-8?q?bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/chain/subscribe.py | 71 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 58 insertions(+), 13 deletions(-) diff --git a/app/chain/subscribe.py b/app/chain/subscribe.py index e829ecf8..63d97a02 100644 --- a/app/chain/subscribe.py +++ b/app/chain/subscribe.py @@ -559,18 +559,34 @@ class SubscribeChain(ChainBase, metaclass=Singleton): with self._rlock: logger.debug(f"match lock acquired at {datetime.now()}") - - # 预处理:先识别所有未识别的种子 - for domain, contexts in torrents.items(): - for context in contexts: - torrent_meta = context.meta_info - torrent_mediainfo = context.media_info - # 如果种子未识别,先进行识别 - if not torrent_mediainfo or (not torrent_mediainfo.tmdb_id and not torrent_mediainfo.douban_id): - context.media_info = self.recognize_media(meta=torrent_meta) - # 所有订阅 subscribes = self.subscribeoper.list(self.get_states_for_search('R')) + + # 预识别所有未识别的种子,并标记是否已识别过 + processed_torrents = {} + for domain, contexts in torrents.items(): + processed_torrents[domain] = [] + for context in contexts: + # 复制上下文避免修改原始数据 + _context = copy.deepcopy(context) + torrent_meta = _context.meta_info + torrent_mediainfo = _context.media_info + torrent_info = _context.torrent_info + + # 标记是否已经尝试过识别(初始为False) + _context._recognized = False + + # 如果种子未识别,尝试识别 + if not torrent_mediainfo or (not torrent_mediainfo.tmdb_id and not torrent_mediainfo.douban_id): + torrent_mediainfo = self.recognize_media(meta=torrent_meta) + if torrent_mediainfo: + # 更新种子缓存 + _context.media_info = torrent_mediainfo + # 标记为已尝试识别 + _context._recognized = True + + processed_torrents[domain].append(_context) + # 遍历订阅 for subscribe in subscribes: if global_vars.is_system_stopped: @@ -614,9 +630,9 @@ class SubscribeChain(ChainBase, metaclass=Singleton): else: custom_words_list = None - # 遍历缓存种子 + # 遍历预识别后的种子 _match_context = [] - for domain, contexts in torrents.items(): + for domain, contexts in processed_torrents.items(): if global_vars.is_system_stopped: break if domains and domain not in domains: @@ -649,7 +665,36 @@ class SubscribeChain(ChainBase, metaclass=Singleton): # 更新元数据缓存 context.meta_info = torrent_meta # 媒体信息需要重新识别 - torrent_mediainfo = None + need_reprocess = None + # 重置识别标记 + _context._recognized = False + + # 重新识别媒体信息(仅当有自定义识别词或尚未尝试识别时才需要) + if need_reprocess or (not _context._recognized and + (not torrent_mediainfo or + (not torrent_mediainfo.tmdb_id and not torrent_mediainfo.douban_id))): + torrent_mediainfo = self.recognize_media(meta=torrent_meta, + episode_group=subscribe.episode_group) + if torrent_mediainfo: + # 更新种子缓存 + _context.media_info = torrent_mediainfo + # 标记为已尝试识别 + _context._recognized = True + + # 如果仍然没有识别到媒体信息,尝试标题匹配 + if not torrent_mediainfo or (not torrent_mediainfo.tmdb_id and not torrent_mediainfo.douban_id): + logger.warn( + f'{torrent_info.site_name} - {torrent_info.title} 重新识别失败,尝试通过标题匹配...') + if self.torrenthelper.match_torrent(mediainfo=mediainfo, + torrent_meta=torrent_meta, + torrent=torrent_info): + # 匹配成功 + logger.info( + f'{mediainfo.title_year} 通过标题匹配到可选资源:{torrent_info.site_name} - {torrent_info.title}') + torrent_mediainfo = mediainfo + _context.media_info = torrent_mediainfo + else: + continue # 直接比对媒体信息 if torrent_mediainfo and (torrent_mediainfo.tmdb_id or torrent_mediainfo.douban_id):