mirror of
https://github.com/beetbox/beets.git
synced 2026-02-21 23:03:26 +01:00
Merge pull request #3207 from arcresu/mpd-currentsong
mpdstats: use currentsong instead of playlist
This commit is contained in:
commit
ebed21f319
3 changed files with 19 additions and 18 deletions
|
|
@ -107,17 +107,17 @@ class MPDClientWrapper(object):
|
|||
self.connect()
|
||||
return self.get(command, retries=retries - 1)
|
||||
|
||||
def playlist(self):
|
||||
"""Return the currently active playlist. Prefixes paths with the
|
||||
def currentsong(self):
|
||||
"""Return the path to the currently playing song. Prefixes paths with the
|
||||
music_directory, to get the absolute path.
|
||||
"""
|
||||
result = {}
|
||||
for entry in self.get('playlistinfo'):
|
||||
result = None
|
||||
entry = self.get('currentsong')
|
||||
if 'file' in entry:
|
||||
if not is_url(entry['file']):
|
||||
result[entry['id']] = os.path.join(
|
||||
self.music_directory, entry['file'])
|
||||
result = os.path.join(self.music_directory, entry['file'])
|
||||
else:
|
||||
result[entry['id']] = entry['file']
|
||||
result = entry['file']
|
||||
return result
|
||||
|
||||
def status(self):
|
||||
|
|
@ -250,12 +250,16 @@ class MPDStats(object):
|
|||
self.now_playing = None
|
||||
|
||||
def on_play(self, status):
|
||||
playlist = self.mpd.playlist()
|
||||
path = playlist.get(status['songid'])
|
||||
|
||||
path = self.mpd.currentsong()
|
||||
|
||||
if not path:
|
||||
return
|
||||
|
||||
if is_url(path):
|
||||
self._log.info(u'playing stream {0}', displayable_path(path))
|
||||
return
|
||||
|
||||
played, duration = map(int, status['time'].split(':', 1))
|
||||
remaining = duration - played
|
||||
|
||||
|
|
@ -272,14 +276,6 @@ class MPDStats(object):
|
|||
if diff <= self.time_threshold:
|
||||
return
|
||||
|
||||
if self.now_playing['path'] == path and played == 0:
|
||||
self.handle_song_change(self.now_playing)
|
||||
|
||||
if is_url(path):
|
||||
self._log.info(u'playing stream {0}', displayable_path(path))
|
||||
self.now_playing = None
|
||||
return
|
||||
|
||||
self._log.info(u'playing {0}', displayable_path(path))
|
||||
|
||||
self.now_playing = {
|
||||
|
|
|
|||
|
|
@ -190,6 +190,11 @@ Fixes:
|
|||
:bug:`3200`
|
||||
* :doc:`/plugins/lastgenre`: The `force` config option now actually works.
|
||||
:bug:`2704` :bug:`3054`
|
||||
* :doc:`/plugins/mpdstats`: Use the ``currentsong`` MPD command instead of
|
||||
``playlist`` to get the current song, improving performance when the playlist
|
||||
is long.
|
||||
Thanks to :user:`ray66`.
|
||||
:bug:`3207` :bug:`2752`
|
||||
|
||||
.. _python-itunes: https://github.com/ocelma/python-itunes
|
||||
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ class MPDStatsTest(unittest.TestCase, TestHelper):
|
|||
|
||||
@patch("beetsplug.mpdstats.MPDClientWrapper", return_value=Mock(**{
|
||||
"events.side_effect": EVENTS, "status.side_effect": STATUSES,
|
||||
"playlist.return_value": {1: item_path}}))
|
||||
"currentsong.return_value": item_path}))
|
||||
def test_run_mpdstats(self, mpd_mock):
|
||||
item = Item(title=u'title', path=self.item_path, id=1)
|
||||
item.add(self.lib)
|
||||
|
|
|
|||
Loading…
Reference in a new issue