diff options
author | Anton Khirnov <anton@khirnov.net> | 2010-11-30 17:59:27 +0100 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2011-09-04 20:17:35 +0200 |
commit | 5cb110f58a09e93be82a452758382e9637faf4cf (patch) | |
tree | 62aa6984efeca7e3b16cfc24bbdc6b0f98202b0b /nephilim | |
parent | 1be3cf6c6118eb39fe65f4e7848f2037f135ff33 (diff) |
mpclient: increment the playcount sticker
maybe this belongs in a plugin instead?
Diffstat (limited to 'nephilim')
-rw-r--r-- | nephilim/mpclient.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/nephilim/mpclient.py b/nephilim/mpclient.py index 104e62c..4973409 100644 --- a/nephilim/mpclient.py +++ b/nephilim/mpclient.py @@ -18,6 +18,7 @@ from PyQt4 import QtCore, QtNetwork from PyQt4.QtCore import pyqtSignal as Signal, pyqtSlot as Slot import logging +import os.path from song import Song from mpdsocket import MPDSocket @@ -554,9 +555,24 @@ class MPClient(QtCore.QObject): self.cur_song = Song() if song['id'] != self.cur_song['id']: self.song_changed.emit(self.cur_song) + if 'played' in song: + self._update_playcount(song) else: self.songpos_changed.emit(self.cur_song) + def _update_playcount(self, song): + if not 'file' in song or os.path.isabs(song['file']): + return + self._logger.info('Incrementing the playcount for song %s.'%song['file']) + self.sticker_get(song['file'], 'playcount', lambda val: self._update_playcount2(song, val)) + def _update_playcount2(self, song, playcount): + try: + playcount = int(playcount) + except ValueError: + playcount = 0 + playcount += 1 + self.sticker_set(song['file'], 'playcount', playcount) + def _command(self, *cmd, **kwargs): """ Send specified command to MPD asynchronously. kwargs must contain @@ -599,6 +615,9 @@ class MPClient(QtCore.QObject): def _update_timer(self): self.status['time'][0] += 1 self.time_changed.emit(self.status['time'][0]) + if not 'played' in self.cur_song: + if self.status['time'][0] / self.status['time'][1] > 0.75: + self.cur_song['played'] = True ## MPD output parsing functions ## |