Merge pull request #755 from thsrite/customization
This commit is contained in:
commit
e773a9d9d4
@ -197,6 +197,7 @@ docker pull jxxghp/moviepilot:latest
|
|||||||
> `edition`: 版本(资源类型+特效)
|
> `edition`: 版本(资源类型+特效)
|
||||||
> `videoFormat`: 分辨率
|
> `videoFormat`: 分辨率
|
||||||
> `releaseGroup`: 制作组/字幕组
|
> `releaseGroup`: 制作组/字幕组
|
||||||
|
> `customization`: 自定义占位符
|
||||||
> `videoCodec`: 视频编码
|
> `videoCodec`: 视频编码
|
||||||
> `audioCodec`: 音频编码
|
> `audioCodec`: 音频编码
|
||||||
> `tmdbid`: TMDBID
|
> `tmdbid`: TMDBID
|
||||||
|
47
app/core/meta/customization.py
Normal file
47
app/core/meta/customization.py
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
import regex as re
|
||||||
|
|
||||||
|
from app.db.systemconfig_oper import SystemConfigOper
|
||||||
|
from app.schemas.types import SystemConfigKey
|
||||||
|
from app.utils.singleton import Singleton
|
||||||
|
|
||||||
|
|
||||||
|
class CustomizationMatcher(metaclass=Singleton):
|
||||||
|
"""
|
||||||
|
识别自定义占位符
|
||||||
|
"""
|
||||||
|
customization = None
|
||||||
|
custom_separator = None
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.systemconfig = SystemConfigOper()
|
||||||
|
self.customization = None
|
||||||
|
self.custom_separator = None
|
||||||
|
|
||||||
|
def match(self, title=None):
|
||||||
|
"""
|
||||||
|
:param title: 资源标题或文件名
|
||||||
|
:return: 匹配结果
|
||||||
|
"""
|
||||||
|
if not title:
|
||||||
|
return ""
|
||||||
|
if not self.customization:
|
||||||
|
# 自定义占位符
|
||||||
|
customization = self.systemconfig.get(SystemConfigKey.Customization)
|
||||||
|
if not customization:
|
||||||
|
return ""
|
||||||
|
if isinstance(customization, str):
|
||||||
|
customization = customization.replace("\n", ";").replace("|", ";").strip(";").split(";")
|
||||||
|
self.customization = "|".join([f"({item})" for item in customization])
|
||||||
|
|
||||||
|
customization_re = re.compile(r"%s" % self.customization)
|
||||||
|
# 处理重复多次的情况,保留先后顺序(按添加自定义占位符的顺序)
|
||||||
|
unique_customization = {}
|
||||||
|
for item in re.findall(customization_re, title):
|
||||||
|
if not isinstance(item, tuple):
|
||||||
|
item = (item,)
|
||||||
|
for i in range(len(item)):
|
||||||
|
if item[i] and unique_customization.get(item[i]) is None:
|
||||||
|
unique_customization[item[i]] = i
|
||||||
|
unique_customization = list(dict(sorted(unique_customization.items(), key=lambda x: x[1])).keys())
|
||||||
|
separator = self.custom_separator or "@"
|
||||||
|
return separator.join(unique_customization)
|
@ -1,6 +1,7 @@
|
|||||||
import re
|
import re
|
||||||
import zhconv
|
import zhconv
|
||||||
import anitopy
|
import anitopy
|
||||||
|
from app.core.meta.customization import CustomizationMatcher
|
||||||
from app.core.meta.metabase import MetaBase
|
from app.core.meta.metabase import MetaBase
|
||||||
from app.core.meta.releasegroup import ReleaseGroupsMatcher
|
from app.core.meta.releasegroup import ReleaseGroupsMatcher
|
||||||
from app.utils.string import StringUtils
|
from app.utils.string import StringUtils
|
||||||
@ -144,6 +145,8 @@ class MetaAnime(MetaBase):
|
|||||||
self.resource_team = \
|
self.resource_team = \
|
||||||
ReleaseGroupsMatcher().match(title=original_title) or \
|
ReleaseGroupsMatcher().match(title=original_title) or \
|
||||||
anitopy_info_origin.get("release_group") or None
|
anitopy_info_origin.get("release_group") or None
|
||||||
|
# 自定义占位符
|
||||||
|
self.customization = CustomizationMatcher().match(title=original_title) or None
|
||||||
# 视频编码
|
# 视频编码
|
||||||
self.video_encode = anitopy_info.get("video_term")
|
self.video_encode = anitopy_info.get("video_term")
|
||||||
if isinstance(self.video_encode, list):
|
if isinstance(self.video_encode, list):
|
||||||
|
@ -51,6 +51,8 @@ class MetaBase(object):
|
|||||||
resource_pix: Optional[str] = None
|
resource_pix: Optional[str] = None
|
||||||
# 识别的制作组/字幕组
|
# 识别的制作组/字幕组
|
||||||
resource_team: Optional[str] = None
|
resource_team: Optional[str] = None
|
||||||
|
# 识别的自定义占位符
|
||||||
|
customization: Optional[str] = None
|
||||||
# 视频编码
|
# 视频编码
|
||||||
video_encode: Optional[str] = None
|
video_encode: Optional[str] = None
|
||||||
# 音频编码
|
# 音频编码
|
||||||
@ -492,6 +494,9 @@ class MetaBase(object):
|
|||||||
# 制作组/字幕组
|
# 制作组/字幕组
|
||||||
if not self.resource_team:
|
if not self.resource_team:
|
||||||
self.resource_team = meta.resource_team
|
self.resource_team = meta.resource_team
|
||||||
|
# 自定义占位符
|
||||||
|
if not self.customization:
|
||||||
|
self.customization = meta.customization
|
||||||
# 特效
|
# 特效
|
||||||
if not self.resource_effect:
|
if not self.resource_effect:
|
||||||
self.resource_effect = meta.resource_effect
|
self.resource_effect = meta.resource_effect
|
||||||
|
@ -2,6 +2,7 @@ import re
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from app.core.config import settings
|
from app.core.config import settings
|
||||||
|
from app.core.meta.customization import CustomizationMatcher
|
||||||
from app.core.meta.metabase import MetaBase
|
from app.core.meta.metabase import MetaBase
|
||||||
from app.core.meta.releasegroup import ReleaseGroupsMatcher
|
from app.core.meta.releasegroup import ReleaseGroupsMatcher
|
||||||
from app.utils.string import StringUtils
|
from app.utils.string import StringUtils
|
||||||
@ -130,6 +131,8 @@ class MetaVideo(MetaBase):
|
|||||||
self.part = None
|
self.part = None
|
||||||
# 制作组/字幕组
|
# 制作组/字幕组
|
||||||
self.resource_team = ReleaseGroupsMatcher().match(title=original_title) or None
|
self.resource_team = ReleaseGroupsMatcher().match(title=original_title) or None
|
||||||
|
# 自定义占位符
|
||||||
|
self.customization = CustomizationMatcher().match(title=original_title) or None
|
||||||
|
|
||||||
def __fix_name(self, name: str):
|
def __fix_name(self, name: str):
|
||||||
if not name:
|
if not name:
|
||||||
|
@ -542,7 +542,9 @@ class FileTransferModule(_ModuleBase):
|
|||||||
# 剧集标题
|
# 剧集标题
|
||||||
"episode_title": episode_title,
|
"episode_title": episode_title,
|
||||||
# 文件后缀
|
# 文件后缀
|
||||||
"fileExt": file_ext
|
"fileExt": file_ext,
|
||||||
|
# 自定义占位符
|
||||||
|
"customization": meta.customization
|
||||||
}
|
}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -58,6 +58,8 @@ class SystemConfigKey(Enum):
|
|||||||
NotificationChannels = "NotificationChannels"
|
NotificationChannels = "NotificationChannels"
|
||||||
# 自定义制作组/字幕组
|
# 自定义制作组/字幕组
|
||||||
CustomReleaseGroups = "CustomReleaseGroups"
|
CustomReleaseGroups = "CustomReleaseGroups"
|
||||||
|
# 自定义占位符
|
||||||
|
Customization = "Customization"
|
||||||
# 自定义识别词
|
# 自定义识别词
|
||||||
CustomIdentifiers = "CustomIdentifiers"
|
CustomIdentifiers = "CustomIdentifiers"
|
||||||
# 搜索优先级规则
|
# 搜索优先级规则
|
||||||
|
Loading…
x
Reference in New Issue
Block a user