feat 过滤规则存数据库

This commit is contained in:
jxxghp
2023-07-19 11:35:18 +08:00
parent 1012120bec
commit e6bacf3b7b
9 changed files with 43 additions and 29 deletions

View File

@ -189,15 +189,18 @@ class ChainBase(AbstractSingleton, metaclass=Singleton):
"""
return self.run_module("refresh_torrents", site=site)
def filter_torrents(self, torrent_list: List[TorrentInfo],
def filter_torrents(self, rule_string: str,
torrent_list: List[TorrentInfo],
season_episodes: Dict[int, list] = None) -> List[TorrentInfo]:
"""
过滤种子资源
:param rule_string: 过滤规则
:param torrent_list: 资源列表
:param season_episodes: 季集数过滤 {season:[episodes]}
:return: 过滤后的资源列表,添加资源优先级
"""
return self.run_module("filter_torrents", torrent_list=torrent_list, season_episodes=season_episodes)
return self.run_module("filter_torrents", rule_string=rule_string,
torrent_list=torrent_list, season_episodes=season_episodes)
def download(self, torrent_path: Path, cookie: str,
episodes: Set[int] = None) -> Optional[Tuple[Optional[str], str]]:

View File

@ -5,7 +5,6 @@ from typing import Dict
from typing import List, Optional
from app.chain import ChainBase
from app.core.config import settings
from app.core.context import Context
from app.core.context import MediaInfo, TorrentInfo
from app.core.metainfo import MetaInfo
@ -117,8 +116,10 @@ class SearchChain(ChainBase):
logger.warn(f'{keyword or mediainfo.title} 未搜索到资源')
return []
# 过滤种子
logger.info(f'开始过滤资源,当前规则:{settings.FILTER_RULE} ...')
result: List[TorrentInfo] = self.filter_torrents(torrent_list=torrents,
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

View File

@ -304,7 +304,9 @@ class SubscribeChain(ChainBase):
if torrents:
self._torrents_cache[domain] = []
# 过滤种子
result: List[TorrentInfo] = self.filter_torrents(torrent_list=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: