|
24 | 24 |
|
25 | 25 | import codecs |
26 | 26 | import os |
| 27 | +import re |
27 | 28 | import traceback |
28 | 29 | from typing import Union |
29 | 30 |
|
@@ -290,6 +291,15 @@ def fetch_album_artist_genre(self, obj): |
290 | 291 | """Return raw album artist genres from Last.fm for this Item or Album.""" |
291 | 292 | return self._last_lookup("artist", LASTFM.get_artist, obj.albumartist) |
292 | 293 |
|
| 294 | + def fetch_split_album_artist_genre(self, split_artist): |
| 295 | + """Return the artist genre for any passed artist name. |
| 296 | +
|
| 297 | + Used for multi-artist albums where the artist name may not match |
| 298 | + the album artist exactly and a split by separator is needed to get a last.fm |
| 299 | + result. |
| 300 | + """ |
| 301 | + return self._last_lookup("artist", LASTFM.get_artist, split_artist) |
| 302 | + |
293 | 303 | def fetch_artist_genre(self, item): |
294 | 304 | """Returns raw track artist genres from Last.fm for this Item.""" |
295 | 305 | return self._last_lookup("artist", LASTFM.get_artist, item.artist) |
@@ -408,6 +418,47 @@ def _try_resolve_stage(stage_label: str, keep_genres, new_genres): |
408 | 418 | elif obj.albumartist != config["va_name"].as_str(): |
409 | 419 | new_genres = self.fetch_album_artist_genre(obj) |
410 | 420 | stage_label = "album artist" |
| 421 | + if not new_genres: |
| 422 | + if self.config["extended_debug"]: |
| 423 | + self._log.debug( |
| 424 | + 'No album artist genre found for "{0.albumartist}"', |
| 425 | + obj, |
| 426 | + ) |
| 427 | + separators = [ |
| 428 | + re.escape(self.config["separator"].get()), |
| 429 | + " feat\\. ", |
| 430 | + " featuring ", |
| 431 | + " & ", |
| 432 | + " vs\\. ", |
| 433 | + " x ", |
| 434 | + " / ", |
| 435 | + " + ", |
| 436 | + " and ", |
| 437 | + " \\| ", |
| 438 | + ] |
| 439 | + if any( |
| 440 | + re.sub(r"\\", "", sep) in obj.albumartist |
| 441 | + for sep in separators |
| 442 | + ): |
| 443 | + if self.config["extended_debug"]: |
| 444 | + self._log.debug( |
| 445 | + "Found separators in album artist - splitting..." |
| 446 | + ) |
| 447 | + # Split on all separators using regex |
| 448 | + pattern = "|".join(separators) |
| 449 | + albumartists = re.split(pattern, obj.albumartist) |
| 450 | + for albumartist in albumartists: |
| 451 | + albumartist = albumartist.strip() |
| 452 | + if self.config["extended_debug"]: |
| 453 | + self._log.debug( |
| 454 | + 'Fetching multi-artist album genre for "{0}"', |
| 455 | + albumartist, |
| 456 | + ) |
| 457 | + new_genres += self.fetch_split_album_artist_genre( |
| 458 | + albumartist |
| 459 | + ) |
| 460 | + if new_genres: |
| 461 | + label = "album artist (split)" |
411 | 462 | else: |
412 | 463 | # For "Various Artists", pick the most popular track genre. |
413 | 464 | item_genres = [] |
|
0 commit comments