File size: 1,007 Bytes
f7b3397
5806219
da8f353
25c7df7
5806219
4b1708b
5806219
 
 
 
 
 
9d38abe
5806219
4b1708b
1d6256c
5806219
 
4b1708b
da8f353
5806219
9d38abe
da8f353
5806219
 
 
 
36119e5
5806219
 
 
0a1013e
5806219
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import gradio as gr
import yt_dlp
import os

def downloader(video_url, audio_format, audio_name):
    os.makedirs('audios', exist_ok=True)
    ydl_opts = {
        'format': 'bestaudio/best',
        'postprocessors': [{
            'key': 'FFmpegExtractAudio',
            'preferredcodec': audio_format,
        }],
        'outtmpl': f"audios/{audio_name}",
    }
    output_path = f"audios/{audio_name}.%(ext)s"

    with yt_dlp.YoutubeDL(ydl_opts) as ydl:
        ydl.download([video_url])
    return output_path

with gr.Blocks() as demo:
    gr.Markdown("# YouTube Downloader 2.0")
    
    video_url = gr.Textbox(label="YouTube video link")
    audio_name = gr.Textbox(label="Audio name of YouTube audio")
    audio_format = gr.Radio(["wav", "flac", "mp3"], label="Select the output format")
    
    output = gr.Audio(label="Output")
    
    download_button = gr.Button("Download")
    download_button.click(downloader, inputs=[video_url, audio_format, audio_name], outputs=output)

demo.launch()