mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-21 04:39:06 +00:00
fix merge conflicts
This commit is contained in:
43
whisjax.py
43
whisjax.py
@@ -16,7 +16,7 @@ import subprocess
|
|||||||
import re
|
import re
|
||||||
import tempfile
|
import tempfile
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
from pytube import YouTube
|
import yt_dlp as youtube_dl
|
||||||
|
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
from whisper_jax import FlaxWhisperPipline
|
from whisper_jax import FlaxWhisperPipline
|
||||||
@@ -73,9 +73,21 @@ def main():
|
|||||||
# It will be saved to the current directory.
|
# It will be saved to the current directory.
|
||||||
logger.info("Downloading YouTube video at url: " + args.location)
|
logger.info("Downloading YouTube video at url: " + args.location)
|
||||||
|
|
||||||
youtube = YouTube(args.location)
|
# Create options for the download
|
||||||
media_file = youtube.streams.filter(progressive=True, file_extension='mp4').order_by(
|
ydl_opts = {
|
||||||
'resolution').asc().first().download()
|
'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)
|
logger.info("Saved downloaded YouTube video to: " + media_file)
|
||||||
else:
|
else:
|
||||||
@@ -96,16 +108,19 @@ def main():
|
|||||||
quit()
|
quit()
|
||||||
|
|
||||||
# Handle video
|
# Handle video
|
||||||
try:
|
if not media_file.endswith(".mp3"):
|
||||||
video = moviepy.editor.VideoFileClip(media_file)
|
try:
|
||||||
audio_filename = tempfile.NamedTemporaryFile(suffix=".mp3", delete=False).name
|
video = moviepy.editor.VideoFileClip(media_file)
|
||||||
video.audio.write_audiofile(audio_filename, logger=None)
|
audio_filename = tempfile.NamedTemporaryFile(suffix=".mp3", delete=False).name
|
||||||
logger.info(f"Extracting audio to: {audio_filename}")
|
video.audio.write_audiofile(audio_filename, logger=None)
|
||||||
# Handle audio only file
|
logger.info(f"Extracting audio to: {audio_filename}")
|
||||||
except:
|
# Handle audio only file
|
||||||
audio = moviepy.editor.AudioFileClip(media_file)
|
except:
|
||||||
audio_filename = tempfile.NamedTemporaryFile(suffix=".mp3", delete=False).name
|
audio = moviepy.editor.AudioFileClip(media_file)
|
||||||
audio.write_audiofile(audio_filename, logger=None)
|
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")
|
logger.info("Finished extracting audio")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user