#A YouTube Video Downloader GUI In Python
from customtkinter import *
from pytube import YouTube

def Download():
    """
    Function to download YouTube videos based on the provided link.
    """
    link = inp_link.get()
    try:
        # making object of the YouTube class from pytube
        youtubeObject = YouTube(link)
        # setting resolution to best
        youtubeObject = youtubeObject.streams.get_highest_resolution()
        # downloading the video
        youtubeObject.download()
        # clearing input widget after the download is successful
        inp_link.delete(0, 'end')
        # providing successfully downloaded message to the user provinding the location of video
        label = CTkLabel(app, text="The video's Download is completed successfully. You can check it in the same directory.")
        label.grid(row=2, column=0, columnspan=2)

    except Exception as e:
        # displaying errors if any
        label = CTkLabel(app, text=e)
        label.grid(row=2, column=0, columnspan=2)
    
# creating a GUI window
app = CTk()
# getting the link
inp_link = CTkEntry(app, placeholder_text="Enter your link here: ")
inp_link.grid(row=0, column=0, columnspan=2, padx=10, pady=10)
# button to download the video at the given link
download = CTkButton(app, text="Download", command=Download)
download.grid(row=1, column=0, columnspan=2, padx=10, pady=10)
app.mainloop()