1 # -*- coding: utf-8 -*-
2 # Copyright (c) 2013, 2014, 2020 kaliko <kaliko@azylum.org>
4 # This file is part of sima
6 # sima is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # sima is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with sima. If not, see <http://www.gnu.org/licenses/>.
20 """Add playing tracks to history
23 # standard library import
26 # third parties components
29 from ...lib.plugin import Plugin
32 class History(Plugin):
36 def __init__(self, daemon):
37 Plugin.__init__(self, daemon)
38 self._last_clean = time()
41 self.log.info('Cleaning database')
42 self.sdb.purge_history()
45 hist = self.sdb.fetch_history()
50 def callback_player(self):
51 current = self.player.current
53 if self.player.state == 'play':
54 self.log.debug('Cannot add "%s" to history (empty or missing file)', current)
56 last_hist = self._h_tip()
57 if last_hist and last_hist == current:
59 self.log.debug('add history: "%s"', current)
60 self.sdb.add_history(current)
61 if time() - self._last_clean > 86400:
63 self._last_clean = time()
67 # vim: ai ts=4 sw=4 sts=4 expandtab