File size: 1,363 Bytes
5b527ce
 
 
 
 
1b0583a
 
5b527ce
 
 
 
 
 
 
 
 
1b0583a
5b527ce
 
 
1b0583a
5b527ce
1b0583a
056ac0b
 
 
 
1b0583a
5b527ce
1b0583a
5b527ce
 
1b0583a
 
5b527ce
 
1b0583a
5b527ce
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
35
36
37
38
39
import gradio as gr
import os

def download_url(url, name, ext):
    opts = {
        "mp3": '-f "ba" -x --audio-format mp3',
        "mp4": '-f "bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best"',
    }[ext]
    filename = f"{name}.{ext}"
    os.system(f"yt-dlp {opts} {url} -o {filename}")
    return filename

with gr.Blocks(theme="Nex432/green") as demo:
    with gr.Tab("main settings"):
        url = gr.Textbox(label="Media URL")
        name_file = gr.Textbox(label="Media Name")
        format = gr.Dropdown(label="Format File", choices=["mp3", "mp4"])
        download = gr.Button("Download")
        audio_output = gr.Audio(visible=False)
        video_output = gr.Video(visible=False)

        def download_media(url, name_file, format):
            filename = download_url(url, name_file, format)
            if format == "mp3":
                return filename, None  # Return filename for audio, None for video
            else:
                return None, filename  # Return None for audio, filename for video

        download.click(download_media, inputs=[url, name_file, format], outputs=[audio_output, video_output])

    with gr.Tab("credits"):
        gr.Markdown(
            """
            Code by [Nex432](https://huggingface.co/Nex432)<br> with [ChatGPT's](https://chatgpt.com) help
            """
        )

    demo.launch()