From dc41f4946a5dc1f2b347cab77bf053c73b07a4ce Mon Sep 17 00:00:00 2001 From: jxxghp Date: Fri, 22 Sep 2023 12:52:40 +0800 Subject: [PATCH] fix bug --- app/chain/search.py | 25 +++++++++++++------------ app/chain/subscribe.py | 24 ++++-------------------- 2 files changed, 17 insertions(+), 32 deletions(-) diff --git a/app/chain/search.py b/app/chain/search.py index 6d1fe4056..4b9389d34 100644 --- a/app/chain/search.py +++ b/app/chain/search.py @@ -141,10 +141,13 @@ def process(self, mediainfo: MediaInfo, if result is not None: torrents = result if not torrents: - logger.warn(f'{keyword or mediainfo.title} 没有符合过滤条件的资源') + logger.warn(f'{keyword or mediainfo.title} 没有符合优先级规则的资源') return [] # 使用默认过滤规则再次过滤 - torrents = self.filter_torrents_by_default_rule(torrents, keyword, mediainfo) + torrents = self.filter_torrents_by_default_rule(torrents) + if not torrents: + logger.warn(f'{keyword or mediainfo.title} 没有符合默认过滤规则的资源') + return [] # 匹配的资源 _match_torrents = [] # 总数 @@ -312,15 +315,16 @@ def __search_all_sites(self, mediainfo: Optional[MediaInfo] = None, return results def filter_torrents_by_default_rule(self, - torrents: List[TorrentInfo], - keyword: str, - mediainfo: MediaInfo) -> List[TorrentInfo]: + torrents: List[TorrentInfo]) -> List[TorrentInfo]: + + # 取默认过滤规则 + default_include_exclude = self.systemconfig.get(SystemConfigKey.DefaultIncludeExcludeFilter) or {} + if not default_include_exclude: + return torrents + include = default_include_exclude.get("include") + exclude = default_include_exclude.get("exclude") new_torrents = [] for torrent in torrents: - # 取默认过滤规则 - default_include_exclude = self.systemconfig.get(SystemConfigKey.DefaultIncludeExcludeFilter) or {} - include = default_include_exclude.get("include") - exclude = default_include_exclude.get("exclude") # 包含 if include: if not re.search(r"%s" % include, @@ -334,7 +338,4 @@ def filter_torrents_by_default_rule(self, logger.info(f"{torrent.title} 匹配排除规则 {exclude}") continue new_torrents.append(torrent) - if not new_torrents: - logger.warn(f'{keyword or mediainfo.title} 没有符合过滤条件的资源') - return [] return new_torrents diff --git a/app/chain/subscribe.py b/app/chain/subscribe.py index 37a9a2219..fac2771fd 100644 --- a/app/chain/subscribe.py +++ b/app/chain/subscribe.py @@ -285,22 +285,6 @@ def search(self, sid: int = None, state: str = 'N', manual: bool = False): torrent_meta = context.meta_info torrent_info = context.torrent_info torrent_mediainfo = context.media_info - # 包含与排除规则 - default_include_exclude = self.systemconfig.get(SystemConfigKey.DefaultIncludeExcludeFilter) or {} - include = subscribe.include or default_include_exclude.get("include") - exclude = subscribe.exclude or default_include_exclude.get("exclude") - # 包含 - if include: - if not re.search(r"%s" % include, - f"{torrent_info.title} {torrent_info.description}", re.I): - logger.info(f"{torrent_info.title} 不匹配包含规则 {include}") - continue - # 排除 - if exclude: - if re.search(r"%s" % exclude, - f"{torrent_info.title} {torrent_info.description}", re.I): - logger.info(f"{torrent_info.title} 匹配排除规则 {exclude}") - continue # 非洗版 if not subscribe.best_version: # 如果是电视剧过滤掉已经下载的集数 @@ -493,6 +477,10 @@ def match(self, torrents: Dict[str, List[Context]]): } else: no_exists = {} + # 包含与排除规则 + default_include_exclude = self.systemconfig.get(SystemConfigKey.DefaultIncludeExcludeFilter) or {} + include = subscribe.include or default_include_exclude.get("include") + exclude = subscribe.exclude or default_include_exclude.get("exclude") # 遍历缓存种子 _match_context = [] for domain, contexts in torrents.items(): @@ -564,10 +552,6 @@ def match(self, torrents: Dict[str, List[Context]]): if torrent_meta.episode_list: logger.info(f'{subscribe.name} 正在洗版,{torrent_info.title} 不是整季') continue - # 包含与排除规则 - default_include_exclude = self.systemconfig.get(SystemConfigKey.DefaultIncludeExcludeFilter) or {} - include = subscribe.include or default_include_exclude.get("include") - exclude = subscribe.exclude or default_include_exclude.get("exclude") # 包含 if include: if not re.search(r"%s" % include,