Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import yt_dlp
|
3 |
+
|
4 |
+
def download_media(url, download_video):
|
5 |
+
if download_video:
|
6 |
+
ydl_opts = {
|
7 |
+
'format': 'bestvideo+bestaudio/best',
|
8 |
+
'outtmpl': 'downloads/%(title)s.%(ext)s',
|
9 |
+
}
|
10 |
+
else:
|
11 |
+
ydl_opts = {
|
12 |
+
'format': 'bestaudio/best',
|
13 |
+
'postprocessors': [{
|
14 |
+
'key': 'FFmpegExtractAudio',
|
15 |
+
'preferredcodec': 'mp3',
|
16 |
+
'preferredquality': '192',
|
17 |
+
}],
|
18 |
+
'outtmpl': 'downloads/%(title)s.%(ext)s',
|
19 |
+
}
|
20 |
+
|
21 |
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
22 |
+
info_dict = ydl.extract_info(url, download=True)
|
23 |
+
file_title = ydl.prepare_filename(info_dict)
|
24 |
+
|
25 |
+
if download_video:
|
26 |
+
output_file = file_title
|
27 |
+
else:
|
28 |
+
output_file = file_title.rsplit('.', 1)[0] + '.mp3'
|
29 |
+
|
30 |
+
return output_file
|
31 |
+
|
32 |
+
# brr
|
33 |
+
with gr.Blocks() as demo:
|
34 |
+
gr.Markdown("# YouTube Media Downloader")
|
35 |
+
with gr.Row():
|
36 |
+
url_input = gr.Textbox(label="YouTube URL")
|
37 |
+
download_video_checkbox = gr.Checkbox(label="Download Video", value=False)
|
38 |
+
with gr.Row():
|
39 |
+
download_button = gr.Button("Download")
|
40 |
+
with gr.Row():
|
41 |
+
output = gr.File(label="Downloaded Media")
|
42 |
+
download_button.click(download_media, inputs=[url_input, download_video_checkbox], outputs=output)
|
43 |
+
|
44 |
+
demo.launch()
|