- 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
- Then add to candidates in self.to_add
- """
- artist = tracks[0].artist
- # In random play mode use complete playlist to filter
- if self.player.playmode.get('random'):
- black_list = self.player.playlist + self.to_add
- else:
- black_list = self.player.queue + self.to_add
- not_in_hist = list(set(tracks) - set(self.get_history(artist=artist)))
- if self.plugin_conf.get('queue_mode') != 'top' and not not_in_hist:
- self.log.debug('All tracks already played for "%s"', artist)
- random.shuffle(not_in_hist)
- candidate = []
- for trk in [_ for _ in not_in_hist if _ not in black_list]:
- # Should use albumartist heuristic as well
- if self.plugin_conf.getboolean('single_album'): # pylint: disable=no-member
- if (trk.album == self.player.current.album or
- trk.album in [tr.album for tr in black_list]):
- self.log.debug('Found unplayed track ' +
- 'but from an album already queued: %s', trk)
- continue
- candidate.append(trk)
- if not candidate:
- return False
- self.to_add.append(random.choice(candidate))
- return True
-
- def _get_artists_list_reorg(self, alist):
- """
- Move around items in artists_list in order to play first not recently
- played artists
- """
- hist = list()
- duration = self.daemon_conf.getint('sima', 'history_duration')
- for art in self.sdb.get_artists_history(alist, duration=duration):
- if art not in hist:
- hist.insert(0, art)
- reorg = [art for art in alist if art not in hist]
- reorg.extend(hist)
- return reorg
-