Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
yt-dlp
git+https://github.com/openai/whisper.git
validators
25 changes: 22 additions & 3 deletions yt_whisper/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import argparse
import warnings
import yt_dlp
from .utils import slugify, str2bool, write_srt, write_vtt
from utils import slugify, str2bool, write_srt, write_vtt
import tempfile
import validators


def main():
Expand Down Expand Up @@ -41,7 +42,25 @@ def main():
args["language"] = "en"

model = whisper.load_model(model_name)
audios = get_audio(args.pop("video"))

video_sources = args.pop("video")

# check if the video sources are valid URLs
all_are_urs = True
for video_source in video_sources:
if not validators.url(video_source):
all_are_urs = False
break

if all_are_urs:
# download the videos and return their paths
audios = get_audio(video_sources)
else:
# prep the video sources as audio paths
audios = {}
for video_source in video_sources:
audios[video_source] = video_source

break_lines = args.pop("break_lines")

for title, audio_path in audios.items():
Expand All @@ -62,7 +81,7 @@ def main():

print("Saved SRT to", os.path.abspath(srt_path))


# Downlaods youtube videos and returns their paths

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*Downloads YouTube

def get_audio(urls):
temp_dir = tempfile.gettempdir()

Expand Down