X-Git-Url: https://git.kaliko.me/?a=blobdiff_plain;f=sima%2Fmpdclient.py;h=95cfb5765c23e41df83cb571924cdb0e6c6f6575;hb=5595804ad7bc2eeb15db93efc129bf21d9a3cc77;hp=abc8282ea545e50722ecf0dcfcb4c70d79bdc05a;hpb=c2772b384c9a73397733a81bce3d7f21c52370a7;p=mpd-sima.git diff --git a/sima/mpdclient.py b/sima/mpdclient.py index abc8282..95cfb57 100644 --- a/sima/mpdclient.py +++ b/sima/mpdclient.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright (c) 2009-2020 kaliko +# Copyright (c) 2009-2021 kaliko # # This file is part of sima # @@ -33,7 +33,7 @@ from .utils.leven import levenshtein_ratio class PlayerError(Exception): - """Fatal error in poller.""" + """Fatal error in the player.""" # Some decorators @@ -121,10 +121,16 @@ class MPD(MPDClient): """ needed_cmds = ['status', 'stats', 'add', 'find', 'search', 'currentsong', 'ping'] - needed_mbid_tags = {'Artist', 'Album', 'AlbumArtist', - 'Title', 'Track', 'Genre', - 'MUSICBRAINZ_ARTISTID', 'MUSICBRAINZ_ALBUMID', + needed_tags = {'Artist', 'Album', 'AlbumArtist', 'Title', 'Track'} + needed_mbid_tags = {'MUSICBRAINZ_ARTISTID', 'MUSICBRAINZ_ALBUMID', 'MUSICBRAINZ_ALBUMARTISTID', 'MUSICBRAINZ_TRACKID'} + MPD_supported_tags = {'Artist', 'ArtistSort', 'Album', 'AlbumSort', 'AlbumArtist', + 'AlbumArtistSort', 'Title', 'Track', 'Name', 'Genre', + 'Date', 'OriginalDate', 'Composer', 'Performer', + 'Conductor', 'Work', 'Grouping', 'Disc', 'Label', + 'MUSICBRAINZ_ARTISTID', 'MUSICBRAINZ_ALBUMID', + 'MUSICBRAINZ_ALBUMARTISTID', 'MUSICBRAINZ_TRACKID', + 'MUSICBRAINZ_RELEASETRACKID', 'MUSICBRAINZ_WORKID'} database = None def __init__(self, daemon): @@ -181,10 +187,18 @@ class MPD(MPDClient): raise PlayerError('Could connect to "%s", ' 'but command "%s" not available' % (host, cmd)) - # Controls use of MusicBrainzIdentifier self.tagtypes('clear') + for tag in MPD.needed_tags: + self.tagtypes('enable', tag) + tt = set(map(str.lower, self.tagtypes())) + needed_tags = set(map(str.lower, MPD.needed_tags)) + if len(needed_tags & tt) != len(MPD.needed_tags): + self.log.warning('MPD exposes: %s', tt) + self.log.warning('Tags needed: %s', needed_tags) + raise PlayerError('Missing mandatory metadata!') for tag in MPD.needed_mbid_tags: self.tagtypes('enable', tag) + # Controls use of MusicBrainzIdentifier if self.daemon.config.get('sima', 'musicbrainzid'): tt = set(self.tagtypes()) if len(MPD.needed_mbid_tags & tt) != len(MPD.needed_mbid_tags): @@ -329,7 +343,7 @@ class MPD(MPDClient): tracks = set() if artist.mbid: tracks |= set(self.find('musicbrainz_artistid', artist.mbid)) - for name in artist.names_sz: + for name in artist.names: tracks |= set(self.find('artist', name)) return list(tracks) @@ -376,8 +390,11 @@ class MPD(MPDClient): if len(library) > 1: self.log.debug('I got "%s" searching for %r', library, artist) elif len(library) == 1 and library[0] != artist.name: + new_alias = artist.name self.log.info('Update artist name %s->%s', artist, library[0]) + self.log.debug('Also add alias for %s: %s', artist, new_alias) artist = Artist(name=library[0], mbid=artist.mbid) + artist.add_alias(new_alias) # Fetches remaining artists for potential match artists = self._cache['nombid_artists'] else: # not using MusicBrainzIDs @@ -411,11 +428,11 @@ class MPD(MPDClient): if SimaStr(artist.name) == fuzz: found = True artist.add_alias(fuzz) - self.log.info('"%s" quite probably matches "%s" (SimaStr)', - fuzz, artist) + self.log.debug('"%s" quite probably matches "%s" (SimaStr)', + fuzz, artist) if found: if artist.aliases: - self.log.debug('Found aliases: %s', '/'.join(artist.names)) + self.log.info('Found aliases: %s', '/'.join(artist.names)) return artist return None @@ -460,13 +477,14 @@ class MPD(MPDClient): looking for albums for Artist_B returns wrongly this album. """ # First, look for all potential albums - self.log.debug('Searching album for "%s"', artist) + self.log.debug('Searching album for "%r"', artist) if artist.aliases: self.log.debug('Searching album for %s aliases: "%s"', artist, artist.aliases) for name_sz in artist.names_sz: - raw_albums = self.list('album', f"( albumartist == '{name_sz}')") - albums = [Album(a, albumartist=artist.name, artist=artist) for a in raw_albums if a] + mpd_filter = f"((albumartist == '{name_sz}') AND ( album != ''))" + raw_albums = self.list('album', mpd_filter) + albums = [Album(a, albumartist=artist.name, artist=artist) for a in raw_albums] candidates = [] for album in albums: album_trks = self.find_tracks(album)