Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement MPD stats for Cantata #13

Open
rnovacek opened this issue Jun 29, 2016 · 8 comments
Open

Implement MPD stats for Cantata #13

rnovacek opened this issue Jun 29, 2016 · 8 comments
Labels
C-enhancement Category: A PR with an enhancement or an issue with an enhancement proposal

Comments

@rnovacek
Copy link

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
     }
@adamcik
Copy link
Member

adamcik commented Jul 15, 2016

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.

  1. 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.
  2. Sadly there are other clients that use the current state of the stats command to detect mopidy and special case handling :/

@rnovacek
Copy link
Author

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.

@adamcik
Copy link
Member

adamcik commented Jul 25, 2016

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.

@gvc0
Copy link

gvc0 commented Jan 9, 2017

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.

@kingosticks
Copy link
Member

Do you know it's only Cantana?

@gvc0
Copy link

gvc0 commented Jan 9, 2017

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.

@gvc0
Copy link

gvc0 commented Jan 12, 2017

Update: the next release of Cantata might include the workaround for Mopidy stats again: CDrummond/cantata#949. That includes detection of Mopidy based on the stats returning 0.

@reconmaster

This comment has been minimized.

@jodal jodal transferred this issue from mopidy/mopidy Dec 20, 2019
@jodal jodal added the C-enhancement Category: A PR with an enhancement or an issue with an enhancement proposal label Dec 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: A PR with an enhancement or an issue with an enhancement proposal
Projects
None yet
Development

No branches or pull requests

6 participants