fix filter

This commit is contained in:
jxxghp 2023-07-27 18:49:18 +08:00
parent c39ccde876
commit 9203c63094
2 changed files with 34 additions and 21 deletions

View File

@ -83,13 +83,15 @@ class SearchChain(ChainBase):
def process(self, mediainfo: MediaInfo, def process(self, mediainfo: MediaInfo,
keyword: str = None, keyword: str = None,
no_exists: Dict[int, Dict[int, NotExistMediaInfo]] = None, no_exists: Dict[int, Dict[int, NotExistMediaInfo]] = None,
sites: List[int] = None) -> List[Context]: sites: List[int] = None,
filter_rule: str = None) -> List[Context]:
""" """
根据媒体信息搜索种子资源精确匹配应用过滤规则同时根据no_exists过滤本地已存在的资源 根据媒体信息搜索种子资源精确匹配应用过滤规则同时根据no_exists过滤本地已存在的资源
:param mediainfo: 媒体信息 :param mediainfo: 媒体信息
:param keyword: 搜索关键词 :param keyword: 搜索关键词
:param no_exists: 缺失的媒体信息 :param no_exists: 缺失的媒体信息
:param sites: 站点ID列表为空时搜索所有站点 :param sites: 站点ID列表为空时搜索所有站点
:param filter_rule: 过滤规则为空是使用默认过滤规则
""" """
logger.info(f'开始搜索资源,关键词:{keyword or mediainfo.title} ...') logger.info(f'开始搜索资源,关键词:{keyword or mediainfo.title} ...')
# 补充媒体信息 # 补充媒体信息
@ -116,16 +118,19 @@ class SearchChain(ChainBase):
logger.warn(f'{keyword or mediainfo.title} 未搜索到资源') logger.warn(f'{keyword or mediainfo.title} 未搜索到资源')
return [] return []
# 过滤种子 # 过滤种子
filter_rules = self.systemconfig.get(SystemConfigKey.FilterRules) if filter_rule is None:
logger.info(f'开始过滤资源,当前规则:{filter_rules} ...') # 取默认过滤规则
result: List[TorrentInfo] = self.filter_torrents(rule_string=filter_rules, filter_rule = self.systemconfig.get(SystemConfigKey.FilterRules)
torrent_list=torrents, if filter_rule:
season_episodes=season_episodes) logger.info(f'开始过滤资源,当前规则:{filter_rule} ...')
if result is not None: result: List[TorrentInfo] = self.filter_torrents(rule_string=filter_rule,
torrents = result torrent_list=torrents,
if not torrents: season_episodes=season_episodes)
logger.warn(f'{keyword or mediainfo.title} 没有符合过滤条件的资源') if result is not None:
return [] torrents = result
if not torrents:
logger.warn(f'{keyword or mediainfo.title} 没有符合过滤条件的资源')
return []
# 匹配的资源 # 匹配的资源
_match_torrents = [] _match_torrents = []
# 总数 # 总数

View File

@ -241,11 +241,17 @@ class SubscribeChain(ChainBase):
sites = json.loads(subscribe.sites) sites = json.loads(subscribe.sites)
else: else:
sites = None sites = None
# 过滤规则
if subscribe.best_version:
filter_rule = self.systemconfig.get(SystemConfigKey.FilterRules2)
else:
filter_rule = self.systemconfig.get(SystemConfigKey.FilterRules)
# 搜索,同时电视剧会过滤掉不需要的剧集 # 搜索,同时电视剧会过滤掉不需要的剧集
contexts = self.searchchain.process(mediainfo=mediainfo, contexts = self.searchchain.process(mediainfo=mediainfo,
keyword=subscribe.keyword, keyword=subscribe.keyword,
no_exists=no_exists, no_exists=no_exists,
sites=sites) sites=sites,
filter_rule=filter_rule)
if not contexts: if not contexts:
logger.warn(f'订阅 {subscribe.keyword or subscribe.name} 未搜索到资源') logger.warn(f'订阅 {subscribe.keyword or subscribe.name} 未搜索到资源')
if meta.type == MediaType.TV: if meta.type == MediaType.TV:
@ -366,15 +372,6 @@ class SubscribeChain(ChainBase):
domain = StringUtils.get_url_domain(indexer.get("domain")) domain = StringUtils.get_url_domain(indexer.get("domain"))
torrents: List[TorrentInfo] = self.refresh_torrents(site=indexer) torrents: List[TorrentInfo] = self.refresh_torrents(site=indexer)
if torrents: if torrents:
# 过滤种子
result: List[TorrentInfo] = self.filter_torrents(
rule_string=self.systemconfig.get(SystemConfigKey.FilterRules),
torrent_list=torrents)
if result is not None:
torrents = result
if not torrents:
logger.warn(f'{indexer.get("name")} 没有符合过滤条件的种子')
continue
# 过滤出没有处理过的种子 # 过滤出没有处理过的种子
torrents = [torrent for torrent in torrents torrents = [torrent for torrent in torrents
if f'{torrent.title}{torrent.description}' if f'{torrent.title}{torrent.description}'
@ -493,6 +490,17 @@ class SubscribeChain(ChainBase):
if torrent_mediainfo.tmdb_id != mediainfo.tmdb_id \ if torrent_mediainfo.tmdb_id != mediainfo.tmdb_id \
or torrent_mediainfo.type != mediainfo.type: or torrent_mediainfo.type != mediainfo.type:
continue continue
# 过滤规则
if subscribe.best_version:
filter_rule = self.systemconfig.get(SystemConfigKey.FilterRules2)
else:
filter_rule = self.systemconfig.get(SystemConfigKey.FilterRules)
result: List[TorrentInfo] = self.filter_torrents(
rule_string=filter_rule,
torrent_list=[torrent_info])
if result is not None and not result:
# 不符合过滤规则
continue
# 不在订阅站点范围的不处理 # 不在订阅站点范围的不处理
if subscribe.sites: if subscribe.sites:
sub_sites = json.loads(subscribe.sites) sub_sites = json.loads(subscribe.sites)