feat 过滤规则存数据库
This commit is contained in:
parent
1012120bec
commit
e6bacf3b7b
@ -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 . .
|
||||
|
26
README.md
26
README.md
@ -138,18 +138,7 @@ docker pull jxxghp/moviepilot:latest
|
||||
| icc2022 | `ICC2022_UID`:用户ID<br/>`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管理界面中禁用。
|
||||
|
@ -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]]:
|
||||
|
@ -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
|
||||
|
@ -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:
|
||||
|
@ -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服务器地址
|
||||
|
@ -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 \
|
||||
|
@ -46,6 +46,8 @@ class SystemConfigKey(Enum):
|
||||
CustomReleaseGroups = "CustomReleaseGroups"
|
||||
# 自定义识别词
|
||||
CustomIdentifiers = "CustomIdentifiers"
|
||||
# 过滤规则
|
||||
FilterRules = "FilterRules"
|
||||
|
||||
|
||||
# 站点框架
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user