-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathsubtitle.py
executable file
·39 lines (30 loc) · 1.17 KB
/
subtitle.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python
import sys
import argparse
import logging
from app.core import add_subtitle_in_video
from app.utils import download_file, is_url
# Configure logging
logger = logging.getLogger(__name__)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Add subtitles to video.")
parser.add_argument(
"filepath", type=str, help="The path to the video file or its URL."
)
parser.add_argument("--model", type=str, default="base", help="The model name.")
args = parser.parse_args()
if not args.filepath:
print("Please provide a filename.")
sys.exit(1)
try:
filepath = args.filepath
if is_url(filepath):
filepath = download_file(filepath)
# if filepath contains any space, replace all space it with underscore
if " " in filepath:
filepath = filepath.replace(" ", "_")
vtt_file_path, output_file = add_subtitle_in_video(filepath, args.model)
logger.info(f"VTT file path: {vtt_file_path}, Output file path: {output_file}")
print(f"Output filepath: {output_file}")
except Exception as e:
logging.error(f"An error occurred: {e}")