Don't register a natural song change twice

mpd responds twice to an 'idle' command upon a 'natural' song change
(i.e. not a skip). Checking the reason for mpd response avoids
registering twice the song change.

Fix issue #773
This commit is contained in:
Bruno Cauet 2015-01-08 12:39:28 +01:00
parent 0f1b5b2ca5
commit b7735bd3bf

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()