dont error on imageless spotify tracks
This commit is contained in:
parent
1b54aae3b3
commit
762160e84b
|
|
@ -1,11 +1,17 @@
|
||||||
class Track:
|
class Track:
|
||||||
"""The base class for a Spotify Track"""
|
"""The base class for a Spotify Track"""
|
||||||
|
|
||||||
def __init__(self, data: dict) -> None:
|
def __init__(self, data: dict) -> None:
|
||||||
self.name = data['name']
|
self.name = data['name']
|
||||||
self.artists = ", ".join(artist["name"] for artist in data['artists'])
|
self.artists = ", ".join(artist["name"] for artist in data['artists'])
|
||||||
self.length = data['duration_ms']
|
self.length = data['duration_ms']
|
||||||
self.id = data['id']
|
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']
|
self.uri = data['external_urls']['spotify']
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue