From fe79d78b656cb1487876903de2da08e70ec9c0c4 Mon Sep 17 00:00:00 2001 From: Shabir Mahfudz Prahono Date: Sun, 19 May 2024 17:33:13 +0700 Subject: [PATCH 1/2] Update ytDownloader.py Added Features: 1. A neater and more organized appearance. Importing the "os" library that make the output easy to see. 2. Added history log file that save the download history. file saved in `history.yt` --- ytDownloader.py | 86 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 68 insertions(+), 18 deletions(-) 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() From 88b4e382a032c2e69aaba390d335c04e3765c6a6 Mon Sep 17 00:00:00 2001 From: Shabir Mahfudz Prahono Date: Sun, 19 May 2024 17:34:39 +0700 Subject: [PATCH 2/2] Create history.yt File Features: Added history log from ytDownloader.py file that save the download history. File saved in `history.yt`, this file. --- history.yt | 1 + 1 file changed, 1 insertion(+) create mode 100644 history.yt diff --git a/history.yt b/history.yt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/history.yt @@ -0,0 +1 @@ +