Spaces:
Running
Running
import yt_dlp | |
import gradio as gr | |
import os | |
def downloader(video_url, save_folder, audio_format, audio_name): | |
save_path = os.path.join(save_folder, audio_name) | |
ydl_opts = { | |
'format': 'bestaudio/best', | |
'postprocessors': [{ | |
'key': 'FFmpegExtractAudio', | |
'preferredcodec': audio_format, | |
}], | |
'outtmpl': save_path, | |
} | |
with yt_dlp.YoutubeDL(ydl_opts) as ydl: | |
ydl.download([video_url]) | |
return f"Audio downloaded successfully to {save_path}" | |
inputs = [ | |
gr.Textbox(label="YouTube video link"), | |
gr.Textbox(label="Audio name"), | |
gr.Textbox(label="Output path for downloaded audio files"), | |
gr.Radio(["wav", "flac", "mp3"], label="Select the output format") | |
] | |
output = gr.Textbox(label="Output") | |
title = "YouTube Audio Downloader" | |
description = "Download audio from YouTube videos" | |
gr.Interface( | |
fn=downloader, | |
inputs=inputs, | |
outputs=output, | |
title=title, | |
description=description, | |
theme="light" | |
).launch() | |