Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
|
|
|
| 3 |
|
| 4 |
def fetch(url, name, ext):
|
| 5 |
opts = {
|
|
@@ -7,16 +8,21 @@ def fetch(url, name, ext):
|
|
| 7 |
"mp4": "-f \"bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best\"",
|
| 8 |
}[ext]
|
| 9 |
filename = f"{name}.{ext}"
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
# Create the Gradio interface
|
| 14 |
interface = gr.Interface(
|
| 15 |
fn=fetch,
|
| 16 |
inputs=[
|
| 17 |
-
gr.Textbox(label="Link Address", placeholder="Enter the
|
| 18 |
-
gr.Textbox(label="File
|
| 19 |
-
gr.Dropdown(["mp3", "mp4"], value="mp4", label="File
|
| 20 |
],
|
| 21 |
outputs=gr.File(label="Download!"),
|
| 22 |
description="Download from X, Youtube, Reddit, etc..",
|
|
@@ -24,4 +30,4 @@ interface = gr.Interface(
|
|
| 24 |
)
|
| 25 |
|
| 26 |
# Launch the interface
|
| 27 |
-
interface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
+
import subprocess
|
| 4 |
|
| 5 |
def fetch(url, name, ext):
|
| 6 |
opts = {
|
|
|
|
| 8 |
"mp4": "-f \"bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best\"",
|
| 9 |
}[ext]
|
| 10 |
filename = f"{name}.{ext}"
|
| 11 |
+
|
| 12 |
+
try:
|
| 13 |
+
# Run yt-dlp command using subprocess to capture errors
|
| 14 |
+
result = subprocess.run(f"yt-dlp {opts} {url} -o {filename}", shell=True, check=True)
|
| 15 |
+
return filename
|
| 16 |
+
except subprocess.CalledProcessError as e:
|
| 17 |
+
return f"Error: {str(e)}"
|
| 18 |
|
| 19 |
# Create the Gradio interface
|
| 20 |
interface = gr.Interface(
|
| 21 |
fn=fetch,
|
| 22 |
inputs=[
|
| 23 |
+
gr.Textbox(label="Link Address", placeholder="Enter the URL here ..."),
|
| 24 |
+
gr.Textbox(label="File Name", placeholder="Example: file_name"),
|
| 25 |
+
gr.Dropdown(["mp3", "mp4"], value="mp4", label="File Type")
|
| 26 |
],
|
| 27 |
outputs=gr.File(label="Download!"),
|
| 28 |
description="Download from X, Youtube, Reddit, etc..",
|
|
|
|
| 30 |
)
|
| 31 |
|
| 32 |
# Launch the interface
|
| 33 |
+
interface.launch()
|