Last active
September 16, 2023 12:59
-
-
Save erdum/83ac46598b6abba40328555a132a9bb7 to your computer and use it in GitHub Desktop.
Youtube Audio Downloader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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