lets add gui and make it as real app
- User
lets add gui and make it as real app
- Assistant
To create a GUI application from the batch script, we'll use a programming language that supports GUI development. Here, I'll demonstrate how to achieve this using Python with the
tkinterlibrary for the GUI andyt-dlpandrequestslibraries for the downloading functionality.Prerequisites:
-
Python 3.8 or later installed on your system.
-
yt-dlpandrequestslibraries installed. You can install them using pip:
pip install yt-dlp requests
**Code:** ```python import tkinter as tk from tkinter import filedialog, messagebox import yt_dlp import requests from threading import Thread class DownloaderApp: def __init__(self, root): self.root = root self.root.title("Universal Downloader") self.root.geometry("500x300") # URL Entry self.url_label = tk.Label(root, text="URL:") self.url_label.pack() self.url_entry = tk.Entry(root, width=50) self.url_entry.pack() # Download Directory self.download_dir_label = tk.Label(root, text="Download Directory:") self.download_dir_label.pack() self.download_dir_entry = tk.Entry(root, width=50) self.download_dir_entry.pack() self.browse_button = tk.Button(root, text="Browse", command=self.browse_directory) self.browse_button.pack() # YouTube Options self.youtube_frame = tk.Frame(root) self.youtube_frame.pack() self.youtube_quality_label = tk.Label(self.youtube_frame, text="YouTube Quality:") self.youtube_quality_label.pack(side=tk.LEFT) self.youtube_quality = tk.StringVar(root) self.youtube_quality.set("Highest") # default value self.youtube_quality_option = tk.OptionMenu(self.youtube_frame, self.youtube_quality, "Highest", "720p", "480p", "Audio Only") self.youtube_quality_option.pack(side=tk.LEFT) # Download Button self.download_button = tk.Button(root, text="Download", command=self.start_download) self.download_button.pack() # Status Label self.status_label = tk.Label(root, text="") self.status_label.pack() def browse_directory(self): directory = filedialog.askdirectory() self.download_dir_entry.delete(0, tk.END) self.download_dir_entry.insert(0, directory) def start_download(self): url = self.url_entry.get() download_dir = self.download_dir_entry.get() youtube_quality = self.youtube_quality.get() if not url or not download_dir: messagebox.showerror("Error", "Please fill in both URL and Download Directory") return thread = Thread(target=self.download, args=(url, download_dir, youtube_quality)) thread.start() def download(self, url, download_dir, youtube_quality): try: if "youtube.com" in url or "youtu.be" in url: self.status_label['text'] = "Downloading YouTube video..." self.download_youtube(url, download_dir, youtube_quality) else: self.status_label['text'] = "Downloading file..." self.download_file(url, download_dir) self.status_label['text'] = "Download complete!" except Exception as e: self.status_label['text'] = f"Error: {str(e)}" messagebox.showerror("Error", str(e)) def download_youtube(self, url, download_dir, youtube_quality): ydl_opts = { 'outtmpl': f'{download_dir}/%(title)s.%(ext)s', } if youtube_quality == "Audio Only": ydl_opts['format'] = 'bestaudio' ydl_opts['postprocessors'] = [{ 'key': 'FFmpegExtractAudio', 'preferredcodec': 'mp3', 'preferredquality': '0', }] else: if youtube_quality == "Highest": ydl_opts['format'] = 'bestvideo[height<=1080]+bestaudio/best' elif youtube_quality == "720p": ydl_opts['format'] = 'bestvideo[height<=720]+bestaudio/best' elif youtube_quality == "480p": ydl_opts['format'] = 'bestvideo[height<=480]+bestaudio/best' ydl_opts['merge_output_format'] = 'mp4' with yt_dlp.YoutubeDL(ydl_opts) as ydl: ydl.download([url]) def download_file(self, url, download_dir): response = requests.get(url, stream=True) if response.status_code != 200: raise Exception(f"Failed to download file. Status code: {response.status_code}") filename = url.split("/")[-1] filepath = f"{download_dir}/{filename}" with open(filepath, 'wb') as f: for chunk in response.iter_content(chunk_size=1024): if chunk: f.write(chunk) if __name__ == "__main__": root = tk.Tk() app = DownloaderApp(root) root.mainloop()How to run:
- Save the code above as a
.pyfile (e.g.,downloader.py). - Make sure you have Python and the required libraries (
yt-dlpandrequests) installed. - Run the script using Python (e.g.,
python downloader.py).
This will launch a GUI application where you can input a URL, select a download directory, and choose the YouTube quality (if applicable). The download will start when you click the "Download" button.
Note: This is a basic implementation. You may want to add more features, such as error handling, progress bars, or support for more download options.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.