Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,10 @@
|
|
1 |
import gradio as gr
|
2 |
import yt_dlp
|
3 |
import os
|
|
|
|
|
|
|
|
|
4 |
|
5 |
def download_media(url, output_format):
|
6 |
ydl_opts = {}
|
@@ -23,10 +27,13 @@ def download_media(url, output_format):
|
|
23 |
|
24 |
try:
|
25 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
26 |
-
ydl.
|
27 |
-
|
|
|
|
|
|
|
28 |
except Exception as e:
|
29 |
-
return f"Error: {str(e)}"
|
30 |
|
31 |
# Gradio Blocks UI
|
32 |
with gr.Blocks() as demo:
|
@@ -39,6 +46,21 @@ with gr.Blocks() as demo:
|
|
39 |
download_button = gr.Button("Download")
|
40 |
output_text = gr.Textbox(label="Output Message")
|
41 |
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import yt_dlp
|
3 |
import os
|
4 |
+
os.system('yt-dlp -U')
|
5 |
+
|
6 |
+
|
7 |
+
|
8 |
|
9 |
def download_media(url, output_format):
|
10 |
ydl_opts = {}
|
|
|
27 |
|
28 |
try:
|
29 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
30 |
+
info_dict = ydl.extract_info(url, download=True)
|
31 |
+
title = info_dict.get('title', 'Unknown')
|
32 |
+
ext = info_dict.get('ext', 'mp4' if output_format == "Video" else 'mp3')
|
33 |
+
file_path = f'downloads/{title}.{ext}'
|
34 |
+
return file_path, f"Download successful: {title}.{ext}"
|
35 |
except Exception as e:
|
36 |
+
return None, f"Error: {str(e)}"
|
37 |
|
38 |
# Gradio Blocks UI
|
39 |
with gr.Blocks() as demo:
|
|
|
46 |
download_button = gr.Button("Download")
|
47 |
output_text = gr.Textbox(label="Output Message")
|
48 |
|
49 |
+
# Placeholder for media output
|
50 |
+
audio_output = gr.Audio(label="Audio Output", visible=False)
|
51 |
+
video_output = gr.Video(label="Video Output", visible=False)
|
52 |
+
|
53 |
+
def handle_download(url, output_format):
|
54 |
+
file_path, message = download_media(url, output_format)
|
55 |
+
if file_path and output_format == "Audio":
|
56 |
+
return file_path, None, audio_output.update(visible=True), video_output.update(visible=False), message
|
57 |
+
elif file_path and output_format == "Video":
|
58 |
+
return None, file_path, audio_output.update(visible=False), video_output.update(visible=True), message
|
59 |
+
else:
|
60 |
+
return None, None, audio_output.update(visible=False), video_output.update(visible=False), message
|
61 |
+
|
62 |
+
download_button.click(handle_download,
|
63 |
+
inputs=[url_input, format_dropdown],
|
64 |
+
outputs=[audio_output, video_output, audio_output, video_output, output_text])
|
65 |
|
66 |
demo.launch()
|