From 219690afc06c503d2d59b017b5553b791c420f82 Mon Sep 17 00:00:00 2001 From: mayun110 Date: Fri, 22 Sep 2023 09:10:58 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix=20=E5=9C=A8=E6=90=9C=E7=B4=A2=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E4=B8=AD=20=E9=BB=98=E8=AE=A4=E8=BF=87=E6=BB=A4?= =?UTF-8?q?=E8=A7=84=E5=88=99=E6=97=A0=E6=95=88=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/chain/search.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/app/chain/search.py b/app/chain/search.py index 9eb93dd0..0f1c216f 100644 --- a/app/chain/search.py +++ b/app/chain/search.py @@ -1,4 +1,5 @@ import pickle +import re from concurrent.futures import ThreadPoolExecutor, as_completed from datetime import datetime from typing import Dict @@ -129,7 +130,7 @@ class SearchChain(ChainBase): return [] # 过滤种子 if filter_rule is None: - # 取默认过滤规则 + # 取搜索优先级规则 filter_rule = self.systemconfig.get(SystemConfigKey.SearchFilterRules) if filter_rule: logger.info(f'开始过滤资源,当前规则:{filter_rule} ...') @@ -142,6 +143,8 @@ class SearchChain(ChainBase): if not torrents: logger.warn(f'{keyword or mediainfo.title} 没有符合过滤条件的资源') return [] + # 使用默认过滤规则再次过滤 + torrents = self.filter_torrents_by_default_rule(torrents, keyword, mediainfo) # 匹配的资源 _match_torrents = [] # 总数 @@ -307,3 +310,28 @@ class SearchChain(ChainBase): self.progress.end(ProgressKey.Search) # 返回 return results + + def filter_torrents_by_default_rule(self, torrents, keyword, mediainfo): + 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, + f"{torrent.title} {torrent.description}", re.I): + logger.info(f"{torrent.title} 不匹配包含规则 {include}") + continue + # 排除 + if exclude: + if re.search(r"%s" % exclude, + f"{torrent.title} {torrent.description}", re.I): + 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 From d98376b4901d1c72a4f4b7149d2132ed0414547c Mon Sep 17 00:00:00 2001 From: mayun110 Date: Fri, 22 Sep 2023 09:45:23 +0800 Subject: [PATCH 2/2] =?UTF-8?q?filter=5Ftorrents=5Fby=5Fdefault=5Frule?= =?UTF-8?q?=E6=96=B9=E6=B3=95=20=E6=B7=BB=E5=8A=A0=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E5=92=8C=E8=BF=94=E5=9B=9E=E5=80=BC=E5=A3=B0=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/chain/search.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/chain/search.py b/app/chain/search.py index 0f1c216f..6d1fe405 100644 --- a/app/chain/search.py +++ b/app/chain/search.py @@ -311,7 +311,10 @@ class SearchChain(ChainBase): # 返回 return results - def filter_torrents_by_default_rule(self, torrents, keyword, mediainfo): + def filter_torrents_by_default_rule(self, + torrents: List[TorrentInfo], + keyword: str, + mediainfo: MediaInfo) -> List[TorrentInfo]: new_torrents = [] for torrent in torrents: # 取默认过滤规则