Skip to content

Commit

Permalink
fix: musicbrainz error if a release has no label
Browse files Browse the repository at this point in the history
  • Loading branch information
jtpavlock committed Oct 8, 2022
1 parent fcaaaa8 commit 6991a41
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion moe/plugins/musicbrainz/mb_core.py
Expand Up @@ -384,12 +384,17 @@ def _create_album(release: dict) -> Album:
"""Creates an album from a given musicbrainz release."""
log.debug(f"Creating album from musicbrainz release. [release={release['id']!r}]")

if release["label-info-list"]:
label = release["label-info-list"][0]["label"]["name"]
else:
label = None

album = Album(
artist=_flatten_artist_credit(release["artist-credit"]),
country=release.get("country"),
date=_parse_date(release["date"]),
disc_total=int(release["medium-count"]),
label=release["label-info-list"][0]["label"]["name"],
label=label,
mb_album_id=release["id"],
media=release["medium-list"][0]["format"],
original_date=_parse_date(release["release-group"]["first-release-date"]),
Expand Down
9 changes: 9 additions & 0 deletions tests/plugins/musicbrainz/test_mb_core.py
Expand Up @@ -423,6 +423,15 @@ def test_no_country(self, mock_mb_by_id, mb_config):

moe_mb.get_album_by_id(mb_album_id)

def test_no_label(self, mock_mb_by_id, mb_config):
"""Don't error if no label in the release."""
mb_album_id = "112dec42-65f2-3bde-8d7d-26deddde10b2"
release = copy.deepcopy(mb_rsrc.full_release.release)
release["release"]["label-info-list"].clear()
mock_mb_by_id.return_value = release

moe_mb.get_album_by_id(mb_album_id)


class TestGetTrackByID:
"""Test `get_track_by_id`."""
Expand Down

0 comments on commit 6991a41

Please sign in to comment.