Skip to content

Commit

Permalink
fix filter
Browse files Browse the repository at this point in the history
  • Loading branch information
jxxghp committed Jul 27, 2023
1 parent c39ccde commit 9203c63
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 21 deletions.
27 changes: 16 additions & 11 deletions app/chain/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,15 @@ def browse(self, domain: str, keyword: str = None) -> List[TorrentInfo]:
def process(self, mediainfo: MediaInfo,
keyword: str = 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过滤本地已存在的资源
:param mediainfo: 媒体信息
:param keyword: 搜索关键词
:param no_exists: 缺失的媒体信息
:param sites: 站点ID列表,为空时搜索所有站点
:param filter_rule: 过滤规则,为空是使用默认过滤规则
"""
logger.info(f'开始搜索资源,关键词:{keyword or mediainfo.title} ...')
# 补充媒体信息
Expand All @@ -116,16 +118,19 @@ def process(self, mediainfo: MediaInfo,
logger.warn(f'{keyword or mediainfo.title} 未搜索到资源')
return []
# 过滤种子
filter_rules = self.systemconfig.get(SystemConfigKey.FilterRules)
logger.info(f'开始过滤资源,当前规则:{filter_rules} ...')
result: List[TorrentInfo] = self.filter_torrents(rule_string=filter_rules,
torrent_list=torrents,
season_episodes=season_episodes)
if result is not None:
torrents = result
if not torrents:
logger.warn(f'{keyword or mediainfo.title} 没有符合过滤条件的资源')
return []
if filter_rule is None:
# 取默认过滤规则
filter_rule = self.systemconfig.get(SystemConfigKey.FilterRules)
if filter_rule:
logger.info(f'开始过滤资源,当前规则:{filter_rule} ...')
result: List[TorrentInfo] = self.filter_torrents(rule_string=filter_rule,
torrent_list=torrents,
season_episodes=season_episodes)
if result is not None:
torrents = result
if not torrents:
logger.warn(f'{keyword or mediainfo.title} 没有符合过滤条件的资源')
return []
# 匹配的资源
_match_torrents = []
# 总数
Expand Down
28 changes: 18 additions & 10 deletions app/chain/subscribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,17 @@ def search(self, sid: int = None, state: str = 'N', manual: bool = False):
sites = json.loads(subscribe.sites)
else:
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,
keyword=subscribe.keyword,
no_exists=no_exists,
sites=sites)
sites=sites,
filter_rule=filter_rule)
if not contexts:
logger.warn(f'订阅 {subscribe.keyword or subscribe.name} 未搜索到资源')
if meta.type == MediaType.TV:
Expand Down Expand Up @@ -366,15 +372,6 @@ def refresh(self):
domain = StringUtils.get_url_domain(indexer.get("domain"))
torrents: List[TorrentInfo] = self.refresh_torrents(site=indexer)
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
if f'{torrent.title}{torrent.description}'
Expand Down Expand Up @@ -493,6 +490,17 @@ def __match(self, torrents_cache: Dict[str, List[Context]]):
if torrent_mediainfo.tmdb_id != mediainfo.tmdb_id \
or torrent_mediainfo.type != mediainfo.type:
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:
sub_sites = json.loads(subscribe.sites)
Expand Down

0 comments on commit 9203c63

Please sign in to comment.