From 8a21d120a08c71f009a7910ec59476dc89abefbc Mon Sep 17 00:00:00 2001 From: McCloudS <64094529+McCloudS@users.noreply.github.com> Date: Mon, 5 Aug 2024 18:24:08 -0600 Subject: [PATCH] Fixed cases where force_detected_language was overwriting intended case --- subgen.py | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/subgen.py b/subgen.py index ac2d4f7..bf1a1b2 100644 --- a/subgen.py +++ b/subgen.py @@ -546,7 +546,9 @@ def gen_subtitles(file_path: str, transcription_type: str, force_language=None) start_time = time.time() start_model() - if force_detected_language_to: + if force_language: + break + elif force_detected_language_to: force_language = force_detected_language_to logging.info(f"Forcing language to {force_language}") @@ -585,16 +587,27 @@ def gen_subtitles_queue(file_path: str, transcription_type: str, force_language= return message = None - if has_subtitle_language(file_path, skipifinternalsublang): - message = f"{file_path} already has an internal subtitle we want, skipping generation" - elif os.path.exists(get_file_name_without_extension(file_path) + subextension): - message = f"{file_path} already has a subtitle created for this, skipping it" - elif skipifexternalsub and os.path.exists(get_file_name_without_extension(file_path) + f".{namesublang}.srt"): - message = f"{file_path} already has an external {namesublang} subtitle created for this, skipping it" - elif os.path.exists(get_file_name_without_extension(file_path) + subextensionSDH): - message = f"{file_path} already has a SDH subtitle created for this, skipping it" - elif os.path.exists(get_file_name_without_extension(file_path) + '.lrc'): - message = f"{file_path} already has a LRC created for this, skipping it" + + # Check if force_language is set + if force_language: + # Check if an internal subtitle with the force_language already exists + if has_subtitle_language(file_path, force_language): + message = f"{file_path} already has an internal subtitle for {force_language}, skipping generation" + # Check if an external subtitle with the force_language already exists + elif os.path.exists(get_file_name_without_extension(file_path) + f".{force_language}.srt"): + message = f"{file_path} already has an external {force_language} subtitle created for this, skipping it" + else: + if has_subtitle_language(file_path, skipifinternalsublang): + message = f"{file_path} already has an internal subtitle we want, skipping generation" + elif os.path.exists(get_file_name_without_extension(file_path) + subextension): + message = f"{file_path} already has a subtitle created for this, skipping it" + elif skipifexternalsub and os.path.exists(get_file_name_without_extension(file_path) + f".{namesublang}.srt"): + message = f"{file_path} already has an external {namesublang} subtitle created for this, skipping it" + elif os.path.exists(get_file_name_without_extension(file_path) + subextensionSDH): + message = f"{file_path} already has a SDH subtitle created for this, skipping it" + elif os.path.exists(get_file_name_without_extension(file_path) + '.lrc'): + message = f"{file_path} already has a LRC created for this, skipping it" + if message: logging.info(message) return