mopidy-mpd
mopidy-mpd copied to clipboard
Implement MPD stats for Cantata
After update to Cantata version 2.0.1, the library is empty and doesn't even refresh when I run "Refresh database" from the menu.
After some investigation it seems that Cantata uses MDP 'stats' command to find out if the library should be updated. And since Mopidy doesn't implement the 'stats' command, the library is never updated.
Following change fixed this issue for me, although it's far from perfect - it forces library update every time Cantata starts and there are still some field not implemented. I was not able to get library update time anywhere.
iff --git a/mopidy/mpd/protocol/status.py b/mopidy/mpd/protocol/status.py
index 3d76d35..5f3ac06 100644
--- a/mopidy/mpd/protocol/status.py
+++ b/mopidy/mpd/protocol/status.py
@@ -2,6 +2,8 @@ from __future__ import absolute_import, unicode_literals
import pykka
+from datetime import datetime
+
from mopidy.core import PlaybackState
from mopidy.mpd import exceptions, protocol, translator
@@ -125,12 +127,12 @@ def stats(context):
- ``playtime``: time length of music played
"""
return {
- 'artists': 0, # TODO
- 'albums': 0, # TODO
- 'songs': 0, # TODO
+ 'artists': len(context.core.library.get_distinct('artist', {}).get()),
+ 'albums': len(context.core.library.get_distinct('album', {}).get()),
+ 'songs': len(context.core.library.get_distinct('track', {}).get()),
'uptime': 0, # TODO
'db_playtime': 0, # TODO
- 'db_update': 0, # TODO
+ 'db_update': datetime.now().strftime("%s"), # TODO
'playtime': 0, # TODO
}
The get_distinct()
call was only ever intended for a very specific use in the MPD frontend. Most backends don't implement them and the only reason they exist is to avoid some really bad lookup performance if we don't specialize it :/
So I'm a bit unsure if we should add something like this.
- There is a mismatch between our generic backend support and the MPD idea of a library. This really doesn't mesh well with streaming services like Spotify etc.
- Sadly there are other clients that use the current state of the stats command to detect mopidy and special case handling :/
My impression is that the 'stats' command should return info only about local collection. It doesn't make sense to ask for this information for streaming services like Spotify.
For me, reporting info only about local collection would solve the issue.
If someone has a good proposal for how we could add this in clean way I'm all ears. My main concern is trying to avoid adding things that are one offs for specific backends.
I would really appreciate a solution for this issue. Cantata is by far the best MPD client for Windows and Linux, it's a shame we can't use it with Mopidy. Cantata used to have some workarounds to support Mopidy but these were removed, see https://github.com/CDrummond/cantata/issues/949#issuecomment-271230502.
Your statement "Sadly there are other clients that use the current state of the stats command to detect mopidy and special case handling" refers to Cantata. As Cantata doesn't perform this check anymore it's safe to change the stats behavior.
Do you know it's only Cantana?
I reviewed lots of MPD clients on Windows, Linux as well as Android and Cantata is the only one with this issue. I guess because it's probably one of the only clients which uses as local database copy, which needs to be kept in sync with the server database. I know you don't like that local copy concept, but it's one of the main reasons how Cantata manages to be the best MPD client.
If you're afraid to break things it might be an option to enable/disable new 'stats' behavior in the Mopidy configuration file.
Update: the next release of Cantata might include the workaround for Mopidy stats again: https://github.com/CDrummond/cantata/issues/949. That includes detection of Mopidy based on the stats returning 0.
Would it be possible to get support for some type of rating functionality? Even using something simple like beets type plugin would be nice. Looks like someone has a bounty for mpdstats.