From 5b9140a8f3d3d11e81e6d8809a4c72f821f147c6 Mon Sep 17 00:00:00 2001 From: v2lmmj04 <122140891+v2lmmj04@users.noreply.github.com> Date: Wed, 19 Mar 2025 22:25:45 -0700 Subject: [PATCH] Improve LRC output by removing SRT styles ASS files, or even SRT files, may contain styles / markup that are not desirable to exist as part of the final output when exporting subtitles (especially LRC files). This updates the ffmpeg command when converting subtitles to use a plain text format that removes any sort of styling. It results in SRT files also always being "converted" as a result, as they may have styling that needs removed as well. It may not handle cases where `convert_sub_if_needed` is not called, such as through the `condense_multi` -> `extract_srt` code path that seems to skip calling this function. --- condenser.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/condenser.py b/condenser.py index 978cfdb..4213a09 100644 --- a/condenser.py +++ b/condenser.py @@ -302,15 +302,14 @@ def get_srt(subtitle_streams: List[dict], file_folder: str, filename: str, temp_ def convert_sub_if_needed(sub_path: str, temp_dir: str) -> str: - sub_root, sub_ext = op.splitext(sub_path) - if sub_ext.lower() != ".srt": - srt_path = op.join(temp_dir, "out.srt") - sub_convert_cmd = [ffmpeg_cmd, "-i", sub_path, srt_path] - result = sp.run(sub_convert_cmd, capture_output=True) - if result.returncode != 0: - raise SubtitleError("Could not open subtitle file " + sub_path + ": " + str(result.stderr)) - else: - srt_path = sub_path + srt_path = op.join(temp_dir, "out.srt") + + # Run ffmpeg even if the format doesn't change, as srt files may contain non-standard markup that should be stripped + sub_convert_cmd = [ffmpeg_cmd, "-i", sub_path, "-c:s", "text", srt_path] + result = sp.run(sub_convert_cmd, capture_output=True) + if result.returncode != 0: + raise SubtitleError("Could not open subtitle file " + sub_path + ": " + str(result.stderr)) + return srt_path