# local import
from .lib.player import Player
from .lib.track import Track
+from .lib.album import Album
from .lib.simastr import SimaStr
return alb_art_search
return self.find('artist', artist, 'album', album)
- #@blacklist(album=True)
+ @blacklist(album=True)
def find_albums(self, artist):
"""
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
"""
- albums = set()
- albums.update(self.list('album', 'albumartist', artist))
+ albums = []
+ kwalbart = {'albumartist':artist, 'artist':artist}
+ for album in self.list('album', 'albumartist', artist):
+ if album not in albums:
+ albums.append(Album(name=album, **kwalbart))
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:
+ if len(arts) < 2: # TODO: better heuristic, use a ratio instead
+ if album not in albums:
+ albums.append(Album(name=album, albumartist=artist))
+ elif album not in albums:
self.log.debug('"{0}" probably not an album of "{1}"'.format(
- album, artist) + '({0})'.format('/'.join(arts)))
- if albums:
- self.log.debug('Albums candidate: {0}'.format('/'.join(albums)))
+ album, artist) + '({0})'.format('/'.join(arts)))
return albums
def monitor(self):
--- /dev/null
+# -*- coding: utf-8 -*-
+
+from .track import Track
+
+class MetaException(Exception):
+ pass
+
+class Meta:
+
+ def __init__(self, **kwargs):
+ self.name = None
+ self.mbid = None
+ if 'name' not in kwargs:
+ raise MetaException('need at least a "name" argument')
+ self.__dict__.update(kwargs)
+
+ def __repr__(self):
+ fmt = '{0}(name="{1.name}", mbid="{1.mbid}")'
+ return fmt.format(self.__class__.__name__, self)
+
+ def __str__(self):
+ return str(self.name)
+
+ def __hash__(self):
+ if self.mbid is not None:
+ return hash(self.mbid)
+ else:
+ return id(self)
+
+
+class Album(Meta):
+ __hash__ = Meta.__hash__
+
+ def __init__(self, **kwargs):
+ super().__init__(**kwargs)
+
+ def __eq__(self, other):
+ """
+ Perform mbid equality test if present,
+ else fallback on self.name equality
+ """
+ if hasattr(other, 'mbid'):
+ if other.mbid and self.mbid:
+ return self.mbid == other.mbid
+ return str(self) == str(other)
+
+ @property
+ def album(self):
+ return self.name
+
+# vim: ai ts=4 sw=4 sts=4 expandtab
for artist in artists:
self.log.info('Looking for an album to add for "%s"...' % artist)
albums = self.player.find_albums(artist)
+ # str conversion while Album type is not propagated
+ albums = [ str(album) for album in albums]
+ if albums:
+ self.log.debug('Albums candidate: {0:s}'.format(' / '.join(albums)))
+ else: continue
# albums yet in history for this artist
+ albums = set(albums)
albums_yet_in_hist = albums & self._get_album_history(artist=artist)
albums_not_in_hist = list(albums - albums_yet_in_hist)
# Get to next artist if there are no unplayed albums
random.shuffle(albums_not_in_hist)
for album in albums_not_in_hist:
tracks = self.player.find_album(artist, album)
- if tracks and self.sdb.get_bl_album(tracks[0], add_not=True):
- self.log.info('Blacklisted album: "%s"' % album)
- self.log.debug('using track: "%s"' % tracks[0])
- continue
# Look if one track of the album is already queued
# Good heuristic, at least enough to guess if the whole album is
# already queued.