try:
from musicpd import (MPDClient, MPDError, CommandError)
except ImportError as err:
try:
from musicpd import (MPDClient, MPDError, CommandError)
except ImportError as err:
self._mpd = host, port, password
self._client = MPDClient()
self._client.iterate = True
self._mpd = host, port, password
self._client = MPDClient()
self._client.iterate = True
def __getattr__(self, attr):
command = attr
wrapper = self._execute
return lambda *args: wrapper(command, args)
def __getattr__(self, attr):
command = attr
wrapper = self._execute
return lambda *args: wrapper(command, args)
def _execute(self, command, args):
self._write_command(command, args)
return self._client_wrapper()
def _execute(self, command, args):
self._write_command(command, args)
return self._client_wrapper()
+ def _flush_cache(self):
+ """
+ Both flushes and instantiates _cache
+ """
+ if isinstance(self._cache, dict):
+ self.log.info('Player: Flushing cache!')
+ else:
+ self.log.info('Player: Initialising cache!')
+ self._cache = {
+ 'artists': None,
+ }
+ self._cache['artists'] = frozenset(self._client.list('artist'))
+
def find_track(self, artist, title=None):
#return getattr(self, 'find')('artist', artist, 'title', title)
if title:
return self.find('artist', artist, 'title', title)
return self.find('artist', artist)
def find_track(self, artist, title=None):
#return getattr(self, 'find')('artist', artist, 'title', title)
if title:
return self.find('artist', artist, 'title', title)
return self.find('artist', artist)
"""
Controls presence of artist in music library.
Crosschecking artist names with SimaStr objects / difflib / levenshtein
"""
Controls presence of artist in music library.
Crosschecking artist names with SimaStr objects / difflib / levenshtein
self.log.debug('found exact match for "%s"' % artist)
return [artist]
# Then proceed with fuzzy matching if got nothing
self.log.debug('found exact match for "%s"' % artist)
return [artist]
# Then proceed with fuzzy matching if got nothing
- match = get_close_matches(artist.orig, all_artists, 50, 0.73)
+ match = get_close_matches(artist.orig, self.artists, 50, 0.73)
- Special wrapper around album search:
- Album lookup is made through AlbumArtist/Album instead of Artist/Album
+ Fetch all albums for "AlbumArtist" == artist
+ Filter albums returned for "artist" == artist since MPD returns any
+ album containing at least a single track for artist
- alb_art_search = self.list('album', 'albumartist', artist,)
- if alb_art_search:
- return alb_art_search
- return self.list('album', 'artist', artist)
+ albums = set()
+ albums.update(self.list('album', 'albumartist', artist))
+ for album in self.list('album', 'artist', artist):
+ arts = set([trk.artist for trk in self.find('album', album)])
+ if len(arts) < 2:
+ albums.add(album)
+ else:
+ self.log.debug('"{0}" probably not an album of "{1}"'.format(
+ album, artist) + '({0})'.format('/'.join(arts)))
+ return albums
return ret
except (MPDError, IOError) as err:
raise PlayerError("Couldn't init idle: %s" % err)
return ret
except (MPDError, IOError) as err:
raise PlayerError("Couldn't init idle: %s" % err)
raise PlayerError('Could connect to "%s", '
'but command "%s" not available' %
(host, nddcmd))
raise PlayerError('Could connect to "%s", '
'but command "%s" not available' %
(host, nddcmd))