SaltProphet's picture
Create app.py
f3a2a7d verified
import customtkinter as ctk
from threading import Thread
from downloader import download_audio
import os
class DownloaderApp(ctk.CTk):
def __init__(self):
super().__init__()
self.title("YouTube Music Downloader")
self.geometry("500x350")
ctk.set_appearance_mode("dark")
ctk.set_default_color_theme("blue")
# URL input
ctk.CTkLabel(self, text="Enter video or audio URL:", font=("Arial", 14)).pack(pady=10)
self.url_entry = ctk.CTkEntry(self, width=420, height=35)
self.url_entry.pack(pady=5)
# Format selector
ctk.CTkLabel(self, text="Choose output format:", font=("Arial", 14)).pack(pady=10)
self.format_var = ctk.StringVar(value="mp3")
self.format_menu = ctk.CTkOptionMenu(
self, values=["mp3", "wav", "flac", "aac", "ogg", "m4a"], variable=self.format_var
)
self.format_menu.pack()
# Download button
self.download_button = ctk.CTkButton(
self, text="Download", command=self.start_download, width=150, height=40
)
self.download_button.pack(pady=20)
# Status label
self.status_label = ctk.CTkLabel(self, text="", wraplength=450)
self.status_label.pack(pady=10)
# Open downloads folder button
self.open_button = ctk.CTkButton(
self, text="Open Downloads Folder", command=self.open_downloads
)
self.open_button.pack(pady=5)
def start_download(self):
url = self.url_entry.get().strip()
fmt = self.format_var.get()
if not url:
self.status_label.configure(text="⚠️ Please enter a URL.")
return
self.status_label.configure(text="⏳ Downloading... Please wait.")
self.download_button.configure(state="disabled")
Thread(target=self.download_thread, args=(url, fmt)).start()
def download_thread(self, url, fmt):
try:
filepath, title = download_audio(url, fmt)
self.status_label.configure(text=f"✅ Download complete:\n{title}\nSaved to: {filepath}")
except Exception as e:
self.status_label.configure(text=f"❌ Error: {str(e)}")
finally:
self.download_button.configure(state="normal")
def open_downloads(self):
path = os.path.abspath("downloads")
if not os.path.exists(path):
os.makedirs(path)
os.startfile(path) # works on Windows only
if __name__ == "__main__":
app = DownloaderApp()
app.mainloop()