from pytube import YouTube

# Function to download YouTube video
def download_video(url):
    try:
        # Create a YouTube object
        video = YouTube(url)

        # Get the highest resolution video stream
        stream = video.streams.get_highest_resolution()

        # Download the video
        print("Downloading:", video.title)
        stream.download()
        print("Download complete!")

    except Exception as e:
        print("An error occurred:", str(e))

# Main program
if __name__ == "__main__":
    # Prompt user for YouTube video URL
    video_url = input("Enter the YouTube video URL: ")

    # Call the download_video function
    download_video(video_url)