Album.get_top_tracks now returns TopItems. Closes #86.
This commit is contained in:
parent
e388db1e2f
commit
44318fccc4
15
pylast.py
15
pylast.py
|
@ -1282,21 +1282,6 @@ class Album(_BaseObject, _Taggable):
|
||||||
|
|
||||||
return _number(_extract(self._request("album.getInfo", cacheable = True), "listeners"))
|
return _number(_extract(self._request("album.getInfo", cacheable = True), "listeners"))
|
||||||
|
|
||||||
def get_top_tags(self, limit=None):
|
|
||||||
"""Returns a list of the most-applied tags to this album."""
|
|
||||||
|
|
||||||
doc = self._request("album.getInfo", True)
|
|
||||||
e = doc.getElementsByTagName("toptags")[0]
|
|
||||||
|
|
||||||
seq = []
|
|
||||||
for name in _extract_all(e, "name"):
|
|
||||||
seq.append(Tag(name, self.network))
|
|
||||||
|
|
||||||
if limit:
|
|
||||||
seq = seq[:limit]
|
|
||||||
|
|
||||||
return seq
|
|
||||||
|
|
||||||
def get_tracks(self):
|
def get_tracks(self):
|
||||||
"""Returns the list of Tracks on this album."""
|
"""Returns the list of Tracks on this album."""
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,7 @@ class TestPyLast(unittest.TestCase):
|
||||||
artist = "Test Artist 2"
|
artist = "Test Artist 2"
|
||||||
title = "Test Title 2"
|
title = "Test Title 2"
|
||||||
timestamp = self.unix_timestamp()
|
timestamp = self.unix_timestamp()
|
||||||
|
print timestamp
|
||||||
library = pylast.Library(user = self.username, network = self.network)
|
library = pylast.Library(user = self.username, network = self.network)
|
||||||
self.network.scrobble(artist = artist, title = title, timestamp = timestamp)
|
self.network.scrobble(artist = artist, title = title, timestamp = timestamp)
|
||||||
lastfm_user = self.network.get_user(self.username)
|
lastfm_user = self.network.get_user(self.username)
|
||||||
|
@ -325,10 +326,21 @@ class TestPyLast(unittest.TestCase):
|
||||||
|
|
||||||
# Act
|
# Act
|
||||||
network = pylast.LibreFMNetwork(password_hash = password_hash, username = username)
|
network = pylast.LibreFMNetwork(password_hash = password_hash, username = username)
|
||||||
tags = network.get_top_tags()
|
tags = network.get_top_tags(limit = 1)
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
self.assertGreater(len(tags), 0)
|
||||||
|
self.assertTrue(type(tags[0]) == pylast.TopItem)
|
||||||
|
|
||||||
|
|
||||||
|
def test_album_tags_are_topitems(self):
|
||||||
|
# Arrange
|
||||||
|
albums = self.network.get_user('RJ').get_top_albums()
|
||||||
|
|
||||||
|
# Act
|
||||||
|
tags = albums[0].item.get_top_tags(limit = 1)
|
||||||
|
|
||||||
# Assert
|
# Assert
|
||||||
print len(tags)
|
|
||||||
self.assertGreater(len(tags), 0)
|
self.assertGreater(len(tags), 0)
|
||||||
self.assertTrue(type(tags[0]) == pylast.TopItem)
|
self.assertTrue(type(tags[0]) == pylast.TopItem)
|
||||||
|
|
||||||
|
@ -336,7 +348,8 @@ class TestPyLast(unittest.TestCase):
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
# suite = unittest.TestSuite()
|
# suite = unittest.TestSuite()
|
||||||
# suite.addTest(TestPyLast('test_libre_fm'))
|
# suite.addTest(TestPyLast('test_scrobble'))
|
||||||
|
# suite.addTest(TestPyLast('test_unscrobble'))
|
||||||
# unittest.TextTestRunner().run(suite)
|
# unittest.TextTestRunner().run(suite)
|
||||||
|
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
Loading…
Reference in a new issue