From 762160e84b255db57cb9b1da0de42640ad10162a Mon Sep 17 00:00:00 2001 From: vveeps <54472340+vveeps@users.noreply.github.com> Date: Tue, 26 Oct 2021 17:57:42 +0300 Subject: [PATCH] dont error on imageless spotify tracks --- pomice/spotify/track.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pomice/spotify/track.py b/pomice/spotify/track.py index 6fe5632..96af859 100644 --- a/pomice/spotify/track.py +++ b/pomice/spotify/track.py @@ -1,12 +1,18 @@ class Track: """The base class for a Spotify Track""" + def __init__(self, data: dict) -> None: self.name = data['name'] self.artists = ", ".join(artist["name"] for artist in data['artists']) self.length = data['duration_ms'] self.id = data['id'] - self.image = data['album']['images'][0]['url'] if data.get('album') else None + + if data.get("album") and data["album"]["images"]: + self.image = data['album']['images'][0]['url'] + else: + self.image = None + self.uri = data['external_urls']['spotify'] def __repr__(self) -> str: - return f"" \ No newline at end of file + return f""