diff options
author | Jackson Taylor <jackson@jacksontaylor.xyz> | 2023-03-22 17:50:26 -0400 |
---|---|---|
committer | Jackson Taylor <jackson@jacksontaylor.xyz> | 2023-03-22 17:50:26 -0400 |
commit | 928947c962fc1fba84fa3be48f50c767f286f5aa (patch) | |
tree | 26d940d554a030a02f389140572b5f42de5afb1c /jamos | |
parent | dc027f1e1b1fa52344f3abfc0562fc633cb73d61 (diff) | |
parent | a26ff373d5f875f0fe20935846f98e1bef439c06 (diff) |
Merge branch 'master' of git.jacksontaylor.xyz:/srv/git/jamos
Diffstat (limited to 'jamos')
-rwxr-xr-x | jamos | 134 |
1 files changed, 63 insertions, 71 deletions
@@ -88,76 +88,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', @@ -213,7 +143,36 @@ def create_downloader(music_directory, cookies): 'quiet': not DEBUG } - return youtube_dl.YoutubeDL(audio_options) +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 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 +186,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() |