From 8f4dcb7eef4a6be43153edf57d28c5af5c6827b2 Mon Sep 17 00:00:00 2001 From: Parker Date: Fri, 29 Nov 2024 22:59:13 -0600 Subject: [PATCH] Add `artworkUrl` checks to remaining Spotify load funcs --- code/utils/custom_sources.py | 12 ++++++++++-- 1 file 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, )