fix spotify url issue and handle local tracks properly

This commit is contained in:
vveeps 2021-11-06 23:07:11 +02:00
parent ec02cbe146
commit 81bf0b9756
3 changed files with 7 additions and 4 deletions

View File

@ -11,7 +11,7 @@ class Album:
self.total_tracks = data["total_tracks"]
self.id = data["id"]
self.image = data["images"][0]["url"]
self.uri = f"https://open.spotify.com/album/{self.id}"
self.uri = data["external_urls"]["spotify"]
def __repr__(self) -> str:
return (

View File

@ -12,7 +12,7 @@ class Playlist:
self.total_tracks = data["tracks"]["total"]
self.id = data["id"]
self.image = data["images"][0]["url"]
self.uri = f"https://open.spotify.com/playlist/{self.id}"
self.uri = data["external_urls"]["spotify"]
def __repr__(self) -> str:
return (

View File

@ -7,12 +7,15 @@ class Track:
self.length = data["duration_ms"]
self.id = data["id"]
if data.get("album") and data["album"]["images"]:
if data.get("album") and data["album"].get("images"):
self.image = data["album"]["images"][0]["url"]
else:
self.image = None
self.uri = f"https://open.spotify.com/track/{self.id}"
if data["is_local"]:
self.uri = None
else:
self.uri = data["external_urls"]["spotify"]
def __repr__(self) -> str:
return (