Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import customtkinter as ctk
|
| 2 |
+
from threading import Thread
|
| 3 |
+
from downloader import download_audio
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
class DownloaderApp(ctk.CTk):
|
| 7 |
+
def __init__(self):
|
| 8 |
+
super().__init__()
|
| 9 |
+
self.title("YouTube Music Downloader")
|
| 10 |
+
self.geometry("500x350")
|
| 11 |
+
ctk.set_appearance_mode("dark")
|
| 12 |
+
ctk.set_default_color_theme("blue")
|
| 13 |
+
|
| 14 |
+
# URL input
|
| 15 |
+
ctk.CTkLabel(self, text="Enter video or audio URL:", font=("Arial", 14)).pack(pady=10)
|
| 16 |
+
self.url_entry = ctk.CTkEntry(self, width=420, height=35)
|
| 17 |
+
self.url_entry.pack(pady=5)
|
| 18 |
+
|
| 19 |
+
# Format selector
|
| 20 |
+
ctk.CTkLabel(self, text="Choose output format:", font=("Arial", 14)).pack(pady=10)
|
| 21 |
+
self.format_var = ctk.StringVar(value="mp3")
|
| 22 |
+
self.format_menu = ctk.CTkOptionMenu(
|
| 23 |
+
self, values=["mp3", "wav", "flac", "aac", "ogg", "m4a"], variable=self.format_var
|
| 24 |
+
)
|
| 25 |
+
self.format_menu.pack()
|
| 26 |
+
|
| 27 |
+
# Download button
|
| 28 |
+
self.download_button = ctk.CTkButton(
|
| 29 |
+
self, text="Download", command=self.start_download, width=150, height=40
|
| 30 |
+
)
|
| 31 |
+
self.download_button.pack(pady=20)
|
| 32 |
+
|
| 33 |
+
# Status label
|
| 34 |
+
self.status_label = ctk.CTkLabel(self, text="", wraplength=450)
|
| 35 |
+
self.status_label.pack(pady=10)
|
| 36 |
+
|
| 37 |
+
# Open downloads folder button
|
| 38 |
+
self.open_button = ctk.CTkButton(
|
| 39 |
+
self, text="Open Downloads Folder", command=self.open_downloads
|
| 40 |
+
)
|
| 41 |
+
self.open_button.pack(pady=5)
|
| 42 |
+
|
| 43 |
+
def start_download(self):
|
| 44 |
+
url = self.url_entry.get().strip()
|
| 45 |
+
fmt = self.format_var.get()
|
| 46 |
+
|
| 47 |
+
if not url:
|
| 48 |
+
self.status_label.configure(text="⚠️ Please enter a URL.")
|
| 49 |
+
return
|
| 50 |
+
|
| 51 |
+
self.status_label.configure(text="⏳ Downloading... Please wait.")
|
| 52 |
+
self.download_button.configure(state="disabled")
|
| 53 |
+
Thread(target=self.download_thread, args=(url, fmt)).start()
|
| 54 |
+
|
| 55 |
+
def download_thread(self, url, fmt):
|
| 56 |
+
try:
|
| 57 |
+
filepath, title = download_audio(url, fmt)
|
| 58 |
+
self.status_label.configure(text=f"✅ Download complete:\n{title}\nSaved to: {filepath}")
|
| 59 |
+
except Exception as e:
|
| 60 |
+
self.status_label.configure(text=f"❌ Error: {str(e)}")
|
| 61 |
+
finally:
|
| 62 |
+
self.download_button.configure(state="normal")
|
| 63 |
+
|
| 64 |
+
def open_downloads(self):
|
| 65 |
+
path = os.path.abspath("downloads")
|
| 66 |
+
if not os.path.exists(path):
|
| 67 |
+
os.makedirs(path)
|
| 68 |
+
os.startfile(path) # works on Windows only
|
| 69 |
+
|
| 70 |
+
if __name__ == "__main__":
|
| 71 |
+
app = DownloaderApp()
|
| 72 |
+
app.mainloop()
|