Store artist images for future use
This commit is contained in:
parent
942ced319a
commit
d1af8d3ebc
|
@ -133,5 +133,5 @@ network = pylast.LastFMNetwork(...)
|
||||||
To enable from pytest:
|
To enable from pytest:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
pytest -k test_album_search_images --log-cli-level debug
|
pytest --log-cli-level debug -k test_album_search_images
|
||||||
```
|
```
|
||||||
|
|
|
@ -1552,7 +1552,7 @@ class Artist(_BaseObject, _Taggable):
|
||||||
|
|
||||||
__hash__ = _BaseObject.__hash__
|
__hash__ = _BaseObject.__hash__
|
||||||
|
|
||||||
def __init__(self, name, network, username=None):
|
def __init__(self, name, network, username=None, images=None):
|
||||||
"""Create an artist object.
|
"""Create an artist object.
|
||||||
# Parameters:
|
# Parameters:
|
||||||
* name str: The artist's name.
|
* name str: The artist's name.
|
||||||
|
@ -1563,6 +1563,7 @@ class Artist(_BaseObject, _Taggable):
|
||||||
|
|
||||||
self.name = name
|
self.name = name
|
||||||
self.username = username
|
self.username = username
|
||||||
|
self.images = images
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "pylast.Artist(%s, %s)" % (
|
return "pylast.Artist(%s, %s)" % (
|
||||||
|
@ -1615,8 +1616,11 @@ class Artist(_BaseObject, _Taggable):
|
||||||
SIZE_SMALL
|
SIZE_SMALL
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return _extract_all(
|
if not self.images:
|
||||||
self._request(self.ws_prefix + ".getInfo", True), "image")[size]
|
self.images = _extract_all(
|
||||||
|
self._request(self.ws_prefix + ".getInfo", cacheable=True),
|
||||||
|
"image")
|
||||||
|
return self.images[size]
|
||||||
|
|
||||||
def get_playcount(self):
|
def get_playcount(self):
|
||||||
"""Returns the number of plays on the network."""
|
"""Returns the number of plays on the network."""
|
||||||
|
@ -2554,7 +2558,8 @@ class AlbumSearch(_Search):
|
||||||
_extract(node, "artist"),
|
_extract(node, "artist"),
|
||||||
_extract(node, "name"),
|
_extract(node, "name"),
|
||||||
self.network,
|
self.network,
|
||||||
images=_extract_all(node, 'image')))
|
images=_extract_all(node, 'image')),
|
||||||
|
)
|
||||||
|
|
||||||
return seq
|
return seq
|
||||||
|
|
||||||
|
@ -2572,7 +2577,8 @@ class ArtistSearch(_Search):
|
||||||
|
|
||||||
seq = []
|
seq = []
|
||||||
for node in master_node.getElementsByTagName("artist"):
|
for node in master_node.getElementsByTagName("artist"):
|
||||||
artist = Artist(_extract(node, "name"), self.network)
|
artist = Artist(_extract(node, "name"), self.network,
|
||||||
|
images=_extract_all(node, "image"))
|
||||||
artist.listener_count = _number(_extract(node, "listeners"))
|
artist.listener_count = _number(_extract(node, "listeners"))
|
||||||
seq.append(artist)
|
seq.append(artist)
|
||||||
|
|
||||||
|
|
|
@ -347,6 +347,26 @@ class TestPyLastNetwork(PyLastTestCase):
|
||||||
self.assertIsInstance(results, list)
|
self.assertIsInstance(results, list)
|
||||||
self.assertIsInstance(results[0], pylast.Artist)
|
self.assertIsInstance(results[0], pylast.Artist)
|
||||||
|
|
||||||
|
def test_artist_search_images(self):
|
||||||
|
# Arrange
|
||||||
|
artist = "Nirvana"
|
||||||
|
search = self.network.search_for_artist(artist)
|
||||||
|
|
||||||
|
# Act
|
||||||
|
results = search.get_next_page()
|
||||||
|
images = results[0].images
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
self.assertEqual(len(images), 5)
|
||||||
|
|
||||||
|
self.assertTrue(images[pylast.SIZE_SMALL].startswith("https://"))
|
||||||
|
self.assertTrue(images[pylast.SIZE_SMALL].endswith(".png"))
|
||||||
|
self.assertIn("/34s/", images[pylast.SIZE_SMALL])
|
||||||
|
|
||||||
|
self.assertTrue(images[pylast.SIZE_EXTRA_LARGE].startswith("https://"))
|
||||||
|
self.assertTrue(images[pylast.SIZE_EXTRA_LARGE].endswith(".png"))
|
||||||
|
self.assertIn("/300x300/", images[pylast.SIZE_EXTRA_LARGE])
|
||||||
|
|
||||||
def test_track_search(self):
|
def test_track_search(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
artist = "Nirvana"
|
artist = "Nirvana"
|
||||||
|
|
Loading…
Reference in a new issue