diff options
author | Parker <contact@pkrm.dev> | 2024-11-29 22:59:13 -0600 |
---|---|---|
committer | Parker <contact@pkrm.dev> | 2024-11-29 22:59:13 -0600 |
commit | 8f4dcb7eef4a6be43153edf57d28c5af5c6827b2 (patch) | |
tree | 009597a2d7830813554eee9b201745cf3bc6de16 | |
parent | 60bace9f2885270c566b406460731a49a2103fc4 (diff) |
Add `artworkUrl` checks to remaining Spotify load funcs
-rw-r--r-- | code/utils/custom_sources.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/code/utils/custom_sources.py b/code/utils/custom_sources.py index ee441d6..240947d 100644 --- a/code/utils/custom_sources.py +++ b/code/utils/custom_sources.py @@ -73,6 +73,10 @@ class SpotifySource(Source): ) # Initialising our custom source with the name 'custom'. async def load_item(self, user, metadata): + try: + artwork_url = metadata["album"]["images"][0]["url"] + except IndexError: + artwork_url = None track = CustomAudioTrack( { # Create an instance of our CustomAudioTrack. "identifier": metadata[ @@ -85,7 +89,7 @@ class SpotifySource(Source): "title": metadata["name"], "uri": metadata["external_urls"]["spotify"], "duration": metadata["duration_ms"], - "artworkUrl": metadata["album"]["images"][0]["url"], + "artworkUrl": artwork_url, }, requester=user, ) @@ -98,6 +102,10 @@ class SpotifySource(Source): for track in metadata["tracks"][ "items" ]: # Loop through each track in the album. + try: + artwork_url = track["album"]["images"][0]["url"] + except IndexError: + artwork_url = None tracks.append( CustomAudioTrack( { # Create an instance of our CustomAudioTrack. @@ -111,7 +119,7 @@ class SpotifySource(Source): "title": track["name"], "uri": track["external_urls"]["spotify"], "duration": track["duration_ms"], - "artworkUrl": metadata["images"][0]["url"], + "artworkUrl": artwork_url, }, requester=user, ) |