From 56da4e191267147318b2ab2010d92b22fac747da Mon Sep 17 00:00:00 2001 From: Jackson Taylor Date: Wed, 10 May 2023 12:48:52 -0400 Subject: Move error classes to separate module --- errors.py | 10 ++++++++++ jamos | 15 ++++----------- 2 files changed, 14 insertions(+), 11 deletions(-) create mode 100644 errors.py diff --git a/errors.py b/errors.py new file mode 100644 index 0000000..9348dcb --- /dev/null +++ b/errors.py @@ -0,0 +1,10 @@ +# Used to indicate if something went wrong while trying to organize the music +# file +class UnableToCreateAlbumDirectoryError(Exception): + pass + + +# Used to indicate if the album cover was not found on the disk when the album +# artwork was meant to be inserted +class UnableToFindThumbnailFileError(Exception): + pass diff --git a/jamos b/jamos index dd0a5a0..ba1d52d 100755 --- a/jamos +++ b/jamos @@ -12,6 +12,7 @@ import sys import youtube_dl from ytmusicapi import YTMusic # import musicpd +import errors # TODO: set this to false to begin with. for now it's always gonna print # debug information @@ -40,14 +41,6 @@ ALBUMS = collections.defaultdict(lambda: None) FAILED_SONGS = [] -class UnableToCreateAlbumDirectoryError(Exception): - pass - - -class UnableToFindThumbnailFileError(Exception): - pass - - def get_command_line_options(): parser = argparse.ArgumentParser( description="Download songs from YouTube Music") @@ -403,7 +396,7 @@ def tag_song(filename, song_data): file['artwork'] = img_in.read() except Exception: - raise UnableToFindThumbnailFileError() + raise errors.UnableToFindThumbnailFileError() # save music tag data file.save() @@ -429,7 +422,7 @@ def move_song_to_permanent_location(music_directory, song_data, filename): try: Path(song_output_dir).mkdir(parents=True, exist_ok=True) except OSError as ex: - raise UnableToCreateAlbumDirectoryError(ex) + raise errors.UnableToCreateAlbumDirectoryError(ex) new_filename = '{}_{}_{}.mp3'.format(artist_for_filename, album_for_filename, @@ -457,7 +450,7 @@ def download_songs(ytdl, music_directory, songs): tag_song(filename, song) move_song_to_permanent_location(music_directory, song, filename) - except UnableToCreateAlbumDirectoryError as ex: + except errors.UnableToCreateAlbumDirectoryError as ex: add_to_failed_songs(song, ex) print('Could not download {} - {}, moving on'.format( song['title'], -- cgit v1.2.3