Nymbo commited on
Commit
895bc24
·
verified ·
1 Parent(s): 20a0bbe

reverting lol

Browse files
Files changed (1) hide show
  1. app.py +18 -44
app.py CHANGED
@@ -1,60 +1,34 @@
1
  import gradio as gr
2
  import os
3
  import subprocess
4
- import shutil
5
- from zipfile import ZipFile
6
 
7
- # A folder to store downloads in a Hugging Face environment
8
- DOWNLOAD_FOLDER = "downloads"
9
-
10
- def fetch(urls, ext):
11
- # Ensure the download folder exists
12
- if not os.path.exists(DOWNLOAD_FOLDER):
13
- os.makedirs(DOWNLOAD_FOLDER)
14
-
15
- downloaded_files = []
16
- url_list = urls.splitlines() # Split multiple URLs by line
17
-
18
- for i, url in enumerate(url_list):
19
- filename = f"file_{i+1}.{ext}" # Generate a generic filename for each URL
20
- file_path = os.path.join(DOWNLOAD_FOLDER, filename)
21
-
22
- opts = {
23
- "mp3": "-f \"ba\" -x --audio-format mp3",
24
- "mp4": "-f \"bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best\"",
25
- "flac": "-f \"ba\" -x --audio-format flac",
26
- "aac": "-f \"ba\" -x --audio-format aac"
27
- }[ext]
28
-
29
- try:
30
- # Run yt-dlp command using subprocess
31
- subprocess.run(f"yt-dlp {opts} {url} -o \"{file_path}\"", shell=True, check=True)
32
- downloaded_files.append(file_path)
33
- except subprocess.CalledProcessError as e:
34
- return f"Error downloading file {url}: {str(e)}"
35
-
36
- # Create a zip file with all downloaded files
37
- zip_filename = os.path.join(DOWNLOAD_FOLDER, "downloaded_files.zip")
38
- with ZipFile(zip_filename, 'w') as zipf:
39
- for file in downloaded_files:
40
- zipf.write(file, os.path.basename(file)) # Add file to zip, with filename
41
 
42
- # Cleanup individual files after zipping
43
- for file in downloaded_files:
44
- os.remove(file)
45
 
46
- # Return the path to the zip file for downloading
47
- return zip_filename
 
 
 
 
48
 
49
  # Create the Gradio interface
50
  interface = gr.Interface(
51
  fn=fetch,
52
  inputs=[
53
- gr.Textbox(label="Link Addresses", placeholder="Enter one URL per line here ...", lines=5),
 
54
  gr.Dropdown(["mp3", "mp4", "flac", "aac"], value="mp3", label="File Type")
55
  ],
56
- outputs=gr.File(label="Download ZIP!"),
57
- description="Download multiple files from X, Youtube, Reddit, etc. and get them in a zip file.",
58
  theme="Nymbo/Nymbo_Theme"
59
  )
60
 
 
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..",
32
  theme="Nymbo/Nymbo_Theme"
33
  )
34