refactor: enhance customization and streaming platform handling

This commit is contained in:
jxxghp
2026-07-06 09:33:49 +08:00
parent 2f0c1252da
commit db9960d9b9
7 changed files with 66 additions and 30 deletions
+9 -2
View File
@@ -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:
+13 -9
View File
@@ -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 = []
+6
View File
@@ -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]:
"""
根据流媒体平台简称或全称获取标准名称。