mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-04 23:17:20 +08:00
@@ -660,10 +660,11 @@ class TransHandler:
|
|||||||
new_file_type = ""
|
new_file_type = ""
|
||||||
|
|
||||||
# 识别字幕语言
|
# 识别字幕语言
|
||||||
if re.search(_zhcn_sub_re, sub_item.name, re.I):
|
# 先识别繁中,避免“繁体中文/繁中字”等名称被后面的“中文/中字”简中兜底规则误判。
|
||||||
new_file_type = ".chi.zh-cn"
|
if re.search(_zhtw_sub_re, sub_item.name, re.I):
|
||||||
elif re.search(_zhtw_sub_re, sub_item.name, re.I):
|
|
||||||
new_file_type = ".zh-tw"
|
new_file_type = ".zh-tw"
|
||||||
|
elif re.search(_zhcn_sub_re, sub_item.name, re.I):
|
||||||
|
new_file_type = ".chi.zh-cn"
|
||||||
elif re.search(_ja_sub_re, sub_item.name, re.I):
|
elif re.search(_ja_sub_re, sub_item.name, re.I):
|
||||||
new_file_type = ".ja"
|
new_file_type = ".ja"
|
||||||
elif re.search(_eng_sub_re, sub_item.name, re.I):
|
elif re.search(_eng_sub_re, sub_item.name, re.I):
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
from pathlib import Path
|
||||||
|
from unittest import TestCase
|
||||||
|
|
||||||
|
from app.core.config import settings
|
||||||
|
from app.modules.filemanager.transhandler import TransHandler
|
||||||
|
from app.schemas.file import FileItem
|
||||||
|
|
||||||
|
|
||||||
|
class SubtitleRenameTest(TestCase):
|
||||||
|
def setUp(self) -> None:
|
||||||
|
self._default_sub = settings.DEFAULT_SUB
|
||||||
|
|
||||||
|
def tearDown(self) -> None:
|
||||||
|
settings.DEFAULT_SUB = self._default_sub
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _rename_subtitle(sub_name: str, default_sub: str) -> Path:
|
||||||
|
"""
|
||||||
|
直接调用字幕重命名逻辑,覆盖语言标签识别与默认字幕标记。
|
||||||
|
"""
|
||||||
|
settings.DEFAULT_SUB = default_sub
|
||||||
|
sub_item = FileItem(
|
||||||
|
storage="local",
|
||||||
|
type="file",
|
||||||
|
path=f"/source/{sub_name}.srt",
|
||||||
|
name=sub_name,
|
||||||
|
extension="srt",
|
||||||
|
)
|
||||||
|
target_file = Path("/target/24 Hours.2001.S02E01.[tmdbid=14064].srt")
|
||||||
|
return TransHandler._TransHandler__rename_subtitles(sub_item, target_file)
|
||||||
|
|
||||||
|
def test_traditional_chinese_subtitle_is_not_misclassified_as_simplified(self):
|
||||||
|
"""
|
||||||
|
issue #5703: “繁体中文” 不应命中简中兜底规则,也不应被打上默认简中标签。
|
||||||
|
"""
|
||||||
|
renamed = self._rename_subtitle("24.Hours.S02E01.繁体中文", default_sub="zh-cn")
|
||||||
|
self.assertEqual(
|
||||||
|
renamed.name,
|
||||||
|
"24 Hours.2001.S02E01.[tmdbid=14064].zh-tw.srt",
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_traditional_chinese_subtitle_can_be_marked_as_default(self):
|
||||||
|
"""
|
||||||
|
当默认字幕设置为繁中时,仍应保留正确的繁中语言后缀并追加 default 标记。
|
||||||
|
"""
|
||||||
|
renamed = self._rename_subtitle("24.Hours.S02E01.繁体中文", default_sub="zh-tw")
|
||||||
|
self.assertEqual(
|
||||||
|
renamed.name,
|
||||||
|
"24 Hours.2001.S02E01.[tmdbid=14064].default.zh-tw.srt",
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user