Merge pull request #149 from hugovk/mbid_fix
Only get the top-level <mbid>
This commit is contained in:
commit
9924500108
|
@ -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):
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in a new issue