41
41
42
42
from beets .library import Item
43
43
44
+ from ._typing import JSONDict
45
+
44
46
VARIOUS_ARTISTS_ID = "89ad4ac3-39f7-470e-963a-56509c546377"
45
47
46
48
BASE_URL = "https://musicbrainz.org/"
@@ -121,7 +123,7 @@ def get_message(self):
121
123
BROWSE_MAXTRACKS = 500
122
124
123
125
124
- def _preferred_alias (aliases : list ):
126
+ def _preferred_alias (aliases : list [ JSONDict ] ):
125
127
"""Given an list of alias structures for an artist credit, select
126
128
and return the user's preferred alias alias or None if no matching
127
129
alias is found.
@@ -130,7 +132,7 @@ def _preferred_alias(aliases: list):
130
132
return
131
133
132
134
# Only consider aliases that have locales set.
133
- aliases = [a for a in aliases if "locale" in a ]
135
+ valid_aliases = [a for a in aliases if "locale" in a ]
134
136
135
137
# Get any ignored alias types and lower case them to prevent case issues
136
138
ignored_alias_types = config ["import" ]["ignored_alias_types" ].as_str_seq ()
@@ -141,13 +143,13 @@ def _preferred_alias(aliases: list):
141
143
# Find matching primary aliases for this locale that are not
142
144
# being ignored
143
145
matches = []
144
- for a in aliases :
146
+ for alias in valid_aliases :
145
147
if (
146
- a ["locale" ] == locale
147
- and "primary" in a
148
- and a .get ("type" , "" ).lower () not in ignored_alias_types
148
+ alias ["locale" ] == locale
149
+ and "primary" in alias
150
+ and alias .get ("type" , "" ).lower () not in ignored_alias_types
149
151
):
150
- matches .append (a )
152
+ matches .append (alias )
151
153
152
154
# Skip to the next locale if we have no matches
153
155
if not matches :
@@ -157,7 +159,7 @@ def _preferred_alias(aliases: list):
157
159
158
160
159
161
def _multi_artist_credit (
160
- credit : list [dict ], include_join_phrase : bool
162
+ credit : list [JSONDict ], include_join_phrase : bool
161
163
) -> tuple [list [str ], list [str ], list [str ]]:
162
164
"""Given a list representing an ``artist-credit`` block, accumulate
163
165
data into a triple of joined artist name lists: canonical, sort, and
@@ -209,7 +211,7 @@ def track_url(trackid: str) -> str:
209
211
return urljoin (BASE_URL , "recording/" + trackid )
210
212
211
213
212
- def _flatten_artist_credit (credit : list [dict ]) -> tuple [str , str , str ]:
214
+ def _flatten_artist_credit (credit : list [JSONDict ]) -> tuple [str , str , str ]:
213
215
"""Given a list representing an ``artist-credit`` block, flatten the
214
216
data into a triple of joined artist name strings: canonical, sort, and
215
217
credit.
@@ -224,7 +226,7 @@ def _flatten_artist_credit(credit: list[dict]) -> tuple[str, str, str]:
224
226
)
225
227
226
228
227
- def _artist_ids (credit : list [dict ]) -> list [str ]:
229
+ def _artist_ids (credit : list [JSONDict ]) -> list [str ]:
228
230
"""
229
231
Given a list representing an ``artist-credit``,
230
232
return a list of artist IDs
@@ -317,8 +319,8 @@ def _is_translation(r):
317
319
318
320
319
321
def _find_actual_release_from_pseudo_release (
320
- pseudo_rel : dict ,
321
- ) -> dict | None :
322
+ pseudo_rel : JSONDict ,
323
+ ) -> JSONDict | None :
322
324
try :
323
325
relations = pseudo_rel ["release" ]["release-relation-list" ]
324
326
except KeyError :
@@ -414,7 +416,7 @@ def __init__(self):
414
416
415
417
def track_info (
416
418
self ,
417
- recording : dict ,
419
+ recording : JSONDict ,
418
420
index : int | None = None ,
419
421
medium : int | None = None ,
420
422
medium_index : int | None = None ,
@@ -515,7 +517,7 @@ def track_info(
515
517
516
518
return info
517
519
518
- def album_info (self , release : dict ) -> beets .autotag .hooks .AlbumInfo :
520
+ def album_info (self , release : JSONDict ) -> beets .autotag .hooks .AlbumInfo :
519
521
"""Takes a MusicBrainz release result dictionary and returns a beets
520
522
AlbumInfo object containing the interesting data about that release.
521
523
"""
0 commit comments