Skip to content

Commit

Permalink
Merge pull request #1 from pylast/zinootje-master
Browse files Browse the repository at this point in the history
 Store all images on get_cover_image for future use
  • Loading branch information
zinootje committed Apr 15, 2018
2 parents c2dfe04 + 4083f72 commit c3476c1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
16 changes: 9 additions & 7 deletions pylast/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,7 @@ class _Request(object):
"""Representing an abstract web service operation."""

def __init__(self, network, method_name, params=None):
print(method_name)

if params is None:
params = {}
Expand Down Expand Up @@ -1369,7 +1370,8 @@ class _Opus(_BaseObject, _Taggable):

__hash__ = _BaseObject.__hash__

def __init__(self, artist, title, network, ws_prefix, username=None, images=None):
def __init__(self, artist, title, network, ws_prefix, username=None,
images=None):
"""
Create an opus instance.
# Parameters:
Expand Down Expand Up @@ -1487,7 +1489,8 @@ class Album(_Opus):
__hash__ = _Opus.__hash__

def __init__(self, artist, title, network, username=None, images=None):
super(Album, self).__init__(artist, title, network, "album", username, images)
super(Album, self).__init__(artist, title, network, "album", username,
images)

def get_cover_image(self, size=SIZE_EXTRA_LARGE):
"""
Expand All @@ -1499,11 +1502,10 @@ def get_cover_image(self, size=SIZE_EXTRA_LARGE):
SIZE_SMALL
"""
if not self.images:
return _extract_all(
self._request(
self.ws_prefix + ".getInfo", cacheable=True), 'image')[size]
else:
return self.images[size]
self.images = _extract_all(
self._request(self.ws_prefix + ".getInfo", cacheable=True),
'image')
return self.images[size]

def get_tracks(self):
"""Returns the list of Tracks on this album."""
Expand Down
20 changes: 20 additions & 0 deletions tests/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,26 @@ def test_album_search(self):
self.assertIsInstance(results, list)
self.assertIsInstance(results[0], pylast.Album)

def test_album_search_images(self):
# Arrange
album = "Nevermind"
search = self.network.search_for_album(album)

# Act
results = search.get_next_page()
images = results[0].images

# Assert
self.assertEqual(len(images), 4)

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_artist_search(self):
# Arrange
artist = "Nirvana"
Expand Down

0 comments on commit c3476c1

Please sign in to comment.