File size: 2,560 Bytes
f3a2a7d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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()