(file, dubbing=False, is_retry=False)
| 17 | YTB_RESOLUTION_KEY = "ytb_resolution" |
| 18 | |
| 19 | def process_video(file, dubbing=False, is_retry=False): |
| 20 | if not is_retry: |
| 21 | prepare_output_folder(OUTPUT_DIR) |
| 22 | |
| 23 | text_steps = [ |
| 24 | ("๐ฅ Processing input file", partial(process_input_file, file)), |
| 25 | ("๐๏ธ Transcribing with Whisper", partial(_2_asr.transcribe)), |
| 26 | ("โ๏ธ Splitting sentences", split_sentences), |
| 27 | ("๐ Summarizing and translating", summarize_and_translate), |
| 28 | ("โก Processing and aligning subtitles", process_and_align_subtitles), |
| 29 | ("๐ฌ Merging subtitles to video", _7_sub_into_vid.merge_subtitles_to_video), |
| 30 | ] |
| 31 | |
| 32 | if dubbing: |
| 33 | dubbing_steps = [ |
| 34 | ("๐ Generating audio tasks", gen_audio_tasks), |
| 35 | ("๐ต Extracting reference audio", _9_refer_audio.extract_refer_audio_main), |
| 36 | ("๐ฃ๏ธ Generating audio", _10_gen_audio.gen_audio), |
| 37 | ("๐ Merging full audio", _11_merge_audio.merge_full_audio), |
| 38 | ("๐๏ธ Merging dubbing to video", _12_dub_to_vid.merge_video_audio), |
| 39 | ] |
| 40 | text_steps.extend(dubbing_steps) |
| 41 | |
| 42 | current_step = "" |
| 43 | for step_name, step_func in text_steps: |
| 44 | current_step = step_name |
| 45 | for attempt in range(3): |
| 46 | try: |
| 47 | console.print(Panel( |
| 48 | f"[bold green]{step_name}[/]", |
| 49 | subtitle=f"Attempt {attempt + 1}/3" if attempt > 0 else None, |
| 50 | border_style="blue" |
| 51 | )) |
| 52 | result = step_func() |
| 53 | if result is not None: |
| 54 | globals().update(result) |
| 55 | break |
| 56 | except Exception as e: |
| 57 | if attempt == 2: |
| 58 | error_panel = Panel( |
| 59 | f"[bold red]Error in step '{current_step}':[/]\n{str(e)}", |
| 60 | border_style="red" |
| 61 | ) |
| 62 | console.print(error_panel) |
| 63 | cleanup(ERROR_OUTPUT_DIR) |
| 64 | return False, current_step, str(e) |
| 65 | console.print(Panel( |
| 66 | f"[yellow]Attempt {attempt + 1} failed. Retrying...[/]", |
| 67 | border_style="yellow" |
| 68 | )) |
| 69 | |
| 70 | console.print(Panel("[bold green]All steps completed successfully! ๐[/]", border_style="green")) |
| 71 | cleanup(SAVE_DIR) |
| 72 | return True, "", "" |
| 73 | |
| 74 | def prepare_output_folder(output_folder): |
| 75 | if os.path.exists(output_folder): |
no test coverage detected