From 1740bca6e3450c2dc14c82bb8fb63a2ec5aed80a Mon Sep 17 00:00:00 2001 From: thecookingsenpai Date: Wed, 27 Dec 2023 23:40:23 +0100 Subject: [PATCH] Playlist resume support + playlist auto organization in folders support --- README.md | 6 ++++++ downloads/placeholder | 1 - term.py | 29 ++++++++++++++++++++++++----- 3 files changed, 30 insertions(+), 6 deletions(-) delete mode 100644 downloads/placeholder diff --git a/README.md b/README.md index bb1c8c6..4a3387f 100644 --- a/README.md +++ b/README.md @@ -36,11 +36,17 @@ TransTerm is an highly experimental text based graphical user interface to act o Being text based, this program runs even in the terminal. +## Latest changelog + +Added experimental playlist folder support and playlist resume support. +Please report any issues. + ## Features - Download any youtube video at the highest resolution by default in mp4 format - Is able to automatically convert the downloaded video both in mp3 or wav format - Playlist support for the above features including automatically rename the files using the video title and the channel name +- Playlists organization in folders with resume support (aka check if files are already there with the same title and channel) - Transcribe a ssingle downloaded video using either: • Google Audio to Text • Google Audio to Text + Silence detection diff --git a/downloads/placeholder b/downloads/placeholder deleted file mode 100644 index 0b719f7..0000000 --- a/downloads/placeholder +++ /dev/null @@ -1 +0,0 @@ -why are you looking at me, my only purpose is to create my parent folder \ No newline at end of file diff --git a/term.py b/term.py index 599e23e..4a9acc8 100644 --- a/term.py +++ b/term.py @@ -14,6 +14,17 @@ forceQuit = False r = sr.Recognizer() +# NOTE: WIP This method is intended to be called to check for the same file (by using slugified name) +def existing(filename): + path_to_download_folder = ( + str(os.path.dirname(os.path.realpath(__file__))) + "/downloads" + ) + for file in os.listdir(path_to_download_folder): + if filename is file: + return True + return False + + # NOTE: Taken from https://stackoverflow.com/questions/295135/turn-a-string-into-a-valid-filename def slugify(value, allow_unicode=False): """ @@ -142,18 +153,26 @@ def managePlaylist(playlist, to_download=False, to_convert=False, named=True): if not to_download: return playlist counter = 0 + normalized_title = slugify(playlist.title) path_to_download_folder = ( - str(os.path.dirname(os.path.realpath(__file__))) + "/downloads" + str(os.path.dirname(os.path.realpath(__file__))) + + "/downloads/" + + normalized_title ) + # Creating a folder for the playlist if it doesn't exist + if not os.path.isdir(path_to_download_folder): + os.mkdir(path_to_download_folder) + # Iterating and doing our job(s) for url in playlist: counter += 1 print("Downloading video", counter, "of", len(playlist)) ytvideo = YouTube(url) + filename = slugify(ytvideo.title + "_" + ytvideo.author) + # EXPERIMENTAL Skip if file already exists (aka resume playlist download) + if existing(filename): + print("File already exists: [" + filename + "]\nskipping...") + continue video = ytvideo.streams.get_highest_resolution() - filename = "video_" + str(counter) - # Experimental name support - if named: - filename = slugify(ytvideo.title + "_" + ytvideo.author) print("Downloading : ", filename) video.download(path_to_download_folder, filename=filename + ".mp4") if to_convert: