-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Add support for artists and albumartists multi-valued tags #4743
Merged
Merged
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
4d92a53
Attempt at multi artist + album artist support
jmbannon 5202734
multi start
jmbannon 1d7c671
tests passing
jmbannon f856a20
broken now?
jmbannon 3ad6031
missing s
jmbannon d133dbe
moar tests
jmbannon b3e2188
mediafile
jmbannon 4454e53
simplify delimiter format
jmbannon faaeb02
fix import
jmbannon 02e851c
super simplified
jmbannon 0d35e0b
artists
jmbannon 04b21c8
better type hinting
jmbannon 60cb7b2
more tests
jmbannon 9400885
write test
jmbannon bfa8e9b
id3v23 test
jmbannon 7074848
changelog, docs
jmbannon ffc05a0
manual linting ugh
jmbannon 457b0ec
Merge branch 'master' into j/multi
jmbannon e57798b
also write mb_artistids and mb_albumartistids
jmbannon 974a022
Merge branch 'master' into j/multi
jmbannon ab3ca88
python <=3.8 null char incompatibility
jmbannon 7051c80
Merge branch 'master' into j/multi
jmbannon 32deac0
more lint
jmbannon 5d4b248
Merge branch 'master' into j/multi
jmbannon 145b5f5
Merge branch 'master' into j/multi
jmbannon 04dda2a
Merge branch 'master' into j/multi
jmbannon d4e9ff2
apply albumartists to track
jmbannon eecdbb3
update autotag to use multis from albuminfo
jmbannon 56d1258
Merge branch 'master' into j/multi
jmbannon d9cc1e5
missing s in artists_credits
jmbannon 2dadf0d
Merge branch 'master' into j/multi
jmbannon e277bb5
Merge branch 'master' into j/multi
jmbannon 18a48cc
album/artists_credits -> album/artists_credit
jmbannon e2bcf30
Merge branch 'master' into j/multi
jmbannon 0d8d59b
lint
jmbannon d836f78
require higher mediafile for multi-tags
jmbannon f569c07
remove debug code
jmbannon b63e0a7
lint
jmbannon 195f1fe
Merge branch 'master' into j/multi
jmbannon 4f58b03
Merge branch 'master' into j/multi
jmbannon 6ff82d0
Merge branch 'master' into j/multi
JOJ0 0242a06
Move #4743 changelog entry to bottom of list
JOJ0 bc8b467
Fix query docs wording for multi-valued tags searches
JOJ0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,15 +74,19 @@ def __init__( | |
album_id: Optional[str] = None, | ||
artist: Optional[str] = None, | ||
artist_id: Optional[str] = None, | ||
artists: Optional[List[str]] = None, | ||
artists_ids: Optional[List[str]] = None, | ||
asin: Optional[str] = None, | ||
albumtype: Optional[str] = None, | ||
albumtypes: Optional[List[str]] = None, | ||
va: bool = False, | ||
year: Optional[int] = None, | ||
month: Optional[int] = None, | ||
day: Optional[int] = None, | ||
label: Optional[str] = None, | ||
mediums: Optional[int] = None, | ||
artist_sort: Optional[str] = None, | ||
artists_sort: Optional[List[str]] = None, | ||
releasegroup_id: Optional[str] = None, | ||
release_group_title: Optional[str] = None, | ||
catalognum: Optional[str] = None, | ||
|
@@ -96,6 +100,7 @@ def __init__( | |
albumdisambig: Optional[str] = None, | ||
releasegroupdisambig: Optional[str] = None, | ||
artist_credit: Optional[str] = None, | ||
artists_credit: Optional[List[str]] = None, | ||
original_year: Optional[int] = None, | ||
original_month: Optional[int] = None, | ||
original_day: Optional[int] = None, | ||
|
@@ -110,16 +115,20 @@ def __init__( | |
self.album_id = album_id | ||
self.artist = artist | ||
self.artist_id = artist_id | ||
self.artists = artists or [] | ||
self.artists_ids = artists_ids or [] | ||
self.tracks = tracks | ||
self.asin = asin | ||
self.albumtype = albumtype | ||
self.albumtypes = albumtypes or [] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was missing from the other PR |
||
self.va = va | ||
self.year = year | ||
self.month = month | ||
self.day = day | ||
self.label = label | ||
self.mediums = mediums | ||
self.artist_sort = artist_sort | ||
self.artists_sort = artists_sort or [] | ||
self.releasegroup_id = releasegroup_id | ||
self.release_group_title = release_group_title | ||
self.catalognum = catalognum | ||
|
@@ -133,6 +142,7 @@ def __init__( | |
self.albumdisambig = albumdisambig | ||
self.releasegroupdisambig = releasegroupdisambig | ||
self.artist_credit = artist_credit | ||
self.artists_credit = artists_credit or [] | ||
self.original_year = original_year | ||
self.original_month = original_month | ||
self.original_day = original_day | ||
|
@@ -190,14 +200,18 @@ def __init__( | |
release_track_id: Optional[str] = None, | ||
artist: Optional[str] = None, | ||
artist_id: Optional[str] = None, | ||
artists: Optional[List[str]] = None, | ||
artists_ids: Optional[List[str]] = None, | ||
length: Optional[float] = None, | ||
index: Optional[int] = None, | ||
medium: Optional[int] = None, | ||
medium_index: Optional[int] = None, | ||
medium_total: Optional[int] = None, | ||
artist_sort: Optional[str] = None, | ||
artists_sort: Optional[List[str]] = None, | ||
disctitle: Optional[str] = None, | ||
artist_credit: Optional[str] = None, | ||
artists_credit: Optional[List[str]] = None, | ||
data_source: Optional[str] = None, | ||
data_url: Optional[str] = None, | ||
media: Optional[str] = None, | ||
|
@@ -220,15 +234,19 @@ def __init__( | |
self.release_track_id = release_track_id | ||
self.artist = artist | ||
self.artist_id = artist_id | ||
self.artists = artists or [] | ||
self.artists_ids = artists_ids or [] | ||
self.length = length | ||
self.index = index | ||
self.media = media | ||
self.medium = medium | ||
self.medium_index = medium_index | ||
self.medium_total = medium_total | ||
self.artist_sort = artist_sort | ||
self.artists_sort = artists_sort or [] | ||
self.disctitle = disctitle | ||
self.artist_credit = artist_credit | ||
self.artists_credit = artists_credit or [] | ||
self.data_source = data_source | ||
self.data_url = data_url | ||
self.lyricist = lyricist | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ | |
from beets import config | ||
from collections import Counter | ||
from urllib.parse import urljoin | ||
|
||
from beets.util.id_extractors import extract_discogs_id_regex, \ | ||
spotify_id_regex, deezer_id_regex, beatport_id_regex | ||
from beets.plugins import MetadataSourcePlugin | ||
|
@@ -166,9 +167,11 @@ def _preferred_release_event(release: Dict[str, Any]) -> Tuple[str, str]: | |
) | ||
|
||
|
||
def _flatten_artist_credit(credit: List[Dict]) -> Tuple[str, str, str]: | ||
"""Given a list representing an ``artist-credit`` block, flatten the | ||
data into a triple of joined artist name strings: canonical, sort, and | ||
def _multi_artist_credit( | ||
credit: List[Dict], include_join_phrase: bool | ||
) -> Tuple[List[str], List[str], List[str]]: | ||
"""Given a list representing an ``artist-credit`` block, accumulate | ||
data into a triple of joined artist name lists: canonical, sort, and | ||
credit. | ||
""" | ||
artist_parts = [] | ||
|
@@ -177,9 +180,10 @@ def _flatten_artist_credit(credit: List[Dict]) -> Tuple[str, str, str]: | |
for el in credit: | ||
if isinstance(el, str): | ||
# Join phrase. | ||
artist_parts.append(el) | ||
artist_credit_parts.append(el) | ||
artist_sort_parts.append(el) | ||
if include_join_phrase: | ||
artist_parts.append(el) | ||
artist_credit_parts.append(el) | ||
artist_sort_parts.append(el) | ||
|
||
else: | ||
alias = _preferred_alias(el['artist'].get('alias-list', ())) | ||
|
@@ -205,13 +209,43 @@ def _flatten_artist_credit(credit: List[Dict]) -> Tuple[str, str, str]: | |
else: | ||
artist_credit_parts.append(cur_artist_name) | ||
|
||
return ( | ||
artist_parts, | ||
artist_sort_parts, | ||
artist_credit_parts, | ||
) | ||
|
||
|
||
def _flatten_artist_credit(credit: List[Dict]) -> Tuple[str, str, str]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Really nice work on this refactoring. Clever and also simple! |
||
"""Given a list representing an ``artist-credit`` block, flatten the | ||
data into a triple of joined artist name strings: canonical, sort, and | ||
credit. | ||
""" | ||
artist_parts, artist_sort_parts, artist_credit_parts = \ | ||
_multi_artist_credit( | ||
credit, | ||
include_join_phrase=True | ||
) | ||
return ( | ||
''.join(artist_parts), | ||
''.join(artist_sort_parts), | ||
''.join(artist_credit_parts), | ||
) | ||
|
||
|
||
def _artist_ids(credit: List[Dict]) -> List[str]: | ||
""" | ||
Given a list representing an ``artist-credit``, | ||
return a list of artist IDs | ||
""" | ||
artist_ids: List[str] = [] | ||
for el in credit: | ||
if isinstance(el, dict): | ||
artist_ids.append(el['artist']['id']) | ||
|
||
return artist_ids | ||
|
||
|
||
def _get_related_artist_names(relations, relation_type): | ||
"""Given a list representing the artist relationships extract the names of | ||
the remixers and concatenate them. | ||
|
@@ -255,9 +289,13 @@ def track_info( | |
info.artist, info.artist_sort, info.artist_credit = \ | ||
_flatten_artist_credit(recording['artist-credit']) | ||
|
||
# Get the ID and sort name of the first artist. | ||
artist = recording['artist-credit'][0]['artist'] | ||
info.artist_id = artist['id'] | ||
info.artists, info.artists_sort, info.artists_credit = \ | ||
_multi_artist_credit( | ||
recording['artist-credit'], include_join_phrase=False | ||
) | ||
|
||
info.artists_ids = _artist_ids(recording['artist-credit']) | ||
info.artist_id = info.artists_ids[0] | ||
|
||
if recording.get('artist-relation-list'): | ||
info.remixer = _get_related_artist_names( | ||
|
@@ -350,6 +388,11 @@ def album_info(release: Dict) -> beets.autotag.hooks.AlbumInfo: | |
artist_name, artist_sort_name, artist_credit_name = \ | ||
_flatten_artist_credit(release['artist-credit']) | ||
|
||
artists_names, artists_sort_names, artists_credit_names = \ | ||
_multi_artist_credit( | ||
release['artist-credit'], include_join_phrase=False | ||
) | ||
|
||
ntracks = sum(len(m['track-list']) for m in release['medium-list']) | ||
|
||
# The MusicBrainz API omits 'artist-relation-list' and 'work-relation-list' | ||
|
@@ -421,21 +464,33 @@ def album_info(release: Dict) -> beets.autotag.hooks.AlbumInfo: | |
# Get the artist names. | ||
ti.artist, ti.artist_sort, ti.artist_credit = \ | ||
_flatten_artist_credit(track['artist-credit']) | ||
ti.artist_id = track['artist-credit'][0]['artist']['id'] | ||
|
||
ti.artists, ti.artists_sort, ti.artists_credit = \ | ||
_multi_artist_credit( | ||
track['artist-credit'], include_join_phrase=False | ||
) | ||
|
||
ti.artists_ids = _artist_ids(track['artist-credit']) | ||
ti.artist_id = ti.artists_ids[0] | ||
if track.get('length'): | ||
ti.length = int(track['length']) / (1000.0) | ||
|
||
track_infos.append(ti) | ||
|
||
album_artist_ids = _artist_ids(release['artist-credit']) | ||
info = beets.autotag.hooks.AlbumInfo( | ||
album=release['title'], | ||
album_id=release['id'], | ||
artist=artist_name, | ||
artist_id=release['artist-credit'][0]['artist']['id'], | ||
artist_id=album_artist_ids[0], | ||
artists=artists_names, | ||
artists_ids=album_artist_ids, | ||
tracks=track_infos, | ||
mediums=len(release['medium-list']), | ||
artist_sort=artist_sort_name, | ||
artists_sort=artists_sort_names, | ||
artist_credit=artist_credit_name, | ||
artists_credit=artists_credit_names, | ||
data_source='MusicBrainz', | ||
data_url=album_url(release['id']), | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, we've been gradually moving away from listing each field exhaustively in
AlbumInfo
/TrackInfo
and instead just relying on**kwargs
to convey all the information we need. But no big deal if it's easier to grok with these fields listed explicitly here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As boiler-plate as it is, I prefer it lol. For me, it helps to know which native field types are expected