- def get_history(self, artist):
- """Constructs list of Track for already played titles for an artist.
- """
- duration = self.daemon_conf.getint('sima', 'history_duration')
- tracks_from_db = self.sdb.get_history(duration=duration, artist=artist)
- # Construct Track() objects list from database history
- played_tracks = [Track(artist=tr[-1], album=tr[1], title=tr[2],
- file=tr[3]) for tr in tracks_from_db]
- return played_tracks
-
- def filter_track(self, tracks):
- """
- Extract one unplayed track from a Track object list.
- * not in history
- * not already in the queue
- * not blacklisted
- """
- artist = tracks[0].artist
- black_list = self.player.queue + self.to_add
- not_in_hist = list(set(tracks) - set(self.get_history(artist=artist)))
- if not not_in_hist:
- self.log.debug('All tracks already played for "{}"'.format(artist))
- random.shuffle(not_in_hist)
- #candidate = [ trk for trk in not_in_hist if trk not in black_list
- #if not self.sdb.get_bl_track(trk, add_not=True)]
- candidate = []
- for trk in [_ for _ in not_in_hist if _ not in black_list]:
- if self.sdb.get_bl_track(trk, add_not=True):
- self.log.info('Blacklisted: {0}: '.format(trk))
- continue
- if self.sdb.get_bl_album(trk, add_not=True):
- self.log.info('Blacklisted album: {0}: '.format(trk))
- continue
- # Should use albumartist heuristic as well
- if self.plugin_conf.getboolean('single_album'):
- if (trk.album == self.player.current.album or
- trk.album in [tr.album for tr in self.to_add]):
- self.log.debug('Found unplayed track ' +
- 'but from an album already queued: %s' % (trk))
- continue
- candidate.append(trk)
- if not candidate:
- self.log.debug('Unable to find title to add' +
- ' for "%s".' % artist)
- return None
- self.to_add.append(random.choice(candidate))
-
- def _get_artists_list_reorg(self, alist):
- """
- Move around items in artists_list in order to play first not recently
- played artists
- """
- # TODO: move to utils as a decorator
- duration = self.daemon_conf.getint('sima', 'history_duration')
- art_in_hist = list()
- for trk in self.sdb.get_history(duration=duration,
- artists=alist):
- if trk[0] not in art_in_hist:
- art_in_hist.append(trk[0])
- art_in_hist.reverse()
- art_not_in_hist = [ ar for ar in alist if ar not in art_in_hist ]
- random.shuffle(art_not_in_hist)
- art_not_in_hist.extend(art_in_hist)
- self.log.debug('history ordered: {}'.format(
- ' / '.join(art_not_in_hist)))
- return art_not_in_hist
-