Merge pull request #1212 from brunal/mpdstats-react-only-once

mpdstats: don't register a natural song change twice
This commit is contained in:
Adrian Sampson 2015-01-08 13:43:46 -08:00
commit 558d1f9639

View file

@ -212,6 +212,8 @@ class MPDStats(object):
To this end the difference between the song's supposed end time
and the current time is calculated. If it's greater than a threshold,
the song is considered skipped.
Returns whether the change was manual (skipped previous song or not)
"""
diff = abs(song['remaining'] - (time.time() - song['started']))
@ -225,6 +227,8 @@ class MPDStats(object):
if self.do_rating:
self.update_rating(song['beets_item'], skipped)
return skipped
def handle_played(self, song):
"""Updates the play count of a song.
"""
@ -264,19 +268,24 @@ class MPDStats(object):
remaining = duration - played
if self.now_playing and self.now_playing['path'] != path:
self.handle_song_change(self.now_playing)
skipped = self.handle_song_change(self.now_playing)
# mpd responds twice on a natural new song start
going_to_happen_twice = not skipped
else:
going_to_happen_twice = False
log.info(u'mpdstats: playing {0}', displayable_path(path))
if not going_to_happen_twice:
log.info(u'mpdstats: playing {0}', displayable_path(path))
self.now_playing = {
'started': time.time(),
'remaining': remaining,
'path': path,
'beets_item': self.get_item(path),
}
self.now_playing = {
'started': time.time(),
'remaining': remaining,
'path': path,
'beets_item': self.get_item(path),
}
self.update_item(self.now_playing['beets_item'],
'last_played', value=int(time.time()))
self.update_item(self.now_playing['beets_item'],
'last_played', value=int(time.time()))
def run(self):
self.mpd.connect()