Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix MBID Mapping Lookup element #129

Merged
merged 2 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions tests/musicbrainz/test_mbid_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"recording_name": "Trigger Hippie",
"release_mbid": "9db51cd6-38f6-3b42-8ad5-559963d68f35",
"release_name": "Who Can You Trust?",
"year": 1996
"artist_mbids": ["067102ea-9519-4622-9077-57ca4164cfbb"]
}
]

Expand Down Expand Up @@ -51,12 +51,11 @@ def test_read(self, req):
assert len(entities) == 1
assert entities[0].artist.artist_credit_id == 963
assert entities[0].artist.name == "Morcheeba"
assert entities[0].artist.mbids == ["067102ea-9519-4622-9077-57ca4164cfbb"]
assert entities[0].release.mbid == "9db51cd6-38f6-3b42-8ad5-559963d68f35"
assert entities[0].release.name == "Who Can You Trust?"
assert entities[0].mbid == "97e69767-5d34-4c97-b36a-f3b2b1ef9dae"
assert entities[0].name == "Trigger Hippie"
assert entities[0].year == 1996


@unittest.mock.patch('requests.post')
def test_read_remove_unmatched(self, req):
Expand Down
19 changes: 12 additions & 7 deletions troi/musicbrainz/mbid_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ def read(self, inputs):
params = []
for r in inputs[0]:
if r.artist is not None and r.name is not None:
params.append({"[artist_credit_name]": r.artist.name,
"[recording_name]": r.name})
params.append({"[artist_credit_name]": r.artist.name, "[recording_name]": r.name})

if not params:
return []
Expand All @@ -51,22 +50,28 @@ def read(self, inputs):
continue

if r.mbid:
r.add_note("recording mbid %s overwritten by mbid_lookup" % (r.mbid))
r.add_note("recording mbid %s overwritten by mbid_lookup" % (r.mbid,))
r.mbid = row['recording_mbid']
r.name = row['recording_name']
r.year = row['year']

if r.artist is None:
r.artist = Artist(artist_credit_id=row['artist_credit_id'], name=row['artist_credit_name'])
r.artist = Artist(
artist_credit_id=row['artist_credit_id'],
name=row['artist_credit_name'],
mbids=row['artist_mbids']
)
else:
if r.artist.artist_credit_id:
r.artist.add_note("artist_credit_id %d overwritten by mbid_lookup" % (r.artist.artist_credit_id))
r.artist.add_note("artist_credit_id %d overwritten by mbid_lookup" % (r.artist.artist_credit_id,))
if r.artist.mbids:
r.artist.add_note("mbids %s overwritten by mbid_lookup" % (r.artist.mbids,))
r.artist.artist_credit_id = row['artist_credit_id']
r.artist.name = row['artist_credit_name']
r.artist.mbids = row['artist_mbids']

if r.release:
if r.release.mbid:
r.release.add_note("mbid %d overwritten by mbid_lookup" % (r.release.mbid))
r.release.add_note("mbid %d overwritten by mbid_lookup" % (r.release.mbid,))
r.release.mbid = row['release_mbid']
r.release.name = row['release_name']
else:
Expand Down
Loading