mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-07 08:26:53 +08:00
refactor(string): split utilities by responsibility
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import regex as re
|
||||
|
||||
from app.domain.meta.metabase import MetaBase
|
||||
from app.domain.string import StringUtils
|
||||
from app.foundation import text as text_tools
|
||||
|
||||
AUXILIARY_CN_STEM_FULLMATCH_RE = re.compile(
|
||||
r"^(双语|字幕|特效|内封|外挂|官译|简体|繁体|繁中|简中|中英|简英|多语|"
|
||||
@@ -27,7 +27,7 @@ def should_use_parent_title_for_file_stem(
|
||||
return False
|
||||
if not PARENT_LATIN_TITLE_RE.search(parent_dir_name):
|
||||
return False
|
||||
if not StringUtils.is_all_chinese(stem):
|
||||
if not text_tools.is_all_chinese(stem):
|
||||
return False
|
||||
if len(stem) > 16:
|
||||
return False
|
||||
|
||||
@@ -6,7 +6,8 @@ import anitopy
|
||||
from app.domain.meta.customization import CustomizationMatcher
|
||||
from app.domain.meta.metabase import MetaBase
|
||||
from app.domain.meta.releasegroup import ReleaseGroupsMatcher
|
||||
from app.domain.string import StringUtils
|
||||
from app.domain import title as title_rules
|
||||
from app.foundation import text as text_tools
|
||||
from app.foundation.text import convert as zhconv_convert
|
||||
from app.schemas.types import MediaType
|
||||
|
||||
@@ -64,11 +65,11 @@ class MetaAnime(MetaBase):
|
||||
if anitopy_info:
|
||||
# 名称
|
||||
name = anitopy_info.get("anime_title")
|
||||
if not name or name in self._anime_no_words or (len(name) < 5 and not StringUtils.is_chinese(name)):
|
||||
if not name or name in self._anime_no_words or (len(name) < 5 and not text_tools.contains_chinese(name)):
|
||||
anitopy_info = anitopy.parse("[ANIME]" + title)
|
||||
if anitopy_info:
|
||||
name = anitopy_info.get("anime_title")
|
||||
if not name or name in self._anime_no_words or (len(name) < 5 and not StringUtils.is_chinese(name)):
|
||||
if not name or name in self._anime_no_words or (len(name) < 5 and not text_tools.contains_chinese(name)):
|
||||
name_match = BRACKET_TITLE_RE.search(title)
|
||||
if name_match and name_match.group(1):
|
||||
name = name_match.group(1).strip()
|
||||
@@ -78,12 +79,12 @@ class MetaAnime(MetaBase):
|
||||
# 按/拆分中英文
|
||||
if name.find("/") != -1:
|
||||
names = name.split("/")
|
||||
if StringUtils.is_chinese(names[0]):
|
||||
if text_tools.contains_chinese(names[0]):
|
||||
self.cn_name = names[0]
|
||||
if len(names) > 1:
|
||||
self.en_name = names[1]
|
||||
_split_flag = False
|
||||
elif StringUtils.is_chinese(names[-1]):
|
||||
elif text_tools.contains_chinese(names[-1]):
|
||||
self.cn_name = names[-1]
|
||||
if len(names) > 1:
|
||||
self.en_name = names[0]
|
||||
@@ -103,19 +104,19 @@ class MetaAnime(MetaBase):
|
||||
self.cn_name = "%s %s" % (self.cn_name or "", word)
|
||||
elif lastword_type == "en":
|
||||
self.en_name = "%s %s" % (self.en_name or "", word)
|
||||
elif StringUtils.is_chinese(word):
|
||||
elif text_tools.contains_chinese(word):
|
||||
self.cn_name = "%s %s" % (self.cn_name or "", word)
|
||||
lastword_type = "cn"
|
||||
else:
|
||||
self.en_name = "%s %s" % (self.en_name or "", word)
|
||||
lastword_type = "en"
|
||||
if self.cn_name:
|
||||
_, self.cn_name, _, _, _, _ = StringUtils.get_keyword(self.cn_name)
|
||||
_, self.cn_name, _, _, _, _ = title_rules.parse_search_keyword(self.cn_name)
|
||||
if self.cn_name:
|
||||
self.cn_name = self._name_nostring_pattern.sub('', self.cn_name).strip()
|
||||
if self.en_name:
|
||||
self.en_name = self._name_nostring_pattern.sub('', self.en_name).strip().title()
|
||||
self._name = StringUtils.str_title(self.en_name)
|
||||
self._name = text_tools.title_case(self.en_name)
|
||||
# 年份
|
||||
year = anitopy_info.get("anime_year")
|
||||
if str(year).isdigit():
|
||||
@@ -271,7 +272,7 @@ class MetaAnime(MetaBase):
|
||||
else:
|
||||
titles.append("%s%s" % (left_char, name.split("/")[0].strip()))
|
||||
elif name:
|
||||
if StringUtils.is_chinese(name) and not StringUtils.is_all_chinese(name):
|
||||
if text_tools.contains_chinese(name) and not text_tools.is_all_chinese(name):
|
||||
if not NUMERIC_BRACKET_RE.search(name):
|
||||
name = MIXED_CHINESE_TOKEN_RE.sub('', name).strip()
|
||||
if not name or name.strip().isdigit():
|
||||
|
||||
@@ -8,7 +8,7 @@ import regex as re
|
||||
|
||||
from app.schemas.types import MediaSource, MediaType
|
||||
from app.schemas.media import resolve_media_identity
|
||||
from app.domain.string import StringUtils
|
||||
from app.foundation import text as text_tools
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -128,7 +128,7 @@ class MetaBase(object):
|
||||
"""
|
||||
返回名称
|
||||
"""
|
||||
if self.cn_name and StringUtils.is_all_chinese(self.cn_name):
|
||||
if self.cn_name and text_tools.is_all_chinese(self.cn_name):
|
||||
return self.cn_name
|
||||
elif self.en_name:
|
||||
return self.en_name
|
||||
@@ -141,7 +141,7 @@ class MetaBase(object):
|
||||
"""
|
||||
设置名称
|
||||
"""
|
||||
if StringUtils.is_all_chinese(name):
|
||||
if text_tools.is_all_chinese(name):
|
||||
self.cn_name = name
|
||||
else:
|
||||
self.en_name = name
|
||||
|
||||
@@ -7,7 +7,7 @@ from app.domain.meta.customization import CustomizationMatcher
|
||||
from app.domain.meta.metabase import MetaBase
|
||||
from app.domain.meta.releasegroup import ReleaseGroupsMatcher
|
||||
from app.schemas.types import MediaType
|
||||
from app.domain.string import StringUtils
|
||||
from app.foundation import text as text_tools
|
||||
from app.domain.tokens import Tokens
|
||||
from app.domain.meta.streamingplatform import StreamingPlatforms
|
||||
from app.domain.meta.runtime import get_media_extensions
|
||||
@@ -218,7 +218,7 @@ class MetaVideo(MetaBase):
|
||||
self.init_subtitle(self.subtitle)
|
||||
# 去掉名字中不需要的干扰字符,过短的纯数字不要
|
||||
self.cn_name = self.__fix_name(self.cn_name)
|
||||
self.en_name = StringUtils.str_title(self.__fix_name(self.en_name))
|
||||
self.en_name = text_tools.title_case(self.__fix_name(self.en_name))
|
||||
# 处理part
|
||||
if self.part and self.part.upper() == "PART":
|
||||
self.part = None
|
||||
@@ -245,7 +245,7 @@ class MetaVideo(MetaBase):
|
||||
if not description:
|
||||
return None
|
||||
titles = DESCRIPTION_SPLIT_RE.split(description)
|
||||
if StringUtils.is_chinese(titles[0]):
|
||||
if text_tools.contains_chinese(titles[0]):
|
||||
return titles[0]
|
||||
return None
|
||||
|
||||
@@ -308,7 +308,7 @@ class MetaVideo(MetaBase):
|
||||
if token in self._name_se_words:
|
||||
self._last_token_type = 'name_se_words'
|
||||
return
|
||||
if StringUtils.is_chinese(token):
|
||||
if text_tools.contains_chinese(token):
|
||||
# 含有中文,直接做为标题(连着的数字或者英文会保留),且不再取用后面出现的中文
|
||||
self._last_token_type = "cnname"
|
||||
if not self.cn_name:
|
||||
|
||||
Reference in New Issue
Block a user