mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-20 20:29:06 +00:00
fix youtibe download bug
This commit is contained in:
@@ -4,7 +4,7 @@ KMP_DUPLICATE_LIB_OK=TRUE
|
||||
# Export OpenAI API Key
|
||||
OPENAI_APIKEY=
|
||||
# Export Whisper Model Size
|
||||
WHISPER_MODEL_SIZE=medium
|
||||
WHISPER_MODEL_SIZE=tiny
|
||||
WHISPER_REAL_TIME_MODEL_SIZE=tiny
|
||||
# AWS config
|
||||
AWS_ACCESS_KEY=***REMOVED***
|
||||
|
||||
@@ -48,4 +48,5 @@ pandas
|
||||
jupyter
|
||||
seaborn
|
||||
matplotlib
|
||||
termcolor
|
||||
termcolor
|
||||
https://github.com/yt-dlp/yt-dlp/archive/master.tar.gz
|
||||
|
||||
@@ -20,7 +20,6 @@ def preprocess_sentence(sentence):
|
||||
|
||||
def compute_similarity(sent1, sent2):
|
||||
tfidf_vectorizer = TfidfVectorizer()
|
||||
print("semt1", sent1, sent2)
|
||||
if sent1 is not None and sent2 is not None:
|
||||
tfidf_matrix = tfidf_vectorizer.fit_transform([sent1, sent2])
|
||||
return cosine_similarity(tfidf_matrix[0], tfidf_matrix[1])[0][0]
|
||||
|
||||
43
whisjax.py
43
whisjax.py
@@ -16,7 +16,7 @@ import subprocess
|
||||
import re
|
||||
import tempfile
|
||||
from loguru import logger
|
||||
from pytube import YouTube
|
||||
import yt_dlp as youtube_dl
|
||||
|
||||
from urllib.parse import urlparse
|
||||
from whisper_jax import FlaxWhisperPipline
|
||||
@@ -73,9 +73,21 @@ def main():
|
||||
# It will be saved to the current directory.
|
||||
logger.info("Downloading YouTube video at url: " + args.location)
|
||||
|
||||
youtube = YouTube(args.location)
|
||||
media_file = youtube.streams.filter(progressive=True, file_extension='mp4').order_by(
|
||||
'resolution').asc().first().download()
|
||||
# Create options for the download
|
||||
ydl_opts = {
|
||||
'format': 'bestaudio/best',
|
||||
'postprocessors': [{
|
||||
'key': 'FFmpegExtractAudio',
|
||||
'preferredcodec': 'mp3',
|
||||
'preferredquality': '192',
|
||||
}],
|
||||
'outtmpl': 'audio', # Specify the output file path and name
|
||||
}
|
||||
|
||||
# Download the audio
|
||||
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
||||
ydl.download([args.location])
|
||||
media_file = "audio.mp3"
|
||||
|
||||
logger.info("Saved downloaded YouTube video to: " + media_file)
|
||||
else:
|
||||
@@ -96,16 +108,19 @@ def main():
|
||||
quit()
|
||||
|
||||
# Handle video
|
||||
try:
|
||||
video = moviepy.editor.VideoFileClip(media_file)
|
||||
audio_filename = tempfile.NamedTemporaryFile(suffix=".mp3", delete=False).name
|
||||
video.audio.write_audiofile(audio_filename, logger=None)
|
||||
logger.info(f"Extracting audio to: {audio_filename}")
|
||||
# Handle audio only file
|
||||
except:
|
||||
audio = moviepy.editor.AudioFileClip(media_file)
|
||||
audio_filename = tempfile.NamedTemporaryFile(suffix=".mp3", delete=False).name
|
||||
audio.write_audiofile(audio_filename, logger=None)
|
||||
if not media_file.endswith(".mp3"):
|
||||
try:
|
||||
video = moviepy.editor.VideoFileClip(media_file)
|
||||
audio_filename = tempfile.NamedTemporaryFile(suffix=".mp3", delete=False).name
|
||||
video.audio.write_audiofile(audio_filename, logger=None)
|
||||
logger.info(f"Extracting audio to: {audio_filename}")
|
||||
# Handle audio only file
|
||||
except:
|
||||
audio = moviepy.editor.AudioFileClip(media_file)
|
||||
audio_filename = tempfile.NamedTemporaryFile(suffix=".mp3", delete=False).name
|
||||
audio.write_audiofile(audio_filename, logger=None)
|
||||
else:
|
||||
audio_filename = media_file
|
||||
|
||||
logger.info("Finished extracting audio")
|
||||
|
||||
|
||||
0
youtube.py
Normal file
0
youtube.py
Normal file
Reference in New Issue
Block a user