fix #829 默认过滤规则拆分
This commit is contained in:
@ -141,7 +141,7 @@ class SearchChain(ChainBase):
|
|||||||
if not torrents:
|
if not torrents:
|
||||||
logger.warn(f'{keyword or mediainfo.title} 没有符合优先级规则的资源')
|
logger.warn(f'{keyword or mediainfo.title} 没有符合优先级规则的资源')
|
||||||
return []
|
return []
|
||||||
# 使用默认过滤规则再次过滤
|
# 使用过滤规则再次过滤
|
||||||
torrents = self.filter_torrents_by_rule(torrents=torrents,
|
torrents = self.filter_torrents_by_rule(torrents=torrents,
|
||||||
filter_rule=filter_rule)
|
filter_rule=filter_rule)
|
||||||
if not torrents:
|
if not torrents:
|
||||||
@ -333,9 +333,9 @@ class SearchChain(ChainBase):
|
|||||||
:param filter_rule: 过滤规则
|
:param filter_rule: 过滤规则
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# 取默认过滤规则
|
|
||||||
if not filter_rule:
|
if not filter_rule:
|
||||||
filter_rule = self.systemconfig.get(SystemConfigKey.DefaultFilterRules)
|
# 没有则取搜索默认过滤规则
|
||||||
|
filter_rule = self.systemconfig.get(SystemConfigKey.DefaultSearchFilterRules)
|
||||||
if not filter_rule:
|
if not filter_rule:
|
||||||
return torrents
|
return torrents
|
||||||
# 包含
|
# 包含
|
||||||
|
@ -244,17 +244,8 @@ class SubscribeChain(ChainBase):
|
|||||||
else:
|
else:
|
||||||
priority_rule = self.systemconfig.get(SystemConfigKey.SubscribeFilterRules)
|
priority_rule = self.systemconfig.get(SystemConfigKey.SubscribeFilterRules)
|
||||||
|
|
||||||
# 默认过滤规则
|
# 过滤规则
|
||||||
if subscribe.include or subscribe.exclude:
|
filter_rule = self.get_filter_rule(subscribe)
|
||||||
filter_rule = {
|
|
||||||
"include": subscribe.include,
|
|
||||||
"exclude": subscribe.exclude,
|
|
||||||
"quality": subscribe.quality,
|
|
||||||
"resolution": subscribe.resolution,
|
|
||||||
"effect": subscribe.effect,
|
|
||||||
}
|
|
||||||
else:
|
|
||||||
filter_rule = self.systemconfig.get(SystemConfigKey.DefaultFilterRules)
|
|
||||||
|
|
||||||
# 搜索,同时电视剧会过滤掉不需要的剧集
|
# 搜索,同时电视剧会过滤掉不需要的剧集
|
||||||
contexts = self.searchchain.process(mediainfo=mediainfo,
|
contexts = self.searchchain.process(mediainfo=mediainfo,
|
||||||
@ -400,6 +391,67 @@ class SubscribeChain(ChainBase):
|
|||||||
|
|
||||||
return ret_sites
|
return ret_sites
|
||||||
|
|
||||||
|
def get_filter_rule(self, subscribe: Subscribe):
|
||||||
|
"""
|
||||||
|
获取订阅过滤规则,没有则返回默认规则
|
||||||
|
"""
|
||||||
|
# 默认过滤规则
|
||||||
|
if (subscribe.include
|
||||||
|
or subscribe.exclude
|
||||||
|
or subscribe.quality
|
||||||
|
or subscribe.resolution
|
||||||
|
or subscribe.effect):
|
||||||
|
return {
|
||||||
|
"include": subscribe.include,
|
||||||
|
"exclude": subscribe.exclude,
|
||||||
|
"quality": subscribe.quality,
|
||||||
|
"resolution": subscribe.resolution,
|
||||||
|
"effect": subscribe.effect,
|
||||||
|
}
|
||||||
|
# 订阅默认过滤规则
|
||||||
|
return self.systemconfig.get(SystemConfigKey.DefaultFilterRules) or {}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def check_filter_rule(torrent_info: TorrentInfo, filter_rule: Dict[str, str]) -> bool:
|
||||||
|
"""
|
||||||
|
检查种子是否匹配订阅过滤规则
|
||||||
|
"""
|
||||||
|
if not filter_rule:
|
||||||
|
return True
|
||||||
|
# 包含
|
||||||
|
include = filter_rule.get("include")
|
||||||
|
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}")
|
||||||
|
return False
|
||||||
|
# 排除
|
||||||
|
exclude = filter_rule.get("exclude")
|
||||||
|
if exclude:
|
||||||
|
if re.search(r"%s" % exclude,
|
||||||
|
f"{torrent_info.title} {torrent_info.description}", re.I):
|
||||||
|
logger.info(f"{torrent_info.title} 匹配排除规则 {exclude}")
|
||||||
|
return False
|
||||||
|
# 质量
|
||||||
|
quality = filter_rule.get("quality")
|
||||||
|
if quality:
|
||||||
|
if not re.search(r"%s" % quality, torrent_info.title, re.I):
|
||||||
|
logger.info(f"{torrent_info.title} 不匹配质量规则 {quality}")
|
||||||
|
return False
|
||||||
|
# 分辨率
|
||||||
|
resolution = filter_rule.get("resolution")
|
||||||
|
if resolution:
|
||||||
|
if not re.search(r"%s" % resolution, torrent_info.title, re.I):
|
||||||
|
logger.info(f"{torrent_info.title} 不匹配分辨率规则 {resolution}")
|
||||||
|
return False
|
||||||
|
# 特效
|
||||||
|
effect = filter_rule.get("effect")
|
||||||
|
if effect:
|
||||||
|
if not re.search(r"%s" % effect, torrent_info.title, re.I):
|
||||||
|
logger.info(f"{torrent_info.title} 不匹配特效规则 {effect}")
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
def match(self, torrents: Dict[str, List[Context]]):
|
def match(self, torrents: Dict[str, List[Context]]):
|
||||||
"""
|
"""
|
||||||
从缓存中匹配订阅,并自动下载
|
从缓存中匹配订阅,并自动下载
|
||||||
@ -475,10 +527,8 @@ class SubscribeChain(ChainBase):
|
|||||||
if no_exists_info:
|
if no_exists_info:
|
||||||
logger.info(f'订阅 {mediainfo.title_year} {meta.season} 缺失集:{no_exists_info.episodes}')
|
logger.info(f'订阅 {mediainfo.title_year} {meta.season} 缺失集:{no_exists_info.episodes}')
|
||||||
|
|
||||||
# 默认过滤规则
|
# 过滤规则
|
||||||
default_filter = self.systemconfig.get(SystemConfigKey.DefaultFilterRules) or {}
|
filter_rule = self.get_filter_rule(subscribe)
|
||||||
include = subscribe.include or default_filter.get("include")
|
|
||||||
exclude = subscribe.exclude or default_filter.get("exclude")
|
|
||||||
|
|
||||||
# 遍历缓存种子
|
# 遍历缓存种子
|
||||||
_match_context = []
|
_match_context = []
|
||||||
@ -494,11 +544,11 @@ class SubscribeChain(ChainBase):
|
|||||||
continue
|
continue
|
||||||
# 优先级过滤规则
|
# 优先级过滤规则
|
||||||
if subscribe.best_version:
|
if subscribe.best_version:
|
||||||
filter_rule = self.systemconfig.get(SystemConfigKey.BestVersionFilterRules)
|
priority_rule = self.systemconfig.get(SystemConfigKey.BestVersionFilterRules)
|
||||||
else:
|
else:
|
||||||
filter_rule = self.systemconfig.get(SystemConfigKey.SubscribeFilterRules)
|
priority_rule = self.systemconfig.get(SystemConfigKey.SubscribeFilterRules)
|
||||||
result: List[TorrentInfo] = self.filter_torrents(
|
result: List[TorrentInfo] = self.filter_torrents(
|
||||||
rule_string=filter_rule,
|
rule_string=priority_rule,
|
||||||
torrent_list=[torrent_info],
|
torrent_list=[torrent_info],
|
||||||
mediainfo=torrent_mediainfo)
|
mediainfo=torrent_mediainfo)
|
||||||
if result is not None and not result:
|
if result is not None and not result:
|
||||||
@ -539,7 +589,8 @@ class SubscribeChain(ChainBase):
|
|||||||
set(torrent_meta.episode_list)
|
set(torrent_meta.episode_list)
|
||||||
):
|
):
|
||||||
logger.info(
|
logger.info(
|
||||||
f'{torrent_info.title} 对应剧集 {torrent_meta.episode_list} 未包含缺失的剧集')
|
f'{torrent_info.title} 对应剧集 {torrent_meta.episode_list} 未包含缺失的剧集'
|
||||||
|
)
|
||||||
continue
|
continue
|
||||||
# 过滤掉已经下载的集数
|
# 过滤掉已经下载的集数
|
||||||
if self.__check_subscribe_note(subscribe, torrent_meta.episode_list):
|
if self.__check_subscribe_note(subscribe, torrent_meta.episode_list):
|
||||||
@ -551,18 +602,12 @@ class SubscribeChain(ChainBase):
|
|||||||
if torrent_meta.episode_list:
|
if torrent_meta.episode_list:
|
||||||
logger.info(f'{subscribe.name} 正在洗版,{torrent_info.title} 不是整季')
|
logger.info(f'{subscribe.name} 正在洗版,{torrent_info.title} 不是整季')
|
||||||
continue
|
continue
|
||||||
# 包含
|
|
||||||
if include:
|
# 过滤规则
|
||||||
if not re.search(r"%s" % include,
|
if not self.check_filter_rule(torrent_info=torrent_info,
|
||||||
f"{torrent_info.title} {torrent_info.description}", re.I):
|
filter_rule=filter_rule):
|
||||||
logger.info(f"{torrent_info.title} 不匹配包含规则 {include}")
|
continue
|
||||||
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
|
|
||||||
# 匹配成功
|
# 匹配成功
|
||||||
logger.info(f'{mediainfo.title_year} 匹配成功:{torrent_info.title}')
|
logger.info(f'{mediainfo.title_year} 匹配成功:{torrent_info.title}')
|
||||||
_match_context.append(context)
|
_match_context.append(context)
|
||||||
|
@ -72,8 +72,10 @@ class SystemConfigKey(Enum):
|
|||||||
SubscribeFilterRules = "SubscribeFilterRules"
|
SubscribeFilterRules = "SubscribeFilterRules"
|
||||||
# 洗版规则
|
# 洗版规则
|
||||||
BestVersionFilterRules = "BestVersionFilterRules"
|
BestVersionFilterRules = "BestVersionFilterRules"
|
||||||
# 默认过滤规则
|
# 默认订阅过滤规则
|
||||||
DefaultFilterRules = "DefaultFilterRules"
|
DefaultFilterRules = "DefaultFilterRules"
|
||||||
|
# 默认搜索过滤规则
|
||||||
|
DefaultSearchFilterRules = "DefaultSearchFilterRules"
|
||||||
# 转移屏蔽词
|
# 转移屏蔽词
|
||||||
TransferExcludeWords = "TransferExcludeWords"
|
TransferExcludeWords = "TransferExcludeWords"
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user