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