Skip to content

Commit 74638fd

Browse files
committed
feat: update batch mode
1 parent 7d94905 commit 74638fd

File tree

6 files changed

+85
-72
lines changed

6 files changed

+85
-72
lines changed

OneKeyBatch.bat

Lines changed: 0 additions & 23 deletions
This file was deleted.

batch/OneKeyBatch.bat

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
@echo off
2-
cd /d %~dp0..
3-
4-
if exist runtime (
5-
echo Using runtime folder...
6-
runtime\python.exe batch\utils\batch_processor.py
7-
) else (
8-
echo Runtime folder not found. Using conda environment...
9-
call conda activate videolingo
10-
python batch\utils\batch_processor.py
11-
call conda deactivate
12-
)
2+
cd /D "%~dp0"
3+
cd ..
134

5+
@rem 设置环境变量
6+
set INSTALL_DIR=%cd%\installer_files
7+
set CONDA_ROOT_PREFIX=%cd%\installer_files\conda
8+
set INSTALL_ENV_DIR=%cd%\installer_files\env
9+
10+
@rem 环境隔离设置
11+
set PYTHONNOUSERSITE=1
12+
set PYTHONPATH=
13+
set PYTHONHOME=
14+
set "CUDA_PATH=%INSTALL_ENV_DIR%"
15+
set "CUDA_HOME=%CUDA_PATH%"
16+
17+
@rem 激活conda环境
18+
call "%CONDA_ROOT_PREFIX%\condabin\conda.bat" activate "%INSTALL_ENV_DIR%" || ( echo. && echo Conda environment not found && goto end )
19+
20+
@rem 运行批处理脚本
21+
call python batch\utils\batch_processor.py
22+
23+
:end
1424
pause

batch/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Example:
3131

3232
### 3. Executing Batch Processing
3333

34-
1. Double-click to run `OneKeyBatch.bat` in the root directory
34+
1. Double-click to run `OneKeyBatch.bat`
3535
2. Output files will be saved in the `output` folder
3636
3. Task status can be monitored in the `Status` column of `tasks_setting.xlsx`
3737

batch/README.zh.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
### 3. 运行批处理
3333

34-
1. 双击运行根目录的 `OneKeyBatch.bat`
34+
1. 双击运行 `OneKeyBatch.bat`
3535
2. 输出文件将保存在 `output` 文件夹
3636
3. 任务状态可在 `tasks_setting.xlsx``Status` 列查看
3737

batch/utils/settings_check.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@
44
from rich.console import Console
55
from rich.panel import Panel
66

7+
# Constants
8+
SETTINGS_FILE = 'batch/tasks_setting.xlsx'
9+
INPUT_FOLDER = os.path.join('batch', 'input')
10+
VALID_DUBBING_VALUES = [0, 1]
11+
712
console = Console()
813

914
def check_settings():
10-
df = pd.read_excel('batch/tasks_setting.xlsx')
11-
input_files = set(os.listdir(os.path.join('batch', 'input')))
15+
os.makedirs(INPUT_FOLDER, exist_ok=True)
16+
df = pd.read_excel(SETTINGS_FILE)
17+
input_files = set(os.listdir(INPUT_FOLDER))
1218
excel_files = set(df['Video File'].tolist())
1319
files_not_in_excel = input_files - excel_files
1420

@@ -31,19 +37,14 @@ def check_settings():
3137

3238
if video_file.startswith('http'):
3339
url_tasks += 1
34-
elif os.path.isfile(os.path.join('batch', 'input', video_file)):
40+
elif os.path.isfile(os.path.join(INPUT_FOLDER, video_file)):
3541
local_video_tasks += 1
3642
else:
3743
console.print(Panel(f"Invalid video file or URL 「{video_file}」", title=f"[bold red]Error in row {index + 2}", expand=False))
3844
all_passed = False
3945

40-
if not pd.isna(source_language):
41-
if source_language.lower() not in ['en', 'zh', 'auto']:
42-
console.print(Panel(f"Invalid source language 「{source_language}」", title=f"[bold red]Error in row {index + 2}", expand=False))
43-
all_passed = False
44-
4546
if not pd.isna(dubbing):
46-
if int(dubbing) not in [0, 1]:
47+
if int(dubbing) not in VALID_DUBBING_VALUES:
4748
console.print(Panel(f"Invalid dubbing value 「{dubbing}」", title=f"[bold red]Error in row {index + 2}", expand=False))
4849
all_passed = False
4950

batch/utils/video_processor.py

Lines changed: 52 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,74 @@
11
import os, sys
22
sys.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 *
64
from core.onekeycleanup import cleanup
75
from core.config_utils import load_key
86
import shutil
97
from 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

1119
def 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

5374
def prepare_output_folder(output_folder):
@@ -57,11 +78,11 @@ def prepare_output_folder(output_folder):
5778

5879
def 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():
7798
def 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

Comments
 (0)