GilbertClaus commited on
Commit
64685fc
·
1 Parent(s): b42bb78
Files changed (3) hide show
  1. README.md +11 -1
  2. app.py +54 -0
  3. requirements.txt +2 -0
README.md CHANGED
@@ -8,5 +8,15 @@ sdk_version: 5.9.1
8
  app_file: app.py
9
  pinned: false
10
  ---
 
 
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
8
  app_file: app.py
9
  pinned: false
10
  ---
11
+ # YouTube MP3 Downloader
12
+ This application allows you to paste YouTube links and download them as MP3 files. It uses Gradio for the web interface and `yt-dlp` for downloading.
13
 
14
+ ## Features
15
+ - Input YouTube links (one per line).
16
+ - Converts videos to MP3 format with thumbnails.
17
+ - Downloads all MP3s as a ZIP file.
18
+
19
+ ## How to Use
20
+ 1. Paste YouTube links in the provided textbox.
21
+ 2. Click the "Download MP3s" button.
22
+ 3. Download the ZIP file containing MP3 files.
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import zipfile
3
+ import subprocess
4
+ import gradio as gr
5
+
6
+ # Install yt-dlp (handled automatically in Hugging Face Spaces)
7
+ def ensure_dependencies():
8
+ try:
9
+ import yt_dlp
10
+ except ImportError:
11
+ subprocess.run(['pip', 'install', 'yt-dlp'])
12
+ ensure_dependencies()
13
+
14
+ def download_youtube_mp3(urls):
15
+ directory = "/content" # Directory for storing files
16
+ os.makedirs(directory, exist_ok=True)
17
+ os.chdir(directory)
18
+
19
+ # Process each URL from the input
20
+ urls = urls.splitlines()
21
+ for url in urls:
22
+ if "youtube" not in url:
23
+ url = "https://www.youtube.com/watch?v=" + url.split("[")[-1].split("]")[0]
24
+ url = url.split("&")[0]
25
+ subprocess.run(['yt-dlp', '-x', '--audio-format', 'mp3', '--embed-thumbnail', url])
26
+
27
+ # Create a ZIP file containing all MP3 files
28
+ zip_filename = "mp3_files.zip"
29
+ with zipfile.ZipFile(zip_filename, "w") as zipf:
30
+ for file in os.listdir(directory):
31
+ if file.endswith(".mp3"):
32
+ zipf.write(os.path.join(directory, file), file)
33
+ os.remove(os.path.join(directory, file)) # Clean up MP3 files after zipping
34
+
35
+ return zip_filename
36
+
37
+ # Gradio interface
38
+ def process_input(input_text):
39
+ zip_file = download_youtube_mp3(input_text)
40
+ return zip_file
41
+
42
+ with gr.Blocks() as demo:
43
+ gr.Markdown("""# YouTube MP3 Downloader
44
+
45
+ Paste YouTube links below (one per line), and download them as MP3 files.
46
+ """)
47
+
48
+ input_text = gr.Textbox(label="Enter YouTube Links (one per line)")
49
+ download_button = gr.Button("Download MP3s")
50
+ output_file = gr.File(label="Download the ZIP File")
51
+
52
+ download_button.click(process_input, inputs=input_text, outputs=output_file)
53
+
54
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio
2
+ yt-dlp