mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-04-04 19:28:59 +08:00
fix rule group filter
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from typing import List, Optional
|
||||
|
||||
from app.core.context import MediaInfo
|
||||
from app.db.systemconfig_oper import SystemConfigOper
|
||||
from app.schemas import FilterRuleGroup, CustomRule
|
||||
from app.schemas.types import SystemConfigKey
|
||||
@@ -32,6 +33,23 @@ class RuleHelper:
|
||||
return group
|
||||
return None
|
||||
|
||||
def get_rule_group_by_media(self, media: MediaInfo, group_names: list = None) -> List[FilterRuleGroup]:
|
||||
"""
|
||||
根据媒体信息获取规则组
|
||||
"""
|
||||
ret_groups = []
|
||||
rule_groups = self.get_rule_groups()
|
||||
if group_names:
|
||||
rule_groups = [group for group in rule_groups if group.name in group_names]
|
||||
for group in rule_groups:
|
||||
if not group.media_type:
|
||||
ret_groups.append(group)
|
||||
elif not group.category and group.media_type == media.type.value:
|
||||
ret_groups.append(group)
|
||||
elif group.category == media.category:
|
||||
ret_groups.append(group)
|
||||
return ret_groups
|
||||
|
||||
def get_custom_rules(self) -> List[CustomRule]:
|
||||
"""
|
||||
获取用户所有自定义规则
|
||||
|
||||
@@ -178,26 +178,16 @@ class FilterModule(_ModuleBase):
|
||||
return torrent_list
|
||||
self.media = mediainfo
|
||||
# 查询规则表详情
|
||||
for group_name in rule_groups:
|
||||
rule_group = self.rulehelper.get_rule_group(group_name)
|
||||
if not rule_group:
|
||||
logger.error(f"规则组 {group_name} 不存在")
|
||||
continue
|
||||
if rule_group.media_type and rule_group.media_type != mediainfo.type.value:
|
||||
# 规则组不适用当前媒体类型
|
||||
logger.debug(f"规则组 {group_name} 不适用于 {mediainfo.type.value}")
|
||||
continue
|
||||
if rule_group.category and mediainfo.category and mediainfo.category != rule_group.category:
|
||||
# 规则组不适用于当前媒体类别
|
||||
logger.debug(f"规则组 {group_name} 不适用于 {mediainfo.category}")
|
||||
continue
|
||||
# 过滤种子
|
||||
torrent_list = self.__filter_torrents(
|
||||
rule_string=rule_group.rule_string,
|
||||
rule_name=rule_group.name,
|
||||
torrent_list=torrent_list,
|
||||
season_episodes=season_episodes
|
||||
)
|
||||
groups = self.rulehelper.get_rule_group_by_media(media=mediainfo, group_names=rule_groups)
|
||||
if groups:
|
||||
for group in groups:
|
||||
# 过滤种子
|
||||
torrent_list = self.__filter_torrents(
|
||||
rule_string=group.rule_string,
|
||||
rule_name=group.name,
|
||||
torrent_list=torrent_list,
|
||||
season_episodes=season_episodes
|
||||
)
|
||||
return torrent_list
|
||||
|
||||
def __filter_torrents(self, rule_string: str, rule_name: str,
|
||||
|
||||
Reference in New Issue
Block a user