Merge remote-tracking branch 'upstream/develop' into develop

This commit is contained in:
hugovk 2015-12-10 00:42:11 +02:00
commit 6ecba676bc
2 changed files with 28 additions and 5 deletions

View file

@ -1809,8 +1809,21 @@ class _Opus(_BaseObject, _Taggable):
def get_mbid(self): def get_mbid(self):
"""Returns the MusicBrainz ID of the album or track.""" """Returns the MusicBrainz ID of the album or track."""
return _extract( doc = self._request(self.ws_prefix + ".getInfo", cacheable=True)
self._request(self.ws_prefix + ".getInfo", cacheable=True), "mbid")
try:
lfm = doc.getElementsByTagName('lfm')[0]
opus = self._get_children_by_tag_name(lfm, self.ws_prefix).next()
mbid = self._get_children_by_tag_name(opus, "mbid").next()
return mbid.firstChild.nodeValue
except StopIteration:
return None
def _get_children_by_tag_name(self, node, tag_name):
for child in node.childNodes:
if (child.nodeType == child.ELEMENT_NODE and
(tag_name == '*' or child.tagName == tag_name)):
yield child
class Album(_Opus): class Album(_Opus):
@ -1844,9 +1857,9 @@ class Album(_Opus):
def get_tracks(self): def get_tracks(self):
"""Returns the list of Tracks on this album.""" """Returns the list of Tracks on this album."""
uri = 'lastfm://playlist/album/%s' % self.get_id() return _extract_tracks(
self._request(
return XSPF(uri, self.network).get_tracks() self.ws_prefix + ".getInfo", cacheable=True), "tracks")
def get_url(self, domain_name=DOMAIN_ENGLISH): def get_url(self, domain_name=DOMAIN_ENGLISH):
"""Returns the URL of the album or track page on the network. """Returns the URL of the album or track page on the network.

View file

@ -1972,5 +1972,15 @@ class TestPyLast(unittest.TestCase):
# Assert # Assert
self.assertEqual(corrected_track_name, "Mr. Brownstone") self.assertEqual(corrected_track_name, "Mr. Brownstone")
def test_track_with_no_mbid(self):
# Arrange
track = pylast.Track("Static-X", "Set It Off", self.network)
# Act
mbid = track.get_mbid()
# Assert
self.assertEqual(mbid, None)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main(failfast=True) unittest.main(failfast=True)