Skip to content

Instantly share code, notes, and snippets.

@erdum
Last active September 16, 2023 12:59
Show Gist options
  • Save erdum/83ac46598b6abba40328555a132a9bb7 to your computer and use it in GitHub Desktop.
Save erdum/83ac46598b6abba40328555a132a9bb7 to your computer and use it in GitHub Desktop.
Youtube Audio Downloader
import os
from pytube import YouTube
import time
from urllib.parse import urlparse, parse_qs
import gradio as gr
def download_audio_from_youtube_url(url: str) -> gr.outputs.File:
filename = 'yt-audio-{timestamp}.mp4'.format(timestamp=round(time.time()))
try:
yt = yt = YouTube(url)
stream = yt.streams.get_audio_only('mp4')
stream.download(filename=filename)
return os.path.join(filename)
except:
return None
iface = gr.Interface(fn=download_audio_from_youtube_url,
inputs=['text'],
outputs=['audio'])
iface.launch(share=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment