feat(subtitle): 文本字幕外置化仅限 TRANSCODE 源;右键菜单合并为级联子菜单
- 内嵌 ASS 抽取与字体抽取挂到 verdict == TRANSCODE(extract-subs / --extract-internal 仍可强制),直传片源不再生成外挂副本 - 外挂 SRT 兜底仅在 [Subtitles] export 不含 ass 时启用,避免同语言双份 - 新增同语言判重(含旧命名 <stem>.<lang>.srt),重复抽取不再产生重复字幕 - 识别中英双语轨为 zh-en,语言白名单加入 zh-en - 外挂字幕统一 <stem>.internal.<lang>.srt 命名 - 右键菜单合并为 SceneMarshal 级联子菜单(ExtendedSubCommandsKey), 四项:媒体整理 / 媒体归档 / 补外挂字幕 / 入库校验,图标 assets/menu 自绘 - HANDOFF 补右键菜单说明;新增 docs/movie-duplicates.md 记录电影库清理
This commit is contained in:
@@ -44,7 +44,8 @@ keywords = TG频道,@yunpantv
|
||||
# 导出格式:ass(原始保真,默认)/ srt(清洗后);可写 ass,srt 同时导出
|
||||
export = ass
|
||||
# 只导出这些语言的轨;all 表示全部
|
||||
languages = zh-CN,zh-TW,en,und
|
||||
# zh-en = 中英双语轨(标题含"双语/中英/CHS&ENG"等)
|
||||
languages = zh-CN,zh-TW,zh-en,en,und
|
||||
# 允许处理的字幕轨编码;ass 轨用 -c:s copy 原样抽出,其余转成 ass
|
||||
codecs = ass,ssa,webvtt,subrip,mov_text
|
||||
# 内嵌优先:有内嵌字幕时不再处理外挂字幕
|
||||
@@ -80,7 +81,7 @@ max_direct_mbps = 70
|
||||
pre_extract_ass_gb = 15
|
||||
# 大文件自动抽 ASS(当前 export=ass 时已天然满足)
|
||||
auto_extract_ass = true
|
||||
# 必须转码的片源(DV5/老编码等)若无外挂字幕,自动导出文本字幕为外挂 SRT
|
||||
# 必须转码的片源(DV5/老编码等)的外挂字幕兜底;仅当 [Subtitles] export 不含 ass 时启用
|
||||
export_text_subs = true
|
||||
# 每次扫描是否输出体检报告
|
||||
write_report = true
|
||||
|
||||
+20
-11
@@ -141,8 +141,16 @@ class MediaPipeline:
|
||||
log.debug(f"✨ [完美豁免] {f.name} 已达最高工业标准,直接放行~")
|
||||
|
||||
if self.args.mode != "clean-ads":
|
||||
# 必须转码的片源:补外挂文本字幕,避免客户端选内嵌字幕时投递失败
|
||||
if config.EXPORT_TEXT_SUBS and pf.verdict == TRANSCODE:
|
||||
# 文本字幕(ASS / SRT)外置化只对必须转码的片源做:
|
||||
# 直传片源的内嵌字幕客户端能直接渲染,不需要外挂副本。
|
||||
# 显式 extract-subs 或 --extract-internal 视为强制,不受此限制。
|
||||
forced_subs = bool(self.args.extract_internal) or self.args.mode == "extract-subs"
|
||||
want_text_subs = forced_subs or pf.verdict == TRANSCODE
|
||||
|
||||
# 外挂 SRT 兜底:只在没配置 ASS 导出时启用,
|
||||
# 否则同一语言会同时出现 .internal.<lang>.ass 和 .srt 两份。
|
||||
if (want_text_subs and config.EXPORT_TEXT_SUBS and pf.verdict == TRANSCODE
|
||||
and 'ass' not in config.SUBTITLE_EXPORT):
|
||||
text_subs = [s for s in pf.info.get("subs", [])
|
||||
if (s.get("codec") or "").lower() in SubtitleService.TEXT_SUB_CODECS]
|
||||
if text_subs:
|
||||
@@ -151,26 +159,27 @@ class MediaPipeline:
|
||||
SubtitleService.export_text_sidecars,
|
||||
(f, dest_dir, target_stem),
|
||||
)
|
||||
|
||||
if config.PREFER_INTERNAL:
|
||||
# 🎯 内嵌字幕优先:先看内嵌,有就不再处理外挂
|
||||
internal_subs = 0
|
||||
if not skip_heavy or self.args.extract_internal or self.args.mode == "extract-subs":
|
||||
internal_subs = SubtitleService.scan_subtitles(f, self.task_mgr, target_stem, dest_dir)
|
||||
elif SubtitleService.has_internal_sub(dest_dir, target_stem):
|
||||
# 完美文件名豁免时不做 ffprobe,但仍需识别"已有内嵌字幕"
|
||||
internal_subs = 1
|
||||
if want_text_subs:
|
||||
if not skip_heavy or forced_subs:
|
||||
internal_subs = SubtitleService.scan_subtitles(f, self.task_mgr, target_stem, dest_dir)
|
||||
elif SubtitleService.has_internal_sub(dest_dir, target_stem):
|
||||
# 完美文件名豁免时不做 ffprobe,但仍需识别"已有内嵌字幕"
|
||||
internal_subs = 1
|
||||
|
||||
if internal_subs == 0:
|
||||
RenamerService.scan_existing_subtitles(f, target_stem, m_type, dest_dir, self.task_mgr)
|
||||
else:
|
||||
# 旧行为:外挂优先,没有外挂(或强制)时才提取内嵌
|
||||
has_ext_sub = RenamerService.scan_existing_subtitles(f, target_stem, m_type, dest_dir, self.task_mgr)
|
||||
if (not has_ext_sub or self.args.extract_internal or self.args.mode == "extract-subs") and (
|
||||
not skip_heavy or self.args.extract_internal or self.args.mode == "extract-subs"):
|
||||
if want_text_subs and (not has_ext_sub or forced_subs) and (not skip_heavy or forced_subs):
|
||||
SubtitleService.scan_subtitles(f, self.task_mgr, target_stem, dest_dir)
|
||||
|
||||
# 内嵌字体附件(ASS 特效字体还原)
|
||||
if config.EXTRACT_FONTS:
|
||||
# 内嵌字体附件(ASS 特效字体还原):只有抽了 ASS 才有意义
|
||||
if config.EXTRACT_FONTS and want_text_subs:
|
||||
SubtitleService.scan_fonts(f, self.task_mgr, dest_dir)
|
||||
|
||||
if self.args.mode != "extract-subs" and not skip_heavy:
|
||||
|
||||
@@ -92,6 +92,15 @@ class SubtitleService:
|
||||
lang = stream.get('tags', {}).get('language', 'und').lower()
|
||||
title = stream.get('tags', {}).get('title', '').lower()
|
||||
|
||||
# 中英双语轨:标题里同时出现中文与英文标识(或直接写"双语")时优先判定,
|
||||
# 否则会被下面的"简/繁"规则吞成单语。输出 zh-en,与 zh-CN / zh-TW 区分。
|
||||
has_cn = any(k in title for k in ('中', '简', '繁', 'chs', 'chi', 'zho'))
|
||||
has_en = any(k in title for k in ('英', 'eng', 'english'))
|
||||
if '双语' in title or 'bilingual' in title or (has_cn and has_en):
|
||||
return 'zh-en'
|
||||
if has_en and not has_cn:
|
||||
return 'en'
|
||||
|
||||
lang_code = "und"
|
||||
if lang in ['chi', 'zho', 'zh', 'chi-cn', 'zh-cn']: lang_code = 'zh-CN'
|
||||
elif lang in ['tw', 'hk', 'zh-tw']: lang_code = 'zh-TW'
|
||||
@@ -99,8 +108,12 @@ class SubtitleService:
|
||||
elif lang in ['jpn', 'ja']: lang_code = 'ja'
|
||||
elif lang in ['kor', 'ko']: lang_code = 'ko'
|
||||
|
||||
if '繁' in title or 'tw' in title or 'hk' in title or 'cht' in title: lang_code = 'zh-TW'
|
||||
elif '简' in title or 'cn' in title or '双语' in title or '中' in title or 'chs' in title: lang_code = 'zh-CN'
|
||||
if ('繁' in title or 'traditional' in title or '传统' in title or '正体' in title
|
||||
or 'tw' in title or 'hk' in title or 'cht' in title):
|
||||
lang_code = 'zh-TW'
|
||||
elif ('简' in title or 'simplified' in title or 'cn' in title
|
||||
or '中' in title or 'chs' in title):
|
||||
lang_code = 'zh-CN'
|
||||
elif '英' in title and lang_code == 'und': lang_code = 'en'
|
||||
elif '中' in title and lang_code == 'und': lang_code = 'zh-CN'
|
||||
|
||||
@@ -149,12 +162,34 @@ class SubtitleService:
|
||||
log.warning(f"⚠️ 内置字幕扫描失败: {file_path.name} -> {e}")
|
||||
return queued
|
||||
|
||||
@staticmethod
|
||||
def _existing_sidecar(dest_dir: Path, target_stem: str, lang: str, suffix: str) -> Path | None:
|
||||
"""同语言外挂字幕是否已存在(含早期不带 .internal 的命名与其它封装格式)。
|
||||
|
||||
老库里的字幕多为 <stem>.<lang>.srt(旧命名),若不认这些,重复抽取会在
|
||||
同一语言下再生成 .internal.<lang>.ass,Jellyfin 里就会出现两条同语言字幕。
|
||||
"""
|
||||
for name in (
|
||||
f"{target_stem}.internal.{lang}{suffix}.ass",
|
||||
f"{target_stem}.internal.{lang}{suffix}.srt",
|
||||
f"{target_stem}.{lang}{suffix}.srt",
|
||||
f"{target_stem}.{lang}{suffix}.ass",
|
||||
):
|
||||
p = dest_dir / name
|
||||
if p.exists() and p.stat().st_size > 0:
|
||||
return p
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def _queue_ass(file_path, task_mgr, target_stem, dest_dir, stream_idx, codec, lang_code, suffix) -> int:
|
||||
out_ass = dest_dir / f"{target_stem}.internal.{lang_code}{suffix}.ass"
|
||||
if out_ass.exists() and out_ass.stat().st_size > 0:
|
||||
log.debug(f"✨ [跳过导出] 目标内置 ASS 已存在: {out_ass.name}")
|
||||
return 1
|
||||
existing = SubtitleService._existing_sidecar(dest_dir, target_stem, lang_code, suffix)
|
||||
if existing is not None:
|
||||
log.debug(f"✨ [跳过导出] 同语言外挂字幕已存在: {existing.name}")
|
||||
return 1
|
||||
|
||||
temp_ass = dest_dir / f".scenemarshal-{uuid4().hex[:12]}.ass"
|
||||
task_mgr.add_extract(
|
||||
@@ -171,6 +206,9 @@ class SubtitleService:
|
||||
log.debug(f"✨ [跳过提取] 目标内置字幕已存在: {out_srt.name}")
|
||||
SubtitleService._drop_external_copies(out_srt)
|
||||
return 1
|
||||
if SubtitleService._existing_sidecar(dest_dir, target_stem, lang_code, suffix) is not None:
|
||||
log.debug(f"✨ [跳过提取] 同语言外挂字幕已存在: {target_stem}.{lang_code}{suffix}")
|
||||
return 1
|
||||
|
||||
temp_ass = dest_dir / f".scenemarshal-{uuid4().hex[:12]}.ass"
|
||||
task_mgr.add_extract(
|
||||
@@ -297,20 +335,12 @@ class SubtitleService:
|
||||
def export_text_sidecars(file_path: Path, dest_dir: Path, out_stem: str) -> int:
|
||||
"""给必须转码的片源补外挂 SRT(客户端本地渲染,避开内嵌字幕投递)。
|
||||
|
||||
- 已有同名外挂字幕(srt/ass/ssa)时整体跳过,避免覆盖用户的字幕;
|
||||
- 按轨逐条补:只导出目录里还缺的语言,已有的不动(便于老库补齐,
|
||||
例如后来才发现的中英双语轨);
|
||||
- 只处理文本字幕轨,图形字幕(PGS/DVD/DVB)跳过;
|
||||
- 命名 <out_stem>.<lang>.srt,已存在则跳过。
|
||||
- 命名 <out_stem>.internal.<lang>.srt,与内嵌抽取共用 .internal 标记;
|
||||
中英双语轨出 <out_stem>.internal.zh-en.srt。
|
||||
"""
|
||||
prefix = f"{out_stem}."
|
||||
try:
|
||||
for existing in dest_dir.iterdir():
|
||||
if (existing.is_file() and existing.name.startswith(prefix)
|
||||
and existing.suffix.lower() in {'.srt', '.ass', '.ssa'}):
|
||||
log.debug(f"✨ [跳过外挂字幕] 已存在: {existing.name}")
|
||||
return 0
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
data = FFprobeUtil.get_json(file_path, "-show_streams", "-select_streams", "s")
|
||||
if not data:
|
||||
return 0
|
||||
@@ -323,11 +353,17 @@ class SubtitleService:
|
||||
continue
|
||||
|
||||
lang = SubtitleService._lang_code(s)
|
||||
# 与内嵌抽取共用一份语言白名单,避免把马来语/泰米尔语这类杂轨也导出来
|
||||
if config.SUBTITLE_LANGUAGES and lang not in config.SUBTITLE_LANGUAGES:
|
||||
continue
|
||||
lang_counts[lang] = lang_counts.get(lang, 0) + 1
|
||||
suffix = "" if lang_counts[lang] == 1 else f".{lang_counts[lang]}"
|
||||
out_srt = dest_dir / f"{out_stem}.{lang}{suffix}.srt"
|
||||
out_srt = dest_dir / f"{out_stem}.internal.{lang}{suffix}.srt"
|
||||
# 早期版本不带 .internal 标记,同语言外挂已存在时同样视为已补齐,避免重复
|
||||
legacy_srt = dest_dir / f"{out_stem}.{lang}{suffix}.srt"
|
||||
|
||||
if out_srt.exists() and out_srt.stat().st_size > 0:
|
||||
if (out_srt.exists() and out_srt.stat().st_size > 0) or (
|
||||
legacy_srt.exists() and legacy_srt.stat().st_size > 0):
|
||||
continue
|
||||
|
||||
temp = dest_dir / f".scenemarshal-{uuid4().hex[:12]}.srt"
|
||||
|
||||
Reference in New Issue
Block a user