fix(subs): update SubtitleEdit CLI syntax and respect conversion_method

- Use lowercase format names (subrip, webvtt, advancedsubstationalpha) to match SubtitleEdit 4.x CLI requirements
- Change /Convert to /convert for consistency with CLI docs
- Convert Path objects to strings explicitly for subprocess calls
- Respect conversion_method config in SDH stripping - skip SubtitleEdit when user has set pysubs2/pycaption/subby as their preferred method
- Add stderr suppression to SubtitleEdit calls
This commit is contained in:
Andy
2026-01-19 00:32:19 +00:00
parent abd8fc2eb9
commit 90a7db2e46

View File

@@ -810,13 +810,18 @@ class Subtitle(Track):
if binaries.SubtitleEdit and self.codec not in (Subtitle.Codec.fTTML, Subtitle.Codec.fVTT): if binaries.SubtitleEdit and self.codec not in (Subtitle.Codec.fTTML, Subtitle.Codec.fVTT):
sub_edit_format = { sub_edit_format = {
Subtitle.Codec.SubStationAlphav4: "AdvancedSubStationAlpha", Subtitle.Codec.SubRip: "subrip",
Subtitle.Codec.TimedTextMarkupLang: "TimedText1.0", Subtitle.Codec.SubStationAlpha: "substationalpha",
}.get(codec, codec.name) Subtitle.Codec.SubStationAlphav4: "advancedsubstationalpha",
Subtitle.Codec.TimedTextMarkupLang: "timedtext1.0",
Subtitle.Codec.WebVTT: "webvtt",
Subtitle.Codec.SAMI: "sami",
Subtitle.Codec.MicroDVD: "microdvd",
}.get(codec, codec.name.lower())
sub_edit_args = [ sub_edit_args = [
binaries.SubtitleEdit, str(binaries.SubtitleEdit),
"/Convert", "/convert",
self.path, str(self.path),
sub_edit_format, sub_edit_format,
f"/outputfilename:{output_path.name}", f"/outputfilename:{output_path.name}",
"/encoding:utf8", "/encoding:utf8",
@@ -1207,18 +1212,26 @@ class Subtitle(Track):
except Exception: except Exception:
pass # Fall through to other methods pass # Fall through to other methods
if binaries.SubtitleEdit: conversion_method = config.subtitle.get("conversion_method", "auto")
if self.codec == Subtitle.Codec.SubStationAlphav4: use_subtitleedit = sdh_method == "subtitleedit" or (
output_format = "AdvancedSubStationAlpha" sdh_method == "auto" and conversion_method in ("auto", "subtitleedit")
elif self.codec == Subtitle.Codec.TimedTextMarkupLang: )
output_format = "TimedText1.0"
else: if binaries.SubtitleEdit and use_subtitleedit:
output_format = self.codec.name output_format = {
Subtitle.Codec.SubRip: "subrip",
Subtitle.Codec.SubStationAlpha: "substationalpha",
Subtitle.Codec.SubStationAlphav4: "advancedsubstationalpha",
Subtitle.Codec.TimedTextMarkupLang: "timedtext1.0",
Subtitle.Codec.WebVTT: "webvtt",
Subtitle.Codec.SAMI: "sami",
Subtitle.Codec.MicroDVD: "microdvd",
}.get(self.codec, self.codec.name.lower())
subprocess.run( subprocess.run(
[ [
binaries.SubtitleEdit, str(binaries.SubtitleEdit),
"/Convert", "/convert",
self.path, str(self.path),
output_format, output_format,
"/encoding:utf8", "/encoding:utf8",
"/overwrite", "/overwrite",
@@ -1226,6 +1239,7 @@ class Subtitle(Track):
], ],
check=True, check=True,
stdout=subprocess.DEVNULL, stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
) )
else: else:
if config.subtitle.get("convert_before_strip", True) and self.codec != Subtitle.Codec.SubRip: if config.subtitle.get("convert_before_strip", True) and self.codec != Subtitle.Codec.SubRip:
@@ -1267,18 +1281,21 @@ class Subtitle(Track):
if not binaries.SubtitleEdit: if not binaries.SubtitleEdit:
raise EnvironmentError("SubtitleEdit executable not found...") raise EnvironmentError("SubtitleEdit executable not found...")
if self.codec == Subtitle.Codec.SubStationAlphav4: output_format = {
output_format = "AdvancedSubStationAlpha" Subtitle.Codec.SubRip: "subrip",
elif self.codec == Subtitle.Codec.TimedTextMarkupLang: Subtitle.Codec.SubStationAlpha: "substationalpha",
output_format = "TimedText1.0" Subtitle.Codec.SubStationAlphav4: "advancedsubstationalpha",
else: Subtitle.Codec.TimedTextMarkupLang: "timedtext1.0",
output_format = self.codec.name Subtitle.Codec.WebVTT: "webvtt",
Subtitle.Codec.SAMI: "sami",
Subtitle.Codec.MicroDVD: "microdvd",
}.get(self.codec, self.codec.name.lower())
subprocess.run( subprocess.run(
[ [
binaries.SubtitleEdit, str(binaries.SubtitleEdit),
"/Convert", "/convert",
self.path, str(self.path),
output_format, output_format,
"/ReverseRtlStartEnd", "/ReverseRtlStartEnd",
"/encoding:utf8", "/encoding:utf8",
@@ -1286,6 +1303,7 @@ class Subtitle(Track):
], ],
check=True, check=True,
stdout=subprocess.DEVNULL, stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
) )