X-Git-Url: http://git.kaliko.me/?a=blobdiff_plain;f=sima%2Fplugins%2Fcore%2Fhistory.py;h=3380870754b84a12c775dd0075b40173e1f0c0c6;hb=c23e4560ba184403e94d41cbf0816ed9847406fc;hp=b85c0dd923b1cb302237fa299dbcd301b3d14cf6;hpb=03d85cc860dde8ec2ecd2076d014db763017f547;p=mpd-sima.git diff --git a/sima/plugins/core/history.py b/sima/plugins/core/history.py index b85c0dd..3380870 100644 --- a/sima/plugins/core/history.py +++ b/sima/plugins/core/history.py @@ -34,25 +34,30 @@ class History(Plugin): """ def __init__(self, daemon): Plugin.__init__(self, daemon) - self.sdb = daemon.sdb self._last_clean = time() 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[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) - if self._last_clean - time() > 86400: + if time() - self._last_clean > 86400: self.shutdown() self._last_clean = time()