Next commited on
Commit
5b527ce
·
verified ·
1 Parent(s): f2b9f8f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+
4
+ def download_url(url, name, ext):
5
+ opts = {
6
+ "mp3": "-f \"ba\" -x --audio-format mp3",
7
+ "mp4": "-f \"bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best\"",
8
+ }[ext]
9
+ filename = f"{name}.{ext}"
10
+ os.system(f"yt-dlp {opts} {url} -o {filename}")
11
+ return filename
12
+
13
+ with gr.Blocks(theme="Nex432/green") as demo:
14
+ with gr.Tab("main settings"):
15
+ url = gr.Textbox(label="Media URL")
16
+ name_file = gr.Textbox(label="Media Name")
17
+ format = gr.Dropdown(label="Format File `mp3` and `mp4`", choices=["mp3", "mp4"])
18
+ download = gr.Button("Download")
19
+ audio_output = gr.Audio(visible=False)
20
+ video_output = gr.Video(visible=False)
21
+ def download_media(url, name_file, format):
22
+ filename = download_url(url, name_file, format)
23
+ if format == "mp3":
24
+ return filename, None # Return filename for audio, None for video
25
+ else:
26
+ return None, filename # Return None for audio, filename for video
27
+
28
+ download.click(download_media, inputs=[url, name_file, format], outputs=[audio_output, video_output])
29
+ with gr.Tab("credits"):
30
+ gr.Markdown(
31
+ f"""
32
+ code by [Nex432](https://huggingface.co/Nex432)<br> with [chatGPT's](https://chatgpt.com) help
33
+
34
+ """
35
+ )
36
+ demo.launch()