- arts = {trk.artist for trk in album_trks}
- # Avoid selecting album where artist is credited for a single
- # track of the album
- if len(set(arts)) < 2: # TODO: better heuristic, use a ratio instead
- if album not in albums:
- albums.append(Album(name=album, **kwalbart))
- elif album and album not in albums:
- self.log.debug('"{0}" probably not an album of "{1}"'.format(
- album, artist) + '({0})'.format('/'.join(arts)))
- return albums
+ albums.add(Album(album_name[0], artist=artist.name,
+ Artist=artist, mbid=albumid))
+ for name_sz in artist.names_sz:
+ mpd_filter = f"((albumartist == '{name_sz}') AND ( album != ''))"
+ raw_albums = self.list('album', mpd_filter)
+ for alb in raw_albums:
+ if alb in [a.name for a in albums]:
+ continue
+ mbid = None
+ if self.use_mbid:
+ _ = Album(alb)
+ mpd_filter = f"((albumartist == '{artist.name_sz}') AND ( album == '{_.name_sz}'))"
+ mbids = self.list('MUSICBRAINZ_ALBUMID', mpd_filter)
+ if mbids:
+ mbid = mbids[0]
+ albums.add(Album(alb, artist=artist.name,
+ Artist=artist, mbid=mbid))
+ candidates = []
+ for album in albums:
+ album_trks = self.find_tracks(album)
+ if not album_trks: # find_track result can be empty, blocklist applied
+ continue
+ album_artists = {tr.albumartist for tr in album_trks if tr.albumartist}
+ if album.Artist.names & album_artists:
+ candidates.append(album)
+ continue
+ if self.use_mbid and artist.mbid:
+ if artist.mbid == album_trks[0].musicbrainz_albumartistid:
+ candidates.append(album)
+ continue
+ self.log.debug('Discarding "%s", "%r" not set as musicbrainz_albumartistid',
+ album, album.Artist)
+ continue
+ if 'Various Artists' in album_artists:
+ self.log.debug('Discarding %s ("Various Artists" set)', album)
+ continue
+ if album_artists and album.Artist.name not in album_artists:
+ self.log.debug('Discarding "%s", "%s" not set as albumartist', album, album.Artist)
+ continue
+ # Attempt to detect false positive (especially when no
+ # AlbumArtist/MBIDs tag ar set)
+ # Avoid selecting albums where artist is credited for a single
+ # track of the album
+ album_trks = self.find(f"(album == '{album.name_sz}')")
+ arts = [trk.artist for trk in album_trks] # Artists in the album
+ # count artist occurences
+ ratio = arts.count(album.Artist.name)/len(arts)
+ if ratio >= 0.8:
+ candidates.append(album)
+ else:
+ self.log.debug('"%s" probably not an album of "%s" (ratio=%.2f)',
+ album, artist, ratio)
+ continue
+ return candidates