11import os , sys
22sys .path .append (os .path .join (os .path .dirname (__file__ ), '..' , '..' ))
3- from core import step1_ytdlp , step2_whisperX , step3_1_spacy_split , step3_2_splitbymeaning , step8_1_gen_audio_task
4- from core import step4_1_summarize , step4_2_translate_all , step5_splitforsub , step6_generate_final_timeline
5- from core import step7_merge_sub_to_vid , step10_gen_audio , step11_merge_audio_to_vid
3+ from st_components .imports_and_utils import *
64from core .onekeycleanup import cleanup
75from core .config_utils import load_key
86import shutil
97from functools import partial
8+ from rich .panel import Panel
9+ from rich .console import Console
10+
11+ console = Console ()
12+
13+ INPUT_DIR = 'batch/input'
14+ OUTPUT_DIR = 'output'
15+ SAVE_DIR = 'batch/output'
16+ ERROR_OUTPUT_DIR = 'batch/output/ERROR'
17+ YTB_RESOLUTION_KEY = "ytb_resolution"
1018
1119def process_video (file , dubbing = False , is_retry = False ):
1220 if not is_retry :
13- prepare_output_folder ('output' )
21+ prepare_output_folder (OUTPUT_DIR )
1422
15- steps = [
16- ("Processing input file" , partial (process_input_file , file )),
17- ("Transcribing with Whisper" , partial (step2_whisperX .transcribe )),
18- ("Splitting sentences" , split_sentences ),
19- ("Summarizing and translating" , summarize_and_translate ),
20- ("Processing and aligning subtitles" , process_and_align_subtitles ),
21- ("Merging subtitles to video" , step7_merge_sub_to_vid .merge_subtitles_to_video ),
23+ text_steps = [
24+ ("🎥 Processing input file" , partial (process_input_file , file )),
25+ ("🎙️ Transcribing with Whisper" , partial (step2_whisperX .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" , step7_merge_sub_to_vid .merge_subtitles_to_video ),
2230 ]
2331
2432 if dubbing :
25- steps .extend ([
26- ("Generating audio tasks" , step8_1_gen_audio_task .gen_audio_task_main ),
27- ("Generating audio using SoVITS" , step10_gen_audio .process_sovits_tasks ),
28- ("Merging generated audio with video" , step11_merge_audio_to_vid .merge_main ),
29- ])
33+ dubbing_steps = [
34+ ("🔊 Generating audio tasks" , gen_audio_tasks ),
35+ ("🎵 Extracting reference audio" , step9_extract_refer_audio .extract_refer_audio_main ),
36+ ("🗣️ Generating audio" , step10_gen_audio .gen_audio ),
37+ ("🔄 Merging full audio" , step11_merge_full_audio .merge_full_audio ),
38+ ("🎞️ Merging dubbing to video" , step12_merge_dub_to_vid .merge_video_audio ),
39+ ]
40+ text_steps .extend (dubbing_steps )
3041
3142 current_step = ""
32- for step_name , step_func in steps :
43+ for step_name , step_func in text_steps :
3344 current_step = step_name
3445 for attempt in range (3 ):
3546 try :
36- print (f"Executing: { step_name } ..." )
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+ ))
3752 result = step_func ()
3853 if result is not None :
3954 globals ().update (result )
4055 break
4156 except Exception as e :
4257 if attempt == 2 :
43- error_message = f"Error in step '{ current_step } ': { str (e )} "
44- print (error_message )
45- cleanup ("batch/output/ERROR" )
46- return False , current_step , error_message
47- print (f"Attempt { attempt + 1 } failed. Retrying..." )
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+ ))
4869
49- print (" All steps completed successfully!" )
50- cleanup ("batch/output" )
70+ console . print (Panel ( "[bold green] All steps completed successfully! 🎉[/]" , border_style = "green" ) )
71+ cleanup (SAVE_DIR )
5172 return True , "" , ""
5273
5374def prepare_output_folder (output_folder ):
@@ -57,11 +78,11 @@ def prepare_output_folder(output_folder):
5778
5879def process_input_file (file ):
5980 if file .startswith ('http' ):
60- step1_ytdlp .download_video_ytdlp (file , resolution = load_key ("ytb_resolution" ), cutoff_time = None )
81+ step1_ytdlp .download_video_ytdlp (file , resolution = load_key (YTB_RESOLUTION_KEY ), cutoff_time = None )
6182 video_file = step1_ytdlp .find_video_files ()
6283 else :
6384 input_file = os .path .join ('batch' , 'input' , file )
64- output_file = os .path .join ('output' , file )
85+ output_file = os .path .join (OUTPUT_DIR , file )
6586 shutil .copy (input_file , output_file )
6687 video_file = output_file
6788 return {'video_file' : video_file }
@@ -77,3 +98,7 @@ def summarize_and_translate():
7798def process_and_align_subtitles ():
7899 step5_splitforsub .split_for_sub_main ()
79100 step6_generate_final_timeline .align_timestamp_main ()
101+
102+ def gen_audio_tasks ():
103+ step8_1_gen_audio_task .gen_audio_task_main ()
104+ step8_2_gen_dub_chunks .gen_dub_chunks ()
0 commit comments