From a12a00a06810f87cc2085e6f13c27b17f51f4eed Mon Sep 17 00:00:00 2001 From: vervaekejonathan Date: Mon, 1 Jun 2020 17:45:32 +0200 Subject: [PATCH] Add extra album info to the recent track --- src/pylast/__init__.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/pylast/__init__.py b/src/pylast/__init__.py index 5ddab60d..d281c692 100644 --- a/src/pylast/__init__.py +++ b/src/pylast/__init__.py @@ -547,7 +547,6 @@ def scrobble( context=None, mbid=None, ): - """Used to add a track-play to a user's profile. Parameters: @@ -2128,16 +2127,17 @@ def is_fulltrack_available(self): def get_album(self): """Returns the album object of this track.""" + if "album" not in self.info: + doc = self._request(self.ws_prefix + ".getInfo", True) - doc = self._request(self.ws_prefix + ".getInfo", True) - - albums = doc.getElementsByTagName("album") + albums = doc.getElementsByTagName("album") - if len(albums) == 0: - return + if len(albums) == 0: + return - node = doc.getElementsByTagName("album")[0] - return Album(_extract(node, "artist"), _extract(node, "title"), self.network) + node = doc.getElementsByTagName("album")[0] + return Album(_extract(node, "artist"), _extract(node, "title"), self.network) + return Album(self.artist, self.info["album"], self.network) def love(self): """Adds the track to the user's loved tracks. """ @@ -2338,8 +2338,9 @@ def get_now_playing(self): artist = _extract(e, "artist") title = _extract(e, "name") + info = {"image": _extract_all(e, "image"), "album": _extract(e, 'album')} - return Track(artist, title, self.network, self.name) + return Track(artist, title, self.network, self.name, info=info) def get_recent_tracks(self, limit=10, cacheable=True, time_from=None, time_to=None): """