From 075a370b71880e6229d87bc386681e388949e33b Mon Sep 17 00:00:00 2001 From: jlw4049 Date: Tue, 23 Jul 2024 13:29:39 -0400 Subject: [PATCH] refactor: create a function `handle_fel_detection` to reduce code duplication --- dv_check.py | 90 ++++++++++++++++++++++++++++------------------------- 1 file changed, 47 insertions(+), 43 deletions(-) diff --git a/dv_check.py b/dv_check.py index 7e2ae26..0bf6f99 100644 --- a/dv_check.py +++ b/dv_check.py @@ -241,6 +241,35 @@ def create_fel( return el_mkv_output_path +def handle_fel_detection( + el_type: str, + prompt: bool, + create_fel_mkv: bool, + file_input: Path, + working_dir: Path, + ffmpeg: Path, + dovi_tool: Path, +) -> None: + if el_type != "FEL" and create_fel_mkv: + exit_print( + "You have loaded a Dolby Vision source file that does NOT have a Full " + "Enhancement Layer (FEL). You must load a standard template to continue " + "processing this file.", + 1, + ) + if el_type == "FEL": + if prompt: + exit_print( + "You have loaded a Dolby Vision source file with a Full Enhancement " + "Layer (FEL). You must load a FEL-enabled template to continue " + "processing this file.", + 1, + ) + if create_fel_mkv: + created_fel = create_fel(file_input, working_dir, ffmpeg, dovi_tool) + exit_print(f"FEL layer: {created_fel}", 0) + + if __name__ == "__main__": file_input, ffmpeg, dovi_tool, prompt, create_fel_mkv, working_dir = ( parse_arguments() @@ -253,54 +282,29 @@ if __name__ == "__main__": if existing_data: el_type = existing_data.get("EL") if el_type: - if el_type != "FEL" and create_fel_mkv: - exit_print( - "You have loaded a Dolby Vision source file that does NOT have a Full " - "Enhancement Layer (FEL). You must load a standard template to continue " - "processing this file.", - 1, - ) print(f"Data loaded, EL type: {el_type}") - if el_type == "FEL": - if prompt: - exit_print( - "You have loaded a Dolby Vision source file with a Full Enhancement " - "Layer (FEL). You must load a FEL-enabled template to continue " - "processing this file.", - 1, - ) - if create_fel_mkv: - created_fel = create_fel( - file_input, working_dir, ffmpeg, dovi_tool - ) - exit_print(f"FEL layer: {created_fel}", 0) + handle_fel_detection( + el_type, + prompt, + create_fel_mkv, + file_input, + working_dir, + ffmpeg, + dovi_tool, + ) else: rpu = read_rpu(file_input, ffmpeg, dovi_tool, working_dir) if rpu: - if rpu != "FEL" and create_fel_mkv: - exit_print( - "You have loaded a Dolby Vision source file that does NOT have a Full " - "Enhancement Layer (FEL). You must load a standard template to continue " - "processing this file.", - 1, - ) - if rpu == "MEL": - exit_print("EL layer is MEL, no processing needed", 0) - elif rpu == "FEL": - if prompt: - exit_print( - "You have loaded a Dolby Vision source file with a Full Enhancement " - "Layer (FEL). You must load a FEL-enabled template to continue " - "processing this file.", - 1, - ) - if create_fel_mkv: - created_fel = create_fel( - file_input, working_dir, ffmpeg, dovi_tool - ) - exit_print(f"FEL layer: {created_fel}", 0) + handle_fel_detection( + rpu, + prompt, + create_fel_mkv, + file_input, + working_dir, + ffmpeg, + dovi_tool, + ) else: exit_print("No RPU data extracted", 1) - else: exit_print("No EL layer detected", 0)