fix #650
This commit is contained in:
29
alembic/versions/30329639c12b_1_0_7.py
Normal file
29
alembic/versions/30329639c12b_1_0_7.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
"""1.0.7
|
||||||
|
|
||||||
|
Revision ID: 30329639c12b
|
||||||
|
Revises: 232dfa044617
|
||||||
|
Create Date: 2023-09-23 08:25:59.776488
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = '30329639c12b'
|
||||||
|
down_revision = '232dfa044617'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade() -> None:
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.execute("delete from systemconfig where key = 'DefaultFilterRules';")
|
||||||
|
op.execute(
|
||||||
|
"insert into systemconfig(key, value) VALUES('DefaultFilterRules', (select value from systemconfig where key= 'DefaultIncludeExcludeFilter'));")
|
||||||
|
op.execute("delete from systemconfig where key = 'DefaultIncludeExcludeFilter';")
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade() -> None:
|
||||||
|
pass
|
@ -81,7 +81,8 @@ class SearchChain(ChainBase):
|
|||||||
keyword: str = None,
|
keyword: str = None,
|
||||||
no_exists: Dict[int, Dict[int, NotExistMediaInfo]] = None,
|
no_exists: Dict[int, Dict[int, NotExistMediaInfo]] = None,
|
||||||
sites: List[int] = None,
|
sites: List[int] = None,
|
||||||
filter_rule: str = None,
|
priority_rule: str = None,
|
||||||
|
filter_rule: Dict[str, str] = None,
|
||||||
area: str = "title") -> List[Context]:
|
area: str = "title") -> List[Context]:
|
||||||
"""
|
"""
|
||||||
根据媒体信息搜索种子资源,精确匹配,应用过滤规则,同时根据no_exists过滤本地已存在的资源
|
根据媒体信息搜索种子资源,精确匹配,应用过滤规则,同时根据no_exists过滤本地已存在的资源
|
||||||
@ -89,7 +90,8 @@ class SearchChain(ChainBase):
|
|||||||
:param keyword: 搜索关键词
|
:param keyword: 搜索关键词
|
||||||
:param no_exists: 缺失的媒体信息
|
:param no_exists: 缺失的媒体信息
|
||||||
:param sites: 站点ID列表,为空时搜索所有站点
|
:param sites: 站点ID列表,为空时搜索所有站点
|
||||||
:param filter_rule: 过滤规则,为空是使用默认搜索过滤规则
|
:param priority_rule: 优先级规则,为空时使用搜索优先级规则
|
||||||
|
:param filter_rule: 过滤规则,为空是使用默认过滤规则
|
||||||
:param area: 搜索范围,title or imdbid
|
:param area: 搜索范围,title or imdbid
|
||||||
"""
|
"""
|
||||||
logger.info(f'开始搜索资源,关键词:{keyword or mediainfo.title} ...')
|
logger.info(f'开始搜索资源,关键词:{keyword or mediainfo.title} ...')
|
||||||
@ -129,12 +131,12 @@ class SearchChain(ChainBase):
|
|||||||
logger.warn(f'{keyword or mediainfo.title} 未搜索到资源')
|
logger.warn(f'{keyword or mediainfo.title} 未搜索到资源')
|
||||||
return []
|
return []
|
||||||
# 过滤种子
|
# 过滤种子
|
||||||
if filter_rule is None:
|
if priority_rule is None:
|
||||||
# 取搜索优先级规则
|
# 取搜索优先级规则
|
||||||
filter_rule = self.systemconfig.get(SystemConfigKey.SearchFilterRules)
|
priority_rule = self.systemconfig.get(SystemConfigKey.SearchFilterRules)
|
||||||
if filter_rule:
|
if priority_rule:
|
||||||
logger.info(f'开始过滤资源,当前规则:{filter_rule} ...')
|
logger.info(f'开始过滤资源,当前规则:{priority_rule} ...')
|
||||||
result: List[TorrentInfo] = self.filter_torrents(rule_string=filter_rule,
|
result: List[TorrentInfo] = self.filter_torrents(rule_string=priority_rule,
|
||||||
torrent_list=torrents,
|
torrent_list=torrents,
|
||||||
season_episodes=season_episodes,
|
season_episodes=season_episodes,
|
||||||
mediainfo=mediainfo)
|
mediainfo=mediainfo)
|
||||||
@ -144,9 +146,10 @@ class SearchChain(ChainBase):
|
|||||||
logger.warn(f'{keyword or mediainfo.title} 没有符合优先级规则的资源')
|
logger.warn(f'{keyword or mediainfo.title} 没有符合优先级规则的资源')
|
||||||
return []
|
return []
|
||||||
# 使用默认过滤规则再次过滤
|
# 使用默认过滤规则再次过滤
|
||||||
torrents = self.filter_torrents_by_default_rule(torrents)
|
torrents = self.filter_torrents_by_rule(torrents=torrents,
|
||||||
|
filter_rule=filter_rule)
|
||||||
if not torrents:
|
if not torrents:
|
||||||
logger.warn(f'{keyword or mediainfo.title} 没有符合默认过滤规则的资源')
|
logger.warn(f'{keyword or mediainfo.title} 没有符合过滤规则的资源')
|
||||||
return []
|
return []
|
||||||
# 匹配的资源
|
# 匹配的资源
|
||||||
_match_torrents = []
|
_match_torrents = []
|
||||||
@ -314,28 +317,43 @@ class SearchChain(ChainBase):
|
|||||||
# 返回
|
# 返回
|
||||||
return results
|
return results
|
||||||
|
|
||||||
def filter_torrents_by_default_rule(self,
|
def filter_torrents_by_rule(self,
|
||||||
torrents: List[TorrentInfo]) -> List[TorrentInfo]:
|
torrents: List[TorrentInfo],
|
||||||
|
filter_rule: Dict[str, str] = None
|
||||||
|
) -> List[TorrentInfo]:
|
||||||
|
"""
|
||||||
|
使用过滤规则过滤种子
|
||||||
|
:param torrents: 种子列表
|
||||||
|
:param filter_rule: 过滤规则
|
||||||
|
"""
|
||||||
|
|
||||||
# 取默认过滤规则
|
# 取默认过滤规则
|
||||||
default_include_exclude = self.systemconfig.get(SystemConfigKey.DefaultIncludeExcludeFilter) or {}
|
if not filter_rule:
|
||||||
if not default_include_exclude:
|
filter_rule = self.systemconfig.get(SystemConfigKey.DefaultFilterRules)
|
||||||
|
if not filter_rule:
|
||||||
return torrents
|
return torrents
|
||||||
include = default_include_exclude.get("include")
|
# 包含
|
||||||
exclude = default_include_exclude.get("exclude")
|
include = filter_rule.get("include")
|
||||||
new_torrents = []
|
# 排除
|
||||||
for torrent in torrents:
|
exclude = filter_rule.get("exclude")
|
||||||
|
|
||||||
|
def __filter_torrent(t: TorrentInfo) -> bool:
|
||||||
|
"""
|
||||||
|
过滤种子
|
||||||
|
"""
|
||||||
# 包含
|
# 包含
|
||||||
if include:
|
if include:
|
||||||
if not re.search(r"%s" % include,
|
if not re.search(r"%s" % include,
|
||||||
f"{torrent.title} {torrent.description}", re.I):
|
f"{t.title} {t.description}", re.I):
|
||||||
logger.info(f"{torrent.title} 不匹配包含规则 {include}")
|
logger.info(f"{t.title} 不匹配包含规则 {include}")
|
||||||
continue
|
return False
|
||||||
# 排除
|
# 排除
|
||||||
if exclude:
|
if exclude:
|
||||||
if re.search(r"%s" % exclude,
|
if re.search(r"%s" % exclude,
|
||||||
f"{torrent.title} {torrent.description}", re.I):
|
f"{t.title} {t.description}", re.I):
|
||||||
logger.info(f"{torrent.title} 匹配排除规则 {exclude}")
|
logger.info(f"{t.title} 匹配排除规则 {exclude}")
|
||||||
continue
|
return False
|
||||||
new_torrents.append(torrent)
|
return True
|
||||||
return new_torrents
|
|
||||||
|
# 使用默认过滤规则再次过滤
|
||||||
|
return list(filter(lambda t: __filter_torrent(t), torrents))
|
||||||
|
@ -262,16 +262,25 @@ class SubscribeChain(ChainBase):
|
|||||||
sites = json.loads(subscribe.sites)
|
sites = json.loads(subscribe.sites)
|
||||||
else:
|
else:
|
||||||
sites = None
|
sites = None
|
||||||
# 过滤规则
|
# 优先级过滤规则
|
||||||
if subscribe.best_version:
|
if subscribe.best_version:
|
||||||
filter_rule = self.systemconfig.get(SystemConfigKey.BestVersionFilterRules)
|
priority_rule = self.systemconfig.get(SystemConfigKey.BestVersionFilterRules)
|
||||||
else:
|
else:
|
||||||
filter_rule = self.systemconfig.get(SystemConfigKey.SubscribeFilterRules)
|
priority_rule = self.systemconfig.get(SystemConfigKey.SubscribeFilterRules)
|
||||||
|
# 默认过滤规则
|
||||||
|
if subscribe.include or subscribe.exclude:
|
||||||
|
filter_rule = {
|
||||||
|
"include": subscribe.include,
|
||||||
|
"exclude": subscribe.exclude
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
filter_rule = self.systemconfig.get(SystemConfigKey.DefaultFilterRules)
|
||||||
# 搜索,同时电视剧会过滤掉不需要的剧集
|
# 搜索,同时电视剧会过滤掉不需要的剧集
|
||||||
contexts = self.searchchain.process(mediainfo=mediainfo,
|
contexts = self.searchchain.process(mediainfo=mediainfo,
|
||||||
keyword=subscribe.keyword,
|
keyword=subscribe.keyword,
|
||||||
no_exists=no_exists,
|
no_exists=no_exists,
|
||||||
sites=sites,
|
sites=sites,
|
||||||
|
priority_rule=priority_rule,
|
||||||
filter_rule=filter_rule)
|
filter_rule=filter_rule)
|
||||||
if not contexts:
|
if not contexts:
|
||||||
logger.warn(f'订阅 {subscribe.keyword or subscribe.name} 未搜索到资源')
|
logger.warn(f'订阅 {subscribe.keyword or subscribe.name} 未搜索到资源')
|
||||||
@ -477,10 +486,10 @@ class SubscribeChain(ChainBase):
|
|||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
no_exists = {}
|
no_exists = {}
|
||||||
# 包含与排除规则
|
# 默认过滤规则
|
||||||
default_include_exclude = self.systemconfig.get(SystemConfigKey.DefaultIncludeExcludeFilter) or {}
|
default_filter = self.systemconfig.get(SystemConfigKey.DefaultFilterRules) or {}
|
||||||
include = subscribe.include or default_include_exclude.get("include")
|
include = subscribe.include or default_filter.get("include")
|
||||||
exclude = subscribe.exclude or default_include_exclude.get("exclude")
|
exclude = subscribe.exclude or default_filter.get("exclude")
|
||||||
# 遍历缓存种子
|
# 遍历缓存种子
|
||||||
_match_context = []
|
_match_context = []
|
||||||
for domain, contexts in torrents.items():
|
for domain, contexts in torrents.items():
|
||||||
@ -493,7 +502,7 @@ class SubscribeChain(ChainBase):
|
|||||||
if torrent_mediainfo.tmdb_id != mediainfo.tmdb_id \
|
if torrent_mediainfo.tmdb_id != mediainfo.tmdb_id \
|
||||||
or torrent_mediainfo.type != mediainfo.type:
|
or torrent_mediainfo.type != mediainfo.type:
|
||||||
continue
|
continue
|
||||||
# 过滤规则
|
# 优先级过滤规则
|
||||||
if subscribe.best_version:
|
if subscribe.best_version:
|
||||||
filter_rule = self.systemconfig.get(SystemConfigKey.BestVersionFilterRules)
|
filter_rule = self.systemconfig.get(SystemConfigKey.BestVersionFilterRules)
|
||||||
else:
|
else:
|
||||||
|
@ -66,8 +66,8 @@ class SystemConfigKey(Enum):
|
|||||||
SubscribeFilterRules = "SubscribeFilterRules"
|
SubscribeFilterRules = "SubscribeFilterRules"
|
||||||
# 洗版规则
|
# 洗版规则
|
||||||
BestVersionFilterRules = "BestVersionFilterRules"
|
BestVersionFilterRules = "BestVersionFilterRules"
|
||||||
# 默认包含与排除规则
|
# 默认过滤规则
|
||||||
DefaultIncludeExcludeFilter = "DefaultIncludeExcludeFilter"
|
DefaultFilterRules = "DefaultFilterRules"
|
||||||
# 转移屏蔽词
|
# 转移屏蔽词
|
||||||
TransferExcludeWords = "TransferExcludeWords"
|
TransferExcludeWords = "TransferExcludeWords"
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user