0

I just created a tkinter application to download YouTube Videos. Now I would like to show the download progress with a Progressbar. There is a built-in Progressbar tool but I can´t find a way to connect it to the try-statement. Is there a way to do this?

Here´s my code:

import customtkinter as ctkt
from pytube import YouTube
import os

path = os.getcwd()

ctkt.set_appearance_mode("dark")
ctkt.set_default_color_theme("dark-blue")

root = ctkt.CTk()
root.geometry("500x500")
root.title("Youtube Downloader")
root.resizable(False, False)


def downloadVid():
    try: #The progress bar appears if try works
        ytLink = link.get()
        ytObject = YouTube(ytLink)

        video = ytObject.streams.get_highest_resolution()
        video.download() # It should show the progress of this
        succeededMessage = ctkt.CTkLabel(master=root, text="[+] Dowload Complete")
        succeededMessage.pack()

    except:
        errorMessage = ctkt.CTkLabel(master=root, text="[-] This Link Is Invalid")
        errorMessage.pack()



link = ctkt.CTkEntry(master=root, width=300, height=20, placeholder_text="Paste the video link here...")
link.pack(pady=15, padx=15)



dowloadBtn = ctkt.CTkButton(master=root, command=downloadVid, text="Download")
dowloadBtn.pack(pady=15, padx=15)

def open_videos():
    os.startfile(path)

open_folder = ctkt.CTkButton(master=root, command=open_videos, text="Saved videos")
open_folder.pack()




root.mainloop()

  • Does the `download()` method provide any sort of hooks for check the progress of the download? Does it return a value? – JRiggles Aug 28 '23 at 13:48
  • Does this answer your question? [How to use Progress bar in pytube?](https://stackoverflow.com/questions/56197879/how-to-use-progress-bar-in-pytube) – JRiggles Aug 28 '23 at 13:51
  • Oh after long research I did find something in the pytube documentation: *he on_progress_callback function will run whenever a chunk is downloaded from a video, and is called with three arguments: the stream, the data chunk, and the bytes remaining in the video. This could be used, for example, to display a progress bar.* But I don´t know how to use it – Marius Prakash Aug 28 '23 at 13:51
  • I had found this dosumentation but I couldn´t figure out how to use iit in tkinter @JRiggles – Marius Prakash Aug 28 '23 at 13:59

0 Answers0