Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jxxghp committed Sep 22, 2023
1 parent fed754f commit dc41f49
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 32 deletions.
25 changes: 13 additions & 12 deletions app/chain/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
# 总数
Expand Down Expand Up @@ -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,
Expand All @@ -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
24 changes: 4 additions & 20 deletions app/chain/subscribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
# 如果是电视剧过滤掉已经下载的集数
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit dc41f49

Please sign in to comment.