fix(subtitle): drive SubtitleEdit 4.x with legacy /convert syntax

Registry refactor (2923292) emitted seconv-only --flags; 4.x opened the GUI per subtitle. Pick syntax per binary; prefer seconv for 5.x.
This commit is contained in:
imSp4rky
2026-06-11 19:09:06 -06:00
parent e207116d30
commit 680f5059b5
2 changed files with 25 additions and 8 deletions

View File

@@ -37,7 +37,8 @@ def find(*names: str) -> Optional[Path]:
FFMPEG = find("ffmpeg")
FFProbe = find("ffprobe")
FFPlay = find("ffplay")
SubtitleEdit = find("SubtitleEdit", "seconv") # seconv = cross-platform subtitleedit-cli (.NET 8)
# seconv = SubtitleEdit 5+ CLI (the 5.0 GUI has no batch mode); SubtitleEdit = 4.x
SubtitleEdit = find("seconv", "SubtitleEdit")
ShakaPackager = find(
"shaka-packager",
"packager",

View File

@@ -65,6 +65,12 @@ PYSUBS2_FORMATS: dict[Codec, str] = {
}
def is_seconv(binary: object) -> bool:
"""True for the SubtitleEdit 5+ CLI (seconv); 4.x binaries need legacy /convert syntax."""
name = str(binary).replace("\\", "/").rsplit("/", 1)[-1]
return name.lower().rsplit(".", 1)[0] == "seconv"
def subtitleedit_args(
binary: object,
src: Path,
@@ -76,15 +82,25 @@ def subtitleedit_args(
reverse_rtl: bool = False,
) -> list[str]:
"""
Build a SubtitleEdit batch-convert command.
Build a SubtitleEdit batch-convert command in 5.x (seconv ``--flags``) or 4.x
(``/convert /flags``) syntax, per ``is_seconv``.
Targets the SubtitleEdit 5+ CLI (``SeConv`` / ``seconv`` on every platform), which takes
``--flags`` with a positional ``<pattern> <format>`` (no legacy ``/convert`` verb). The
SE5 converter names the output ``<input-stem>.<format-ext>``; pass ``output_folder`` to
place it next to a chosen path (a bare ``--output-filename`` resolves against the *cwd*,
not the input dir, so we always steer with ``--output-folder``). ``--overwrite`` is always
set so re-runs and in-place transforms (SDH/RTL) don't fail on an existing file.
Both name the output ``<input-stem>.<format-ext>``; ``output_folder`` steers placement
(a bare ``--output-filename`` resolves against the cwd, not the input dir). Overwrite is
always set so re-runs and in-place transforms (SDH/RTL) don't fail on an existing file.
"""
if not is_seconv(binary):
args = [str(binary), "/convert", str(src), fmt, "/encoding:utf8", "/overwrite"]
if output_folder is not None:
args.append(f"/outputfolder:{output_folder}")
if convert_colors:
args.append("/ConvertColorsToDialog")
if remove_hi:
args.append("/RemoveTextForHI")
if reverse_rtl:
args.append("/ReverseRtlStartEnd")
return args
args = [str(binary), str(src), fmt, "--encoding:utf-8", "--overwrite"]
if output_folder is not None:
args.append(f"--output-folder:{output_folder}")