Nymbo commited on
Commit
c91f6d5
·
verified ·
1 Parent(s): 78d9d7c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -7
app.py CHANGED
@@ -1,22 +1,31 @@
1
  import gradio as gr
2
  import os
 
3
 
4
  def fetch(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
  # Create the Gradio interface
14
  interface = gr.Interface(
15
  fn=fetch,
16
  inputs=[
17
- gr.Textbox(label="Link Address", placeholder="Enter the url here ..."),
18
- gr.Textbox(label="File name", placeholder="Example: file_name"),
19
- gr.Dropdown(["mp3", "mp4"], value="mp4", label="File type")
20
  ],
21
  outputs=gr.File(label="Download!"),
22
  description="Download from X, Youtube, Reddit, etc..",
 
1
  import gradio as gr
2
  import os
3
+ import subprocess
4
 
5
  def fetch(url, name, ext):
6
  opts = {
7
+ "mp3": "-f \"ba\" -x --audio-format mp3", # MP3 format
8
+ "mp4": "-f \"bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best\"", # MP4 format for video + audio
9
+ "flac": "-f \"ba\" -x --audio-format flac", # FLAC format for lossless audio
10
+ "aac": "-f \"ba\" -x --audio-format aac" # AAC format for lossy high-quality audio
11
  }[ext]
12
+
13
  filename = f"{name}.{ext}"
14
+
15
+ try:
16
+ # Run yt-dlp command using subprocess to capture errors
17
+ result = subprocess.run(f"yt-dlp {opts} {url} -o {filename}", shell=True, check=True)
18
+ return filename
19
+ except subprocess.CalledProcessError as e:
20
+ return f"Error: {str(e)}"
21
 
22
  # Create the Gradio interface
23
  interface = gr.Interface(
24
  fn=fetch,
25
  inputs=[
26
+ gr.Textbox(label="Link Address", placeholder="Enter the URL here ..."),
27
+ gr.Textbox(label="File Name", placeholder="Example: file_name"),
28
+ gr.Dropdown(["mp3", "mp4", "flac", "aac"], value="mp3", label="File Type")
29
  ],
30
  outputs=gr.File(label="Download!"),
31
  description="Download from X, Youtube, Reddit, etc..",