In this tutorial, I’ll create a YouTube Downloader using ChatGPT watch the video and try this Code.
Source Code is here:
import tkinter as tk
from tkinter import messagebox, ttk
from pytube import YouTube
import threading
import os
def download_video():
video_url = url_entry.get()
try:
yt = YouTube(video_url)
stream = yt.streams.get_highest_resolution()
video_title = yt.title
file_size = stream.filesize
def download():
stream.download(output_path=”C:/videos/”)
messagebox.showinfo(“Success”, f”Video ‘{video_title}’ downloaded successfully!”)
def update_progress():
while stream.filesize > os.path.getsize(“C:/videos/” + stream.title + “.mp4”):
bytes_downloaded = os.path.getsize(“C:/videos/” + stream.title + “.mp4”)
percent = (bytes_downloaded / file_size) * 100
progress_bar[‘value’] = percent # Set the progress bar value directly
root.update_idletasks()
progress_bar[‘value’] = 100
download()
download_thread = threading.Thread(target=download)
download_thread.start()
progress_thread = threading.Thread(target=update_progress)
progress_thread.start()
except Exception as e:
messagebox.showerror(“Error”, f”An error occurred: {str(e)}”)
# Create the main window
root = tk.Tk()
root.title(“YouTube Video Downloader”)
# Set the initial window size
root.geometry(“400×250”) # Width x Height
# Create a custom style for the labels
label_style = ttk.Style()
label_style.configure(“CustomLabel.TLabel”, foreground=”#333″, font=(“Helvetica”, 12))
url_label = ttk.Label(root, text=”Enter YouTube URL:”, style=”CustomLabel.TLabel”)
url_label.pack(pady=10)
# Create a custom style for the entry widget
entry_style = ttk.Style()
entry_style.configure(“CustomEntry.TEntry”, font=(“Helvetica”, 12))
url_entry = ttk.Entry(root, width=40, style=”CustomEntry.TEntry”)
url_entry.pack(pady=10)
# Create a custom style for the buttons
button_style = ttk.Style()
button_style.configure(“CustomButton.TButton”, foreground=”black”, background=”#0074D9″, font=(“Helvetica”, 13))
download_button = ttk.Button(root, text=”Download”, command=download_video, style=”CustomButton.TButton”)
download_button.pack(pady=10)
# Create the progress bar
progress_bar = ttk.Progressbar(root, length=200, mode=’determinate’)
progress_bar.pack(pady=10)
root.mainloop()