From 6720dc8ef3a346a04c3740a5bba879921b4b7a72 Mon Sep 17 00:00:00 2001 From: ali Date: Tue, 17 Nov 2026 12:47:38 +0800 Subject: [PATCH] =?UTF-8?q?fix(subtitle):=20=E5=86=85=E7=BD=AE=E5=AD=97?= =?UTF-8?q?=E5=B9=95=E4=B8=B4=E6=97=B6=E6=96=87=E4=BB=B6=E6=94=B9=E7=94=A8?= =?UTF-8?q?=E7=9F=AD=E9=9A=8F=E6=9C=BA=E5=90=8D=EF=BC=8C=E9=81=BF=E5=85=8D?= =?UTF-8?q?=E8=B6=85=E9=95=BF=E6=A0=87=E9=A2=98=E8=A7=A6=E5=8F=91=20ENAMET?= =?UTF-8?q?OOLONG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 临时 ass 原名拼成 <目标名>.temp.<目标名>.ass,日文长标题下 UTF-8 字节数 轻松超过 255 触发 [Errno 36] File name too long,导致所有内置提取任务失败。 现改为 .scenerename-<12位hex>.ass;同时 do_extract 捕获 ffmpeg stderr 并 在失败时记录原因,scan_subtitles 的异常不再静默吞掉。 --- media/src/services/subtitle.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/media/src/services/subtitle.py b/media/src/services/subtitle.py index 3811f8a..7972708 100644 --- a/media/src/services/subtitle.py +++ b/media/src/services/subtitle.py @@ -3,6 +3,8 @@ import re import subprocess from pathlib import Path +from uuid import uuid4 + import pysubs2 from core import config from core.logger import log @@ -72,22 +74,24 @@ class SubtitleService: continue out_srt = task_mgr.reserve_path(desired_out_srt) - - temp_ass = dest_dir / f"{target_stem}.temp.{out_srt.name}.ass" - + + # ⚠️ 临时文件必须短:用 <目标名>.temp.<目标名>.ass 这种拼法在长标题(尤其日文/多字节)下 + # 会超过 Linux 的 255 字节文件名上限,导致 [Errno 36] File name too long。 + temp_ass = dest_dir / f".scenerename-{uuid4().hex[:12]}.ass" + task_mgr.add_extract( f"[提取内置字幕] {file_path.name} (轨道 {stream_idx}) --> {out_srt.name}", SubtitleService.do_extract, (file_path, stream_idx, temp_ass, out_srt) ) - except Exception: - pass + except Exception as e: + log.warning(f"⚠️ 内置字幕扫描失败: {file_path.name} -> {e}") @staticmethod def do_extract(file_path, stream_index, temp_ass, out_srt): cmd = ["ffmpeg", "-i", str(file_path), "-map", f"0:{stream_index}", "-c:s", "ass", "-f", "ass", "-y", str(temp_ass)] - res = subprocess.run(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) - + res = subprocess.run(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE, text=True, errors="ignore") + if res.returncode == 0 and temp_ass.exists() and temp_ass.stat().st_size > 0: try: subs = pysubs2.load(str(temp_ass), encoding="utf-8") @@ -95,9 +99,15 @@ class SubtitleService: line.text = re.sub(r'\{.*?\}', '', line.text) subs.save(str(out_srt), format="srt", encoding="utf-8") except Exception as e: - print(f"\n⚠️ 字幕 {out_srt.name} 洗白失败,已跳过。报错信息: {e}") + log.warning(f"⚠️ 字幕 {out_srt.name} 洗白失败,已跳过。报错信息: {e}") finally: temp_ass.unlink(missing_ok=True) else: + detail = "" + if res.stderr: + tail = [line for line in res.stderr.strip().splitlines() if line.strip()] + detail = tail[-1][:200] if tail else "" + log.warning(f"⚠️ 内置字幕提取失败: {file_path.name} (轨道 {stream_index}) " + f"ffmpeg={res.returncode} {detail}") temp_ass.unlink(missing_ok=True)