summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJackson Taylor <jackson@jacksontaylor.xyz>2023-05-10 12:48:52 -0400
committerJackson Taylor <jackson@jacksontaylor.xyz>2023-05-10 12:48:52 -0400
commit56da4e191267147318b2ab2010d92b22fac747da (patch)
treeec908ddbb57fd63f4ce8f097bc0c3fcdfbcfc710
parent7bda15b7d5d034ce2be4293693b2a84ce4b40c3d (diff)
Move error classes to separate module
-rw-r--r--errors.py10
-rwxr-xr-xjamos15
2 files changed, 14 insertions, 11 deletions
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'],