Youtube — To Mp3 Script
def download_thread(self, url): try: import yt_dlp quality_map = { "Best (320kbps)": "320", "Good (192kbps)": "192", "Worst (128kbps)": "128" } ydl_opts = { 'format': 'bestaudio/best', 'postprocessors': [{ 'key': 'FFmpegExtractAudio', 'preferredcodec': 'mp3', 'preferredquality': quality_map[self.quality.get()], }], 'outtmpl': f"{self.output_entry.get()}/%(title)s.%(ext)s", 'quiet': True, } with yt_dlp.YoutubeDL(ydl_opts) as ydl: ydl.download([url]) self.root.after(0, self.download_complete, True, "Download complete!") except Exception as e: self.root.after(0, self.download_complete, False, str(e))
def browse(self): directory = filedialog.askdirectory() if directory: self.output_entry.delete(0, tk.END) self.output_entry.insert(0, directory) youtube to mp3 script
# URL Input tk.Label(root, text="YouTube URL:").pack(pady=5) self.url_entry = tk.Entry(root, width=70) self.url_entry.pack(pady=5) # Output Directory tk.Label(root, text="Output Directory:").pack(pady=5) self.output_frame = tk.Frame(root) self.output_frame.pack(pady=5) self.output_entry = tk.Entry(self.output_frame, width=50) self.output_entry.pack(side=tk.LEFT, padx=5) self.output_entry.insert(0, "downloads") tk.Button(self.output_frame, text="Browse", command=self.browse).pack(side=tk.LEFT) # Quality Selection tk.Label(root, text="Quality:").pack(pady=5) self.quality = ttk.Combobox(root, values=["Best (320kbps)", "Good (192kbps)", "Worst (128kbps)"]) self.quality.set("Good (192kbps)") self.quality.pack(pady=5) # Download Button self.download_btn = tk.Button(root, text="Download", command=self.download, bg="green", fg="white", font=("Arial", 12)) self.download_btn.pack(pady=20) # Status Label self.status = tk.Label(root, text="Ready", fg="blue") self.status.pack(pady=10) # Progress Bar self.progress = ttk.Progressbar(root, mode='indeterminate') self.progress.pack(pady=10, padx=20, fill=tk.X) "Good (192kbps)": "192"
