video-downloader/downloader.py

70 lines
2.3 KiB
Python

import threading
import tkinter as tk
from tkinter import ttk, filedialog, messagebox
from download import download
def update_progress_bar(percentage):
progress_var.set(percentage)
def start_download():
url = url_entry.get()
filename = filename_entry.get()
dest_dir = directory_var.get()
audio_only = audio_only_var.get()
if not url or not filename or not dest_dir:
messagebox.showerror("Error", "Please fill in all required fields!")
return
# Run the download function in a separate thread
thread = threading.Thread(target=download, args=(url, filename, dest_dir, audio_only, update_progress_bar))
thread.start()
def select_directory():
directory = filedialog.askdirectory()
directory_var.set(directory)
# GUI Setup
app = tk.Tk()
app.title("yt-dlp Downloader")
frame = ttk.Frame(app, padding="10")
frame.grid(row=0, column=0, sticky=(tk.W, tk.E, tk.N, tk.S))
# URL input
url_label = ttk.Label(frame, text="Video URL:")
url_label.grid(row=0, column=0, sticky=tk.W, pady=5)
url_entry = ttk.Entry(frame, width=40)
url_entry.grid(row=0, column=1, pady=5)
# Filename input
filename_label = ttk.Label(frame, text="Filename (without extension):")
filename_label.grid(row=1, column=0, sticky=tk.W, pady=5)
filename_entry = ttk.Entry(frame, width=40)
filename_entry.grid(row=1, column=1, pady=5)
# Directory chooser
directory_var = tk.StringVar()
directory_label = ttk.Label(frame, text="Destination Directory:")
directory_label.grid(row=2, column=0, sticky=tk.W, pady=5)
directory_entry = ttk.Entry(frame, width=30, textvariable=directory_var)
directory_entry.grid(row=2, column=1, pady=5, sticky=tk.W)
directory_btn = ttk.Button(frame, text="Browse", command=select_directory)
directory_btn.grid(row=2, column=2, pady=5, sticky=tk.W)
# Audio only checkbox
audio_only_var = tk.BooleanVar()
audio_only_checkbox = ttk.Checkbutton(frame, text="Audio Only", variable=audio_only_var)
audio_only_checkbox.grid(row=3, column=1, sticky=tk.W, pady=5)
# Download button
download_btn = ttk.Button(frame, text="Download", command=start_download)
download_btn.grid(row=4, column=1, pady=10)
# Progress bar
progress_var = tk.DoubleVar()
progress_bar = ttk.Progressbar(frame, orient="horizontal", length=300, variable=progress_var, maximum=100)
progress_bar.grid(row=5, column=0, columnspan=3, pady=5)
app.mainloop()