From f090876c0aa3c8641f79d9acd10f5fa578eaed0f Mon Sep 17 00:00:00 2001 From: hugovk Date: Mon, 7 Sep 2015 23:57:36 +0300 Subject: [PATCH] Fix for #146: only get the top-level --- pylast/__init__.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/pylast/__init__.py b/pylast/__init__.py index 4382337..4c5e28f 100644 --- a/pylast/__init__.py +++ b/pylast/__init__.py @@ -1809,8 +1809,21 @@ class _Opus(_BaseObject, _Taggable): def get_mbid(self): """Returns the MusicBrainz ID of the album or track.""" - return _extract( - self._request(self.ws_prefix + ".getInfo", cacheable=True), "mbid") + doc = self._request(self.ws_prefix + ".getInfo", cacheable=True) + + 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):