diff --git a/history.yt b/history.yt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/history.yt @@ -0,0 +1 @@ + diff --git a/ytDownloader.py b/ytDownloader.py index 03463fa..dc91143 100644 --- a/ytDownloader.py +++ b/ytDownloader.py @@ -1,20 +1,70 @@ from pytube import YouTube +import os, time -try: - # Ask the user to input the YouTube URL - url = input("Enter the YouTube URL: ") - - yt = YouTube(url) - - print("Title:", yt.title) - print("Views:", yt.views) - - # Get the highest resolution stream - yd = yt.streams.get_highest_resolution() - - # Download the video to the current directory - yd.download() - - print("Download complete.") -except Exception as e: - print("An error occurred:", str(e)) + +def home(): + print("\033[31mYoutube Video Downloader\033[0m") + print("1. Download Video \n2. See Download History") + inpt = input("> ").strip().lower() + if inpt == "1": + download() + elif inpt == "2": + history() + else: + print("Input not valid. You will directed to download.") + time.sleep(2) + os.system("clear") + download() + + +def download(): + os.system("clear") + try: + url = input("Enter the YouTube Video URL: ") + yt = YouTube(url) + os.system("clear") + print("Video URL :", url) + print("Video Title:", yt.title) + print("Video Views:", yt.views) + print() + print("\033[32mVideo caught. Request the highest resolution...\033[0m") + yd = yt.streams.get_highest_resolution() + os.system("clear") + print("Video URL :", url) + print("Video Title:", yt.title) + print("Video Views:", yt.views) + print() + print( + "\033[32mThe highest resolution video has been obtained. Downloading Videos...\033[0m" + ) + yd.download() + os.system("clear") + print("\033[32mDownload complete.\033[0m") + f = open("history.yt", "a+") + f.write( + f"\nVideo URL: {url}\nVideo Title: {yt.title}\nVideo Views: {yt.views}" + ) + f.write("\n-----------------") + f.close() + time.sleep(2) + os.system("clear") + home() + except Exception as e: + print("An error occurred:", str(e)) + time.sleep(2) + os.system("clear") + home() + + +def history(): + os.system("clear") + f = open("history.yt", "r") + data = f.read() + print(data) + print() + exit = input("Press enter to exit. ") + os.system("clear") + home() + + +home()