From 5cb110f58a09e93be82a452758382e9637faf4cf Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 30 Nov 2010 17:59:27 +0100 Subject: mpclient: increment the playcount sticker maybe this belongs in a plugin instead? --- nephilim/mpclient.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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 ## -- cgit v1.2.3