From 7694de346eeae20b5d04ce922debe1207d0b9e6c Mon Sep 17 00:00:00 2001 From: Paddez Date: Sat, 22 Jun 2019 11:04:09 +0100 Subject: [PATCH] Store Album Art URLs when you call GetTopAlbums. GetTopAlbums returns AlbumArt information alongside the TopAlbums. We should store this in the Album() info variable, so we don't have to follow up with an additional GetInfo() call if we want the Album Art. Signed-off-by: Paddez --- src/pylast/__init__.py | 3 ++- tests/test_user.py | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/pylast/__init__.py b/src/pylast/__init__.py index 93c8c49..c5d7e05 100644 --- a/src/pylast/__init__.py +++ b/src/pylast/__init__.py @@ -2896,8 +2896,9 @@ def _extract_top_albums(doc, network): name = _extract(node, "name") artist = _extract(node, "name", 1) playcount = _extract(node, "playcount") + info = {"image": _extract_all(node, "image")} - seq.append(TopItem(Album(artist, name, network), playcount)) + seq.append(TopItem(Album(artist, name, network, info=info), playcount)) return seq diff --git a/tests/test_user.py b/tests/test_user.py index e648962..a8b724d 100755 --- a/tests/test_user.py +++ b/tests/test_user.py @@ -271,6 +271,12 @@ class TestPyLastUser(TestPyLastWithLastFm): # Assert self.helper_only_one_thing_in_top_list(albums, pylast.Album) + top_album = albums[0].item + self.assertTrue(len(top_album.info["image"])) + self.assertRegexpMatches( + top_album.info["image"][pylast.SIZE_LARGE], r"^http.+$" + ) + def test_user_tagged_artists(self): # Arrange lastfm_user = self.network.get_user(self.username)