mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 23:47:41 +08:00
refactor: enhance customization and streaming platform handling
This commit is contained in:
@@ -17,7 +17,7 @@ class CustomizationMatcher(metaclass=Singleton):
|
||||
self._customization_re_cache = {}
|
||||
|
||||
@staticmethod
|
||||
def _normalize_customization(customization):
|
||||
def normalize_customization(customization):
|
||||
"""
|
||||
规范化自定义占位符配置,兼容历史字符串与列表两种保存格式。
|
||||
"""
|
||||
@@ -27,6 +27,13 @@ class CustomizationMatcher(metaclass=Singleton):
|
||||
return []
|
||||
return list(filter(None, customization))
|
||||
|
||||
@staticmethod
|
||||
def _normalize_customization(customization):
|
||||
"""
|
||||
兼容旧调用,统一转到公开的自定义占位符规范化入口。
|
||||
"""
|
||||
return CustomizationMatcher.normalize_customization(customization)
|
||||
|
||||
def match(self, title=None):
|
||||
"""
|
||||
:param title: 资源标题或文件名
|
||||
@@ -35,7 +42,7 @@ class CustomizationMatcher(metaclass=Singleton):
|
||||
if not title:
|
||||
return ""
|
||||
# 自定义占位符需要跟随系统配置实时生效,避免单例缓存导致保存后仍沿用旧规则。
|
||||
customization = self._normalize_customization(
|
||||
customization = self.normalize_customization(
|
||||
self.systemconfig.get(SystemConfigKey.Customization)
|
||||
)
|
||||
if not customization:
|
||||
|
||||
@@ -89,6 +89,18 @@ class ReleaseGroupsMatcher(metaclass=Singleton):
|
||||
self.systemconfig = SystemConfigOper()
|
||||
self.__groups_re_cache = {}
|
||||
|
||||
def get_release_groups(self) -> str:
|
||||
"""
|
||||
返回内置与用户自定义制作组组成的匹配规则。
|
||||
"""
|
||||
custom_release_groups = self.systemconfig.get(SystemConfigKey.CustomReleaseGroups)
|
||||
if isinstance(custom_release_groups, list):
|
||||
custom_release_groups = list(filter(None, custom_release_groups))
|
||||
if custom_release_groups:
|
||||
custom_release_groups_str = '|'.join(custom_release_groups)
|
||||
return f"{self.__release_groups}|{custom_release_groups_str}"
|
||||
return self.__release_groups
|
||||
|
||||
def __get_groups_re(self, groups: str):
|
||||
"""
|
||||
发布组规则通常很长,按规则文本缓存编译结果,避免每个标题都重复编译。
|
||||
@@ -108,15 +120,7 @@ class ReleaseGroupsMatcher(metaclass=Singleton):
|
||||
if not title:
|
||||
return ""
|
||||
if not groups:
|
||||
# 自定义组
|
||||
custom_release_groups = self.systemconfig.get(SystemConfigKey.CustomReleaseGroups)
|
||||
if isinstance(custom_release_groups, list):
|
||||
custom_release_groups = list(filter(None, custom_release_groups))
|
||||
if custom_release_groups:
|
||||
custom_release_groups_str = '|'.join(custom_release_groups)
|
||||
groups = f"{self.__release_groups}|{custom_release_groups_str}"
|
||||
else:
|
||||
groups = self.__release_groups
|
||||
groups = self.get_release_groups()
|
||||
title = f"{title} "
|
||||
groups_re = self.__get_groups_re(groups)
|
||||
unique_groups = []
|
||||
|
||||
@@ -297,6 +297,12 @@ class StreamingPlatforms(metaclass=Singleton):
|
||||
if alias:
|
||||
self._lookup_cache[alias.upper()] = canonical_name
|
||||
|
||||
def get_lookup_cache(self) -> dict:
|
||||
"""
|
||||
返回流媒体平台查询表副本,供批量解析配置复用。
|
||||
"""
|
||||
return dict(self._lookup_cache)
|
||||
|
||||
def get_streaming_platform_name(self, platform_code: str) -> Optional[str]:
|
||||
"""
|
||||
根据流媒体平台简称或全称获取标准名称。
|
||||
|
||||
Reference in New Issue
Block a user