Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -2,34 +2,43 @@ import gradio as gr
|
|
2 |
import yt_dlp
|
3 |
import os
|
4 |
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
'format': 'best',
|
13 |
-
'outtmpl': 'downloads/%(title)s.%(ext)s',
|
14 |
-
}
|
15 |
|
16 |
-
with
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
# Create a Gradio interface
|
26 |
-
iface = gr.Interface(
|
27 |
-
fn=download_video,
|
28 |
-
inputs="text",
|
29 |
-
outputs="audio",
|
30 |
-
title="Video Downloader",
|
31 |
-
description="Enter the URL of the video you want to download."
|
32 |
-
)
|
33 |
|
34 |
-
|
35 |
-
iface.launch()
|
|
|
2 |
import yt_dlp
|
3 |
import os
|
4 |
|
5 |
+
def download_media(url, output_format):
|
6 |
+
ydl_opts = {}
|
7 |
|
8 |
+
if output_format == "Audio":
|
9 |
+
ydl_opts = {
|
10 |
+
'format': 'bestaudio/best',
|
11 |
+
'outtmpl': 'downloads/%(title)s.%(ext)s',
|
12 |
+
'postprocessors': [{
|
13 |
+
'key': 'FFmpegExtractAudio',
|
14 |
+
'preferredcodec': 'mp3',
|
15 |
+
'preferredquality': '192',
|
16 |
+
}],
|
17 |
+
}
|
18 |
+
elif output_format == "Video":
|
19 |
+
ydl_opts = {
|
20 |
+
'format': 'bestvideo+bestaudio/best',
|
21 |
+
'outtmpl': 'downloads/%(title)s.%(ext)s',
|
22 |
+
}
|
23 |
+
|
24 |
+
try:
|
25 |
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
26 |
+
ydl.download([url])
|
27 |
+
return "Download successful!"
|
28 |
+
except Exception as e:
|
29 |
+
return f"Error: {str(e)}"
|
30 |
|
31 |
+
# Gradio Blocks UI
|
32 |
+
with gr.Blocks() as demo:
|
33 |
+
gr.Markdown("# Video and Audio Downloader using yt-dlp")
|
|
|
|
|
|
|
34 |
|
35 |
+
with gr.Row():
|
36 |
+
url_input = gr.Textbox(label="Video/Audio URL")
|
37 |
+
format_dropdown = gr.Dropdown(choices=["Audio", "Video"], label="Output Format")
|
38 |
+
|
39 |
+
download_button = gr.Button("Download")
|
40 |
+
output_text = gr.Textbox(label="Output Message")
|
41 |
|
42 |
+
download_button.click(download_media, inputs=[url_input, format_dropdown], outputs=output_text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
+
demo.launch()
|
|