"""
# Query History
- def get_history(self, artist=False):
- """Constructs Track list of already played artists.
-
- :param Artist artist: Artist object to look history for
- """
+ def get_history(self):
+ """Returns a Track list of already played artists."""
duration = self.main_conf.getint('sima', 'history_duration')
- name = None
- if artist:
- name = artist.name
- from_db = self.sdb.get_history(duration=duration, artist=name)
- hist = [Track(artist=tr[0], album=tr[1], title=tr[2],
- file=tr[3]) for tr in from_db]
- return hist
+ return self.sdb.fetch_history(duration=duration)
def get_album_history(self, artist):
"""Retrieve album history"""
- hist = []
- tracks_from_db = self.get_history(artist=artist)
- for trk in tracks_from_db:
- if trk.album and trk.album in hist:
- continue
- hist.append(Album(name=trk.album, artist=Artist(trk.artist)))
- return hist
+ duration = self.main_conf.getint('sima', 'history_duration')
+ return self.sdb.fetch_albums_history(needle=artist, duration=duration)
def get_reorg_artists_list(self, alist):
"""
not_queued_artist = alist - queued_artist
duration = self.main_conf.getint('sima', 'history_duration')
hist = []
- for art in self.sdb.get_artists_history(alist, duration=duration):
+ for art in self.sdb.fetch_artists_history(alist, duration=duration):
if art not in hist:
if art not in queued_artist:
hist.insert(0, art)
deny_list = self.player.playlist
else:
deny_list = self.player.queue
- not_in_hist = list(set(tracks) - set(self.get_history(artist=artist)))
+ not_in_hist = list(set(tracks) - set(self.sdb.fetch_history(artist=artist)))
if not not_in_hist:
self.log.debug('All tracks already played for "%s"', artist)
if unplayed:
#cls.log.debug('using {0} as bl filter'.format(bl_getter.__name__))
results = list()
for elem in func(*args, **kwargs):
- if bl_getter(elem, add_not=True):
+ if bl_getter(elem, add=False):
#cls.log.debug('Blacklisted "{0}"'.format(elem))
continue
- if track and cls.database.get_bl_album(elem, add_not=True):
+ if track and cls.database.get_bl_album(elem, add=False):
# filter album as well in track mode
# (artist have already been)
cls.log.debug('Blacklisted alb. "%s"', elem)
def shutdown(self):
self.log.info('Cleaning database')
self.sdb.purge_history()
- self.sdb.clean_database()
+
+ def _h_tip(self):
+ hist = self.sdb.fetch_history()
+ if hist:
+ return hist[0]
+ return None
def callback_player(self):
current = self.player.current
- last_hist = next(self.sdb.get_history(), None)
- if last_hist and last_hist[3] == current.file:
- return
if not current:
- self.log.debug('Cannot add "%s" to history (empty or missing file)', current)
+ if self.player.state == 'play':
+ self.log.debug('Cannot add "%s" to history (empty or missing file)', current)
+ return
+ last_hist = self._h_tip()
+ if last_hist and last_hist == current:
return
self.log.debug('add history: "%s"', current)
self.sdb.add_history(current)