From eeabede2cdade1aaf4df809e36032b78d28fb694 Mon Sep 17 00:00:00 2001 From: Jackson Taylor Date: Mon, 8 Aug 2022 08:40:49 -0400 Subject: Update README Add usage information Update TODOs --- README.md | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 01347da..3c00cd2 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,33 @@ Personal script to when downloading music with youtube-dl, tagging the files (ar ## Installation Right now, the easiest thing to do is just use it from this repo. +## Usage +Output from using the "--help" option: +``` +usage: jamos [-h] [-c cookiefile.txt] [-o output_directory] [-r jamos_failed_urls.txt] [https://music.youtube.com/playlist?list=1234] + +Download songs from YouTube Music + +positional arguments: + https://music.youtube.com/playlist?list=1234 + Playlist or Song URL to download. + +optional arguments: + -h, --help show this help message and exit + -c cookiefile.txt, --cookies cookiefile.txt + Cookie file to use. + -o output_directory, --output output_directory + Output directory to use + -r jamos_failed_urls.txt, --retryFile jamos_failed_urls.txt + Output directory to use + +``` + +The most common usage (aka tldr) would probably be something like: +``` +$ jamos "https://music.youtube.com/playlist/1234" -o "/home/jackson/Music" +``` + ## TODO - Installation - Add necessary files to install via pip @@ -13,4 +40,4 @@ Right now, the easiest thing to do is just use it from this repo. - Configuration - Config file in XDG directory - URL file in XDG directory - - Command line parameters + - [Done] Command line parameters -- cgit v1.2.3 From a26ff373d5f875f0fe20935846f98e1bef439c06 Mon Sep 17 00:00:00 2001 From: Jackson Taylor Date: Mon, 8 Aug 2022 09:29:19 -0400 Subject: Alphabetize functions Alphabetize functions according to old PEP8 standards --- jamos | 169 ++++++++++++++++++++++++++++++++---------------------------------- 1 file changed, 82 insertions(+), 87 deletions(-) diff --git a/jamos b/jamos index e947e3d..81d47ff 100755 --- a/jamos +++ b/jamos @@ -19,6 +19,26 @@ def cleanup_metadata_files(music_directory): os.remove(file) +def create_downloader(music_directory, cookies): + audio_options = { + 'format': 'mp3/bestaudio/best', + 'cookiefile': cookies, + 'outtmpl': music_directory + '%(title)s.%(ext)s', + 'postprocessors': [ + { + 'key': 'FFmpegExtractAudio', + 'preferredcodec': 'mp3', + 'preferredquality': '192', + }, + {'key': 'FFmpegMetadata'}, + ], + 'writeinfojson': True, + 'quiet': not DEBUG + } + + return youtube_dl.YoutubeDL(audio_options) + + def format_youtube_date(date): default = "Unknown Year" try: @@ -88,76 +108,6 @@ def get_command_line_options(): return args -# TODO: switch command line args to argparse -def get_playlist_url(): - return sys.argv[1] - - -def get_video_urls_in_playlist(playlist_url, ytdl): - videos = ytdl.extract_info(playlist_url, download=False) - - urls = [] - for vid in videos['entries']: - if 'webpage_url' in vid.keys() and vid['webpage_url'] is not None: - urls.append(vid['webpage_url']) - - return urls - - -def remove_special_characters_for_filename(filename): - special_chars = [ - ['-', ' '], - ['(', ''], - [')', ''], - ['/', ' '], - ['/', ' '], - [' ', '_'], - ["'", ''], - ["&", 'and'], - [chr(8217), ''], - ['$', 's'], - ['.', ''] - ] - new_name = filename - - for char_set in special_chars: - new_name = new_name.replace(char_set[0], char_set[1]) - - return new_name.lower() - - -def move_file(file, metadata, output_directory): - artist = remove_special_characters_for_filename(metadata['artist']) - album = remove_special_characters_for_filename(metadata['album']) - title = remove_special_characters_for_filename(metadata['title']) - - final_directory = os.path.join( - output_directory, - artist, - album) - - Path(final_directory).mkdir(parents=True, exist_ok=True) - - # TODO: Research converting to mp3 instead of just naming it such. - # TODO: Research better file formats over mp3? - os.rename( - file, - os.path.join(final_directory, '{}_{}_{}.mp3'.format(artist, - album, - title))) - - -def write_metadata_to_song_file(filename, metadata): - file = music_tag.load_file(filename) - - file['name'] = metadata['title'] - file['artist'] = metadata['artist'] - file['album'] = metadata['album'] - file['year'] = metadata['year'] - - file.save() - - def get_song_metadata_from_json(json, counter): metadata = { 'title': 'unknownsong', @@ -196,24 +146,36 @@ def get_song_metadata_from_json(json, counter): return metadata -def create_downloader(music_directory, cookies): - audio_options = { - 'format': 'mp3/bestaudio/best', - 'cookiefile': cookies, - 'outtmpl': music_directory + '%(title)s.%(ext)s', - 'postprocessors': [ - { - 'key': 'FFmpegExtractAudio', - 'preferredcodec': 'mp3', - 'preferredquality': '192', - }, - {'key': 'FFmpegMetadata'}, - ], - 'writeinfojson': True, - 'quiet': not DEBUG - } +def get_video_urls_in_playlist(playlist_url, ytdl): + videos = ytdl.extract_info(playlist_url, download=False) - return youtube_dl.YoutubeDL(audio_options) + urls = [] + for vid in videos['entries']: + if 'webpage_url' in vid.keys() and vid['webpage_url'] is not None: + urls.append(vid['webpage_url']) + + return urls + + +def move_file(file, metadata, output_directory): + artist = remove_special_characters_for_filename(metadata['artist']) + album = remove_special_characters_for_filename(metadata['album']) + title = remove_special_characters_for_filename(metadata['title']) + + final_directory = os.path.join( + output_directory, + artist, + album) + + Path(final_directory).mkdir(parents=True, exist_ok=True) + + # TODO: Research converting to mp3 instead of just naming it such. + # TODO: Research better file formats over mp3? + os.rename( + file, + os.path.join(final_directory, '{}_{}_{}.mp3'.format(artist, + album, + title))) def save_urls_from_playlist_to_file(filename, urls): @@ -227,6 +189,39 @@ def save_urls_from_playlist_to_file(filename, urls): raise e +def remove_special_characters_for_filename(filename): + special_chars = [ + ['-', ' '], + ['(', ''], + [')', ''], + ['/', ' '], + ['/', ' '], + [' ', '_'], + ["'", ''], + ["&", 'and'], + [chr(8217), ''], + ['$', 's'], + ['.', ''] + ] + new_name = filename + + for char_set in special_chars: + new_name = new_name.replace(char_set[0], char_set[1]) + + return new_name.lower() + + +def write_metadata_to_song_file(filename, metadata): + file = music_tag.load_file(filename) + + file['name'] = metadata['title'] + file['artist'] = metadata['artist'] + file['album'] = metadata['album'] + file['year'] = metadata['year'] + + file.save() + + if __name__ == "__main__": try: args = get_command_line_options() -- cgit v1.2.3