提取内置字幕

This commit is contained in:
Hraulein
2026-05-10 20:54:23 +08:00
parent 083e82ab22
commit ec0250ccb5
3 changed files with 52 additions and 17 deletions
+25 -9
View File
@@ -128,7 +128,8 @@ class RenamerService:
except: return "und"
@staticmethod
def scan_existing_subtitles(f_path: Path, target_stem: str, m_type: str, dest_dir: Path, task_mgr):
def scan_existing_subtitles(f_path: Path, target_stem: str, m_type: str, dest_dir: Path, task_mgr) -> bool:
has_external_sub = False # 💡 初始化状态标识
for sub in f_path.parent.glob("*"):
if sub.is_file() and sub.suffix.lower() in {'.srt', '.ass', '.ssa'}:
is_match = False
@@ -142,18 +143,33 @@ class RenamerService:
is_match = True
if is_match:
has_external_sub = True # 💡 只要匹配到,就说明存在外挂字幕
lang_tag = RenamerService.detect_subtitle_language(sub)
desired_path = dest_dir / f"{target_stem}.{lang_tag}{sub.suffix.lower()}"
# 💡 传入 source_path,如果计算出的名字存在且就是自己,就不会强制加 .2
reserved_path = task_mgr.reserve_path(desired_path, source_path=sub)
if sub.resolve() != reserved_path.resolve():
task_mgr.add_file_rename(
f"[外挂字幕] {sub.name} --> {reserved_path.name}",
RenamerService.do_rename_single,
# 💡 核心修改 1.2: 如果不是 srt,执行转换任务
if sub.suffix.lower() != '.srt':
desired_path = dest_dir / f"{target_stem}.{lang_tag}.srt"
reserved_path = task_mgr.reserve_path(desired_path, source_path=sub)
from services.subtitle import SubtitleService # 延迟导入
task_mgr.add_extract(
f"[外挂字幕转换] {sub.name} --> {reserved_path.name}",
SubtitleService.convert_to_srt,
(sub, reserved_path)
)
else:
# 是 srt,正常走重命名
desired_path = dest_dir / f"{target_stem}.{lang_tag}.srt"
reserved_path = task_mgr.reserve_path(desired_path, source_path=sub)
if sub.resolve() != reserved_path.resolve():
task_mgr.add_file_rename(
f"[规范外挂字幕] {sub.name} --> {reserved_path.name}",
RenamerService.do_rename_single,
(sub, reserved_path)
)
return has_external_sub # 💡 把结果返回给 main.py
@staticmethod
def scan_rename(f_path: Path, target_stem: str, m_type: str, dest_dir: Path, target_season_folder: str, root_dir_path: Path, target_root_folder: str, task_mgr):