@@ -236,6 +236,13 @@ def _add_candidate(
236236 )
237237
238238
239+ def _parse_search_terms (
240+ * pairs : tuple [str | None , str ],
241+ ) -> tuple [str , ...]:
242+ """Determine the search terms to use, falling back to current values."""
243+ return tuple (term or current for term , current in pairs )
244+
245+
239246def tag_album (
240247 items ,
241248 search_artist : str | None = None ,
@@ -295,22 +302,23 @@ def tag_album(
295302 )
296303
297304 # Search terms.
298- if not (search_artist and search_album ):
299- # No explicit search terms -- use current metadata.
300- search_artist , search_album = cur_artist , cur_album
301- log .debug ("Search terms: {} - {}" , search_artist , search_album )
305+ _search_artist , _search_album = _parse_search_terms (
306+ (search_artist , cur_artist ),
307+ (search_album , cur_album ),
308+ )
309+ log .debug ("Search terms: {} - {}" , _search_artist , _search_album )
302310
303311 # Is this album likely to be a "various artist" release?
304312 va_likely = (
305313 (not consensus ["artist" ])
306- or (search_artist .lower () in VA_ARTISTS )
314+ or (_search_artist .lower () in VA_ARTISTS )
307315 or any (item .comp for item in items )
308316 )
309317 log .debug ("Album might be VA: {}" , va_likely )
310318
311319 # Get the results from the data sources.
312320 for matched_candidate in metadata_plugins .candidates (
313- items , search_artist , search_album , va_likely
321+ items , _search_artist , _search_album , va_likely
314322 ):
315323 _add_candidate (items , candidates , matched_candidate )
316324
@@ -322,7 +330,7 @@ def tag_album(
322330
323331
324332def tag_item (
325- item ,
333+ item : Item ,
326334 search_artist : str | None = None ,
327335 search_title : str | None = None ,
328336 search_ids : list [str ] | None = None ,
@@ -365,13 +373,17 @@ def tag_item(
365373 return Proposal ([], Recommendation .none )
366374
367375 # Search terms.
368- search_artist = search_artist or item .artist
369- search_title = search_title or item .title
370- log .debug ("Item search terms: {} - {}" , search_artist , search_title )
376+ _search_artist , _search_title = _parse_search_terms (
377+ (search_artist , item .artist ),
378+ (search_title , item .title ),
379+ )
380+ log .debug ("Item search terms: {} - {}" , _search_artist , _search_title )
371381
372382 # Get and evaluate candidate metadata.
373383 for track_info in metadata_plugins .item_candidates (
374- item , search_artist , search_title
384+ item ,
385+ _search_artist ,
386+ _search_title ,
375387 ):
376388 dist = track_distance (item , track_info , incl_artist = True )
377389 candidates [track_info .track_id ] = hooks .TrackMatch (dist , track_info )
0 commit comments