Compare commits

...

3 commits

2 changed files with 15 additions and 3 deletions

View file

@ -1592,7 +1592,12 @@ class _Opus(_BaseObject, _Taggable):
def get_mbid(self):
"""Returns the MusicBrainz ID of the album or track."""
doc = self._request(self.ws_prefix + ".getInfo", cacheable=True)
try:
doc = self._request(self.ws_prefix + ".getInfo", cacheable=True)
except WSError as e:
if int(e.get_id()) == STATUS_INVALID_PARAMS and str(e) == "Track not found":
return None
raise
try:
lfm = doc.getElementsByTagName("lfm")[0]

View file

@ -241,9 +241,16 @@ class TestPyLastTrack(TestPyLastWithLastFm):
# Assert
assert corrected_track_name == "Mr. Brownstone"
def test_track_with_no_mbid(self):
@pytest.mark.parametrize(
("test_artist", "test_track"),
[
("Static-X", "Set It Off"), # Track with no MBID
("Zytaris", "Shores of Life"), # "Track not found"
],
)
def test_track_with_no_mbid(self, test_artist, test_track):
# Arrange
track = pylast.Track("Static-X", "Set It Off", self.network)
track = pylast.Track(test_track, test_artist, self.network)
# Act
mbid = track.get_mbid()