From e6bacf3b7bfa22b0f1457a2b92c7c766d5b1f1fd Mon Sep 17 00:00:00 2001 From: jxxghp Date: Wed, 19 Jul 2023 11:35:18 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E8=BF=87=E6=BB=A4=E8=A7=84=E5=88=99?= =?UTF-8?q?=E5=AD=98=E6=95=B0=E6=8D=AE=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 3 +-- README.md | 26 ++++++++++++++------------ app/chain/__init__.py | 7 +++++-- app/chain/search.py | 7 ++++--- app/chain/subscribe.py | 4 +++- app/core/config.py | 2 -- app/modules/filter/__init__.py | 18 ++++++++++++------ app/schemas/types.py | 2 ++ tests/test_filter.py | 3 ++- 9 files changed, 43 insertions(+), 29 deletions(-) diff --git a/Dockerfile b/Dockerfile index e11b78c5..ded1264f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,6 +9,7 @@ ENV LANG="C.UTF-8" \ AUTH_SITE="iyuu" \ LIBRARY_PATH="" \ DOWNLOAD_PATH="/downloads" \ + TRANSFER_TYPE="copy" \ COOKIECLOUD_HOST="https://nastool.org/cookiecloud" \ COOKIECLOUD_KEY="" \ COOKIECLOUD_PASSWORD="" \ @@ -22,8 +23,6 @@ ENV LANG="C.UTF-8" \ MEDIASERVER="emby" \ EMBY_HOST="http://127.0.0.1:8096" \ EMBY_API_KEY="" \ - FILTER_RULE="!BLU & 4K & CN > !BLU & 1080P & CN > !BLU & 4K > !BLU & 1080P" \ - TRANSFER_TYPE="copy" \ DOUBAN_USER_IDS="" WORKDIR "/app" COPY . . diff --git a/README.md b/README.md index ab9893f6..accb43ab 100644 --- a/README.md +++ b/README.md @@ -138,18 +138,7 @@ docker pull jxxghp/moviepilot:latest | icc2022 | `ICC2022_UID`:用户ID
`ICC2022_PASSKEY`:密钥 | -### 3. **过滤规则** - -- **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. **进阶配置** +### 2. **进阶配置** - **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}} ``` + +### 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管理界面中禁用。 diff --git a/app/chain/__init__.py b/app/chain/__init__.py index 82e5fb70..034d90fc 100644 --- a/app/chain/__init__.py +++ b/app/chain/__init__.py @@ -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]]: diff --git a/app/chain/search.py b/app/chain/search.py index 2efca631..658b7367 100644 --- a/app/chain/search.py +++ b/app/chain/search.py @@ -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 diff --git a/app/chain/subscribe.py b/app/chain/subscribe.py index 8e59e6d1..c4e2a883 100644 --- a/app/chain/subscribe.py +++ b/app/chain/subscribe.py @@ -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: diff --git a/app/core/config.py b/app/core/config.py index 0f9b0fce..32349e88 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -123,8 +123,6 @@ class Settings(BaseSettings): PLEX_HOST: str = None # Plex Token PLEX_TOKEN: str = None - # 过滤规则 - FILTER_RULE: str = "!BLU & 4K & CN > !BLU & 1080P & CN > !BLU & 4K > !BLU & 1080P" # 转移方式 link/copy/move/softlink TRANSFER_TYPE: str = "copy" # CookieCloud服务器地址 diff --git a/app/modules/filter/__init__.py b/app/modules/filter/__init__.py index 0f706fdc..e9468bef 100644 --- a/app/modules/filter/__init__.py +++ b/app/modules/filter/__init__.py @@ -2,7 +2,6 @@ import re from typing import List, Tuple, Union, Dict, Optional from app.core.context import TorrentInfo -from app.core.config import settings from app.core.metainfo import MetaInfo from app.log import logger from app.modules import _ModuleBase @@ -32,8 +31,13 @@ class FilterModule(_ModuleBase): "exclude": [] }, # 中字 - "CN": { - "include": [r'特效|[中国國繁简](/|\s|\\|\|)?[繁简英粤]|[英简繁](/|\s|\\|\|)?[中繁简]|繁體|简体|[中国國][字配]|国语|國語|中文'], + "CNSUB": { + "include": [r'[中国國繁简](/|\s|\\|\|)?[繁简英粤]|[英简繁](/|\s|\\|\|)?[中繁简]|繁體|简体|[中国國][字配]|国语|國語|中文'], + "exclude": [] + }, + # 特效字幕 + "SPECSUB": { + "include": [r'特效'], "exclude": [] }, # H265 @@ -81,21 +85,23 @@ class FilterModule(_ModuleBase): def init_setting(self) -> Tuple[str, Union[str, bool]]: 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]: """ 过滤种子资源 + :param rule_string: 过滤规则 :param torrent_list: 资源列表 :param season_episodes: 季集数过滤 {season:[episodes]} :return: 过滤后的资源列表,添加资源优先级 """ - if not settings.FILTER_RULE: + if not rule_string: return torrent_list # 返回种子列表 ret_torrents = [] for torrent in torrent_list: # 能命中优先级的才返回 - if not self.__get_order(torrent, settings.FILTER_RULE): + if not self.__get_order(torrent, rule_string): continue # 季集数过滤 if season_episodes \ diff --git a/app/schemas/types.py b/app/schemas/types.py index a37c58ec..bee24d0d 100644 --- a/app/schemas/types.py +++ b/app/schemas/types.py @@ -46,6 +46,8 @@ class SystemConfigKey(Enum): CustomReleaseGroups = "CustomReleaseGroups" # 自定义识别词 CustomIdentifiers = "CustomIdentifiers" + # 过滤规则 + FilterRules = "FilterRules" # 站点框架 diff --git a/tests/test_filter.py b/tests/test_filter.py index fded08ce..85664e98 100644 --- a/tests/test_filter.py +++ b/tests/test_filter.py @@ -18,6 +18,7 @@ class FilterTest(TestCase): description="狼的孩子雨和雪/狼之子雨与雪/Okami kodomo no ame to yuki") _filter = FilterModule() _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(result[0].pri_order, 97)