From 5f74bf4394350905bc4ded74d215d52308d32f47 Mon Sep 17 00:00:00 2001 From: Bootjewolf <35065763+Bootjewolf@users.noreply.github.com> Date: Tue, 15 Nov 2022 12:47:53 +0100 Subject: [PATCH 1/5] Added the remixer field from musicbrainz --- beets/autotag/mb.py | 16 ++++++++++++++++ beets/library.py | 1 + 2 files changed, 17 insertions(+) diff --git a/beets/autotag/mb.py b/beets/autotag/mb.py index 3bd7e8c817..4728b6f7c8 100644 --- a/beets/autotag/mb.py +++ b/beets/autotag/mb.py @@ -202,6 +202,19 @@ def _flatten_artist_credit(credit): ) +def _get_remixer_names(relations): + """ Given a list representing the artist relationships extract the names of + the remixers and concatenate them. + """ + remixers = [] + + for relation in relations: + if relation['type'] == 'remixer': + remixers.append(relation['artist']['name']) + + return ', '.join(remixers) + + def track_info(recording, index=None, medium=None, medium_index=None, medium_total=None): """Translates a MusicBrainz recording result dictionary into a beets @@ -231,6 +244,9 @@ def track_info(recording, index=None, medium=None, medium_index=None, artist = recording['artist-credit'][0]['artist'] info.artist_id = artist['id'] + if recording.get('artist-relation-list'): + info.remixer = _get_remixer_names(recording['artist-relation-list']) + if recording.get('length'): info.length = int(recording['length']) / (1000.0) diff --git a/beets/library.py b/beets/library.py index becf19390f..981563974d 100644 --- a/beets/library.py +++ b/beets/library.py @@ -466,6 +466,7 @@ class Item(LibModel): 'artist': types.STRING, 'artist_sort': types.STRING, 'artist_credit': types.STRING, + 'remixer': types.STRING, 'album': types.STRING, 'albumartist': types.STRING, 'albumartist_sort': types.STRING, From 4918ee64576475a6eadfdc0da95d42dbdf54afbc Mon Sep 17 00:00:00 2001 From: Bootjewolf <35065763+Bootjewolf@users.noreply.github.com> Date: Tue, 15 Nov 2022 17:42:34 +0100 Subject: [PATCH 2/5] Added test for the parsing of the remixer field --- test/test_mb.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/test/test_mb.py b/test/test_mb.py index 0b39d6ce4c..1ef8b256af 100644 --- a/test/test_mb.py +++ b/test/test_mb.py @@ -109,8 +109,8 @@ def _make_release(self, date_str='2009', tracks=None, track_length=None, }) return release - def _make_track(self, title, tr_id, duration, artist=False, video=False, - disambiguation=None): + def _make_track(self, title, tr_id, duration, artist=False, remixer=False, + video=False, disambiguation=None): track = { 'title': title, 'id': tr_id, @@ -128,6 +128,22 @@ def _make_track(self, title, tr_id, duration, artist=False, video=False, 'name': 'RECORDING ARTIST CREDIT', } ] + if remixer: + track['artist-relation-list'] = [ + { + 'type': 'remixer', + 'type-id': 'RELATION TYPE ID', + 'target': 'RECORDING REMIXER ARTIST ID', + 'direction': 'RECORDING RELATION DIRECTION', + 'artist': + { + 'id': 'RECORDING REMIXER ARTIST ID', + 'type': 'RECORDING REMIXER ARTIST TYPE', + 'name': 'RECORDING REMIXER ARTIST NAME', + 'sort-name': 'RECORDING REMIXER ARTIST SORT NAME' + } + } + ] if video: track['video'] = 'true' if disambiguation: @@ -339,6 +355,12 @@ def test_track_artist_overrides_recording_artist(self): self.assertEqual(track.artist_sort, 'TRACK ARTIST SORT NAME') self.assertEqual(track.artist_credit, 'TRACK ARTIST CREDIT') + def test_parse_recording_remixer(self): + tracks = [self._make_track('a', 'b', 1, remixer=True)] + release = self._make_release(None, tracks=tracks) + track = mb.album_info(release).tracks[0] + self.assertEqual(track.remixer, 'RECORDING REMIXER ARTIST NAME') + def test_data_source(self): release = self._make_release() d = mb.album_info(release) From ff22d3dc8988f4cf2ed764fc74c3b13198746034 Mon Sep 17 00:00:00 2001 From: Bootjewolf <35065763+Bootjewolf@users.noreply.github.com> Date: Tue, 15 Nov 2022 17:48:31 +0100 Subject: [PATCH 3/5] Added changelog entry --- docs/changelog.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index 646417f289..3703f422e6 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -8,6 +8,8 @@ Changelog goes here! New features: +* We now import the remixer field from Musicbrainz into the library. + :bug:`4428` * :doc:`/plugins/mbsubmit`: Added a new `mbsubmit` command to print track information to be submitted to MusicBrainz after initial import. :bug:`4455` * Added `spotify_updated` field to track when the information was last updated. From 1be6c22b4425987f979dbf04f3f8d8b9455c4bd0 Mon Sep 17 00:00:00 2001 From: Bootjewolf <35065763+Bootjewolf@users.noreply.github.com> Date: Sat, 19 Nov 2022 12:37:51 +0100 Subject: [PATCH 4/5] Generalise the function to get the names of related artists --- beets/autotag/mb.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/beets/autotag/mb.py b/beets/autotag/mb.py index 4728b6f7c8..5b8d451380 100644 --- a/beets/autotag/mb.py +++ b/beets/autotag/mb.py @@ -202,17 +202,17 @@ def _flatten_artist_credit(credit): ) -def _get_remixer_names(relations): - """ Given a list representing the artist relationships extract the names of +def _get_related_artist_names(relations, relation_type): + """Given a list representing the artist relationships extract the names of the remixers and concatenate them. """ - remixers = [] + related_artists = [] for relation in relations: - if relation['type'] == 'remixer': - remixers.append(relation['artist']['name']) + if relation['type'] == relation_type: + related_artists.append(relation['artist']['name']) - return ', '.join(remixers) + return ', '.join(related_artists) def track_info(recording, index=None, medium=None, medium_index=None, @@ -245,7 +245,10 @@ def track_info(recording, index=None, medium=None, medium_index=None, info.artist_id = artist['id'] if recording.get('artist-relation-list'): - info.remixer = _get_remixer_names(recording['artist-relation-list']) + info.remixer = _get_related_artist_names( + recording['artist-relation-list'], + relation_type='remixer' + ) if recording.get('length'): info.length = int(recording['length']) / (1000.0) From 2a282116bd04dbb6fe4cb93256bd6376d76712a9 Mon Sep 17 00:00:00 2001 From: Bootjewolf <35065763+Bootjewolf@users.noreply.github.com> Date: Sat, 19 Nov 2022 12:39:16 +0100 Subject: [PATCH 5/5] Reorder parameters of _make_track function and fix linting errors --- test/test_mb.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/test_mb.py b/test/test_mb.py index 1ef8b256af..f005c741a3 100644 --- a/test/test_mb.py +++ b/test/test_mb.py @@ -109,8 +109,8 @@ def _make_release(self, date_str='2009', tracks=None, track_length=None, }) return release - def _make_track(self, title, tr_id, duration, artist=False, remixer=False, - video=False, disambiguation=None): + def _make_track(self, title, tr_id, duration, artist=False, + video=False, disambiguation=None, remixer=False): track = { 'title': title, 'id': tr_id, @@ -135,7 +135,7 @@ def _make_track(self, title, tr_id, duration, artist=False, remixer=False, 'type-id': 'RELATION TYPE ID', 'target': 'RECORDING REMIXER ARTIST ID', 'direction': 'RECORDING RELATION DIRECTION', - 'artist': + 'artist': { 'id': 'RECORDING REMIXER ARTIST ID', 'type': 'RECORDING REMIXER ARTIST TYPE',