refactor: create a function handle_fel_detection to reduce code duplication

This commit is contained in:
jlw4049 2024-07-23 13:29:39 -04:00
parent 85641b680d
commit 075a370b71

@ -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)