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

@ -9,6 +9,7 @@ ENV LANG="C.UTF-8" \
AUTH_SITE="iyuu" \ AUTH_SITE="iyuu" \
LIBRARY_PATH="" \ LIBRARY_PATH="" \
DOWNLOAD_PATH="/downloads" \ DOWNLOAD_PATH="/downloads" \
TRANSFER_TYPE="copy" \
COOKIECLOUD_HOST="https://nastool.org/cookiecloud" \ COOKIECLOUD_HOST="https://nastool.org/cookiecloud" \
COOKIECLOUD_KEY="" \ COOKIECLOUD_KEY="" \
COOKIECLOUD_PASSWORD="" \ COOKIECLOUD_PASSWORD="" \
@ -22,8 +23,6 @@ ENV LANG="C.UTF-8" \
MEDIASERVER="emby" \ MEDIASERVER="emby" \
EMBY_HOST="http://127.0.0.1:8096" \ EMBY_HOST="http://127.0.0.1:8096" \
EMBY_API_KEY="" \ EMBY_API_KEY="" \
FILTER_RULE="!BLU & 4K & CN > !BLU & 1080P & CN > !BLU & 4K > !BLU & 1080P" \
TRANSFER_TYPE="copy" \
DOUBAN_USER_IDS="" DOUBAN_USER_IDS=""
WORKDIR "/app" WORKDIR "/app"
COPY . . COPY . .

View File

@ -138,18 +138,7 @@ docker pull jxxghp/moviepilot:latest
| icc2022 | `ICC2022_UID`用户ID<br/>`ICC2022_PASSKEY`:密钥 | | icc2022 | `ICC2022_UID`用户ID<br/>`ICC2022_PASSKEY`:密钥 |
### 3. **过滤规则** ### 2. **进阶配置**
- **FILTER_RULE** 配置过规则,默认`!BLU & 4K & CN > !BLU & 1080P & CN > !BLU & 4K > !BLU & 1080P` 表示优先中文字幕非蓝光4K然后中文字幕非蓝光1080P然后非蓝光4K最后非蓝光1080P
`FILTER_RULE` 规则说明:
- 仅支持使用内置规则进行排列组合,内置规则有:`BLU``4K``1080P``CN``H265``H264``DOLBY``HDR``REMUX``WEBDL``FREE`
- `&`表示与,``表示或,`!`表示非,`>`表示优先级层级
- 符合任一层级规则的资源将被标识选中,匹配成功的层级做为该资源的优先级,排越前面优先级超高
- 不符合过滤规则所有层级规则的资源将不会被选中
### 3. **进阶配置**
- **MOVIE_RENAME_FORMAT** 电影重命名格式 - **MOVIE_RENAME_FORMAT** 电影重命名格式
@ -191,6 +180,19 @@ docker pull jxxghp/moviepilot:latest
{{title}}{% if year %} ({{year}}){% endif %}/Season {{season}}/{{title}} - {{season_episode}}{% if part %}-{{part}}{% endif %}{% if episode %} - 第 {{episode}} 集{% endif %}{{fileExt}} {{title}}{% if year %} ({{year}}){% endif %}/Season {{season}}/{{title}} - {{season_episode}}{% if part %}-{{part}}{% endif %}{% if episode %} - 第 {{episode}} 集{% endif %}{{fileExt}}
``` ```
### 3. **过滤规则**
`设定`-`规则`中设定,规则说明:
- 仅支持使用内置规则进行排列组合,内置规则有:`BLU``4K``1080P``CNSUB``SPECSUB``H265``H264``DOLBY``HDR``REMUX``WEBDL``FREE`
- `&`表示与,``表示或,`!`表示非,`>`表示优先级层级
- 符合任一层级规则的资源将被标识选中,匹配成功的层级做为该资源的优先级,排越前面优先级超高
- 不符合过滤规则所有层级规则的资源将不会被选中
`!BLU & 4K & CN > !BLU & 1080P & CN > !BLU & 4K > !BLU & 1080P` 表示优先中文字幕非蓝光4K然后中文字幕非蓝光1080P然后非蓝光4K最后非蓝光1080P
## 使用 ## 使用
- 通过CookieCloud同步快速同步站点不需要使用的站点可在WEB管理界面中禁用。 - 通过CookieCloud同步快速同步站点不需要使用的站点可在WEB管理界面中禁用。

View File

@ -189,15 +189,18 @@ class ChainBase(AbstractSingleton, metaclass=Singleton):
""" """
return self.run_module("refresh_torrents", site=site) 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]: season_episodes: Dict[int, list] = None) -> List[TorrentInfo]:
""" """
过滤种子资源 过滤种子资源
:param rule_string: 过滤规则
:param torrent_list: 资源列表 :param torrent_list: 资源列表
:param season_episodes: 季集数过滤 {season:[episodes]} :param season_episodes: 季集数过滤 {season:[episodes]}
:return: 过滤后的资源列表添加资源优先级 :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, def download(self, torrent_path: Path, cookie: str,
episodes: Set[int] = None) -> Optional[Tuple[Optional[str], 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 typing import List, Optional
from app.chain import ChainBase from app.chain import ChainBase
from app.core.config import settings
from app.core.context import Context from app.core.context import Context
from app.core.context import MediaInfo, TorrentInfo from app.core.context import MediaInfo, TorrentInfo
from app.core.metainfo import MetaInfo from app.core.metainfo import MetaInfo
@ -117,8 +116,10 @@ class SearchChain(ChainBase):
logger.warn(f'{keyword or mediainfo.title} 未搜索到资源') logger.warn(f'{keyword or mediainfo.title} 未搜索到资源')
return [] return []
# 过滤种子 # 过滤种子
logger.info(f'开始过滤资源,当前规则:{settings.FILTER_RULE} ...') filter_rules = self.systemconfig.get(SystemConfigKey.FilterRules)
result: List[TorrentInfo] = self.filter_torrents(torrent_list=torrents, logger.info(f'开始过滤资源,当前规则:{filter_rules} ...')
result: List[TorrentInfo] = self.filter_torrents(rule_string=filter_rules,
torrent_list=torrents,
season_episodes=season_episodes) season_episodes=season_episodes)
if result is not None: if result is not None:
torrents = result torrents = result

View File

@ -304,7 +304,9 @@ class SubscribeChain(ChainBase):
if torrents: if torrents:
self._torrents_cache[domain] = [] 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: if result is not None:
torrents = result torrents = result
if not torrents: if not torrents:

View File

@ -123,8 +123,6 @@ class Settings(BaseSettings):
PLEX_HOST: str = None PLEX_HOST: str = None
# Plex Token # Plex Token
PLEX_TOKEN: str = None PLEX_TOKEN: str = None
# 过滤规则
FILTER_RULE: str = "!BLU & 4K & CN > !BLU & 1080P & CN > !BLU & 4K > !BLU & 1080P"
# 转移方式 link/copy/move/softlink # 转移方式 link/copy/move/softlink
TRANSFER_TYPE: str = "copy" TRANSFER_TYPE: str = "copy"
# CookieCloud服务器地址 # CookieCloud服务器地址

View File

@ -2,7 +2,6 @@ import re
from typing import List, Tuple, Union, Dict, Optional from typing import List, Tuple, Union, Dict, Optional
from app.core.context import TorrentInfo from app.core.context import TorrentInfo
from app.core.config import settings
from app.core.metainfo import MetaInfo from app.core.metainfo import MetaInfo
from app.log import logger from app.log import logger
from app.modules import _ModuleBase from app.modules import _ModuleBase
@ -32,8 +31,13 @@ class FilterModule(_ModuleBase):
"exclude": [] "exclude": []
}, },
# 中字 # 中字
"CN": { "CNSUB": {
"include": [r'特效|[中国國繁简](/|\s|\\|\|)?[繁简英粤]|[英简繁](/|\s|\\|\|)?[中繁简]|繁體|简体|[中国國][字配]|国语|國語|中文'], "include": [r'[中国國繁简](/|\s|\\|\|)?[繁简英粤]|[英简繁](/|\s|\\|\|)?[中繁简]|繁體|简体|[中国國][字配]|国语|國語|中文'],
"exclude": []
},
# 特效字幕
"SPECSUB": {
"include": [r'特效'],
"exclude": [] "exclude": []
}, },
# H265 # H265
@ -81,21 +85,23 @@ class FilterModule(_ModuleBase):
def init_setting(self) -> Tuple[str, Union[str, bool]]: def init_setting(self) -> Tuple[str, Union[str, bool]]:
return "FILTER_RULE", True return "FILTER_RULE", True
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]: season_episodes: Dict[int, list] = None) -> List[TorrentInfo]:
""" """
过滤种子资源 过滤种子资源
:param rule_string: 过滤规则
:param torrent_list: 资源列表 :param torrent_list: 资源列表
:param season_episodes: 季集数过滤 {season:[episodes]} :param season_episodes: 季集数过滤 {season:[episodes]}
:return: 过滤后的资源列表添加资源优先级 :return: 过滤后的资源列表添加资源优先级
""" """
if not settings.FILTER_RULE: if not rule_string:
return torrent_list return torrent_list
# 返回种子列表 # 返回种子列表
ret_torrents = [] ret_torrents = []
for torrent in torrent_list: for torrent in torrent_list:
# 能命中优先级的才返回 # 能命中优先级的才返回
if not self.__get_order(torrent, settings.FILTER_RULE): if not self.__get_order(torrent, rule_string):
continue continue
# 季集数过滤 # 季集数过滤
if season_episodes \ if season_episodes \

View File

@ -46,6 +46,8 @@ class SystemConfigKey(Enum):
CustomReleaseGroups = "CustomReleaseGroups" CustomReleaseGroups = "CustomReleaseGroups"
# 自定义识别词 # 自定义识别词
CustomIdentifiers = "CustomIdentifiers" CustomIdentifiers = "CustomIdentifiers"
# 过滤规则
FilterRules = "FilterRules"
# 站点框架 # 站点框架

View File

@ -18,6 +18,7 @@ class FilterTest(TestCase):
description="狼的孩子雨和雪/狼之子雨与雪/Okami kodomo no ame to yuki") description="狼的孩子雨和雪/狼之子雨与雪/Okami kodomo no ame to yuki")
_filter = FilterModule() _filter = FilterModule()
_filter.init_module() _filter.init_module()
result = _filter.filter_torrents(torrent_list=[torrent]) result = _filter.filter_torrents(rule_string="!BLU & 4K & CN > !BLU & 1080P & CN > !BLU & 4K > !BLU & 1080P",
torrent_list=[torrent])
self.assertEqual(len(result), 1) self.assertEqual(len(result), 1)
self.assertEqual(result[0].pri_order, 97) self.assertEqual(result[0].pri_order, 97)