mirror of
https://github.com/beetbox/beets.git
synced 2025-12-16 21:54:07 +01:00
Merge pull request #2412 from artemutin/mpdstats_on_play
mpdstats: More general approach to multiple on_play calls for the same song
This commit is contained in:
commit
2a33db3bb6
2 changed files with 22 additions and 16 deletions
|
|
@ -263,25 +263,30 @@ class MPDStats(object):
|
|||
played, duration = map(int, status['time'].split(':', 1))
|
||||
remaining = duration - played
|
||||
|
||||
if self.now_playing and self.now_playing['path'] != path:
|
||||
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
|
||||
if self.now_playing:
|
||||
if self.now_playing['path'] != path:
|
||||
self.handle_song_change(self.now_playing)
|
||||
else:
|
||||
# In case we got mpd play event with same song playing
|
||||
# multiple times,
|
||||
# assume low diff means redundant second play event
|
||||
# after natural song start.
|
||||
diff = abs(time.time() - self.now_playing['started'])
|
||||
|
||||
if not going_to_happen_twice:
|
||||
self._log.info(u'playing {0}', displayable_path(path))
|
||||
if diff <= self.time_threshold:
|
||||
return
|
||||
|
||||
self.now_playing = {
|
||||
'started': time.time(),
|
||||
'remaining': remaining,
|
||||
'path': path,
|
||||
'beets_item': self.get_item(path),
|
||||
}
|
||||
self._log.info(u'playing {0}', displayable_path(path))
|
||||
|
||||
self.update_item(self.now_playing['beets_item'],
|
||||
'last_played', value=int(time.time()))
|
||||
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()))
|
||||
|
||||
def run(self):
|
||||
self.mpd.connect()
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ Fixes:
|
|||
* :doc:`/plugins/bpd`: Report playback times as integer. :bug:`2394`
|
||||
* :doc:`/plugins/mpdstats`: Fix Python 3 compatibility. The plugin also now
|
||||
requires version 0.4.2 or later of the ``python-mpd2`` library. :bug:`2405`
|
||||
* :doc:`/plugins/mpdstats`: Improve handling of mpd status queries.
|
||||
|
||||
|
||||
1.4.3 (January 9, 2017)
|
||||
|
|
|
|||
Loading…
Reference in a new issue