diff options
author | Jackson Taylor <jackson@jacksontaylor.xyz> | 2023-05-10 12:48:52 -0400 |
---|---|---|
committer | Jackson Taylor <jackson@jacksontaylor.xyz> | 2023-05-10 12:48:52 -0400 |
commit | 56da4e191267147318b2ab2010d92b22fac747da (patch) | |
tree | ec908ddbb57fd63f4ce8f097bc0c3fcdfbcfc710 /jamos | |
parent | 7bda15b7d5d034ce2be4293693b2a84ce4b40c3d (diff) |
Move error classes to separate module
Diffstat (limited to 'jamos')
-rwxr-xr-x | jamos | 15 |
1 files changed, 4 insertions, 11 deletions
@@ -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'], |