python-mpd2 icon indicating copy to clipboard operation
python-mpd2 copied to clipboard

Grouping count command

Open mxjeff opened this issue 10 years ago • 4 comments

The grouping version of count command behave unexpectedly IMHO:

>>> cli = mpd.MPDClient()
>>> cli.connect(host='/run/mpd/socket', port=42)
>>> cli.count('group', 'albumartist')
{'albumartist': ['art00', 'art01',…], 
 'playtime': ['123', '321', …],
 'songs': ['1', '2',…]}
>>> #  idem with:
>>> cli.count('genre', 'Rock', 'group', 'albumartist')

I would expect a list of object of that kind instead:

>>> cli.count('group', 'albumartist')
[ {'albumartist': 'art00', 'playtime': '123', 'songs': '1'},
  {'albumartist': 'art01', 'playtime': '321', 'songs': '2'},
…]

This object does not require extra processing to link grouping values with its playtime/songs stats.

I had a quick look at the raw MPD output, I think this might be tricky since the delimiter changes depending on the function signature. I don't have a straight forward solution to submit.

That's it Thanks for your work

mxjeff avatar Feb 16 '15 14:02 mxjeff

it could use the first key received on the wire as delimiter.

Mic92 avatar Feb 16 '15 18:02 Mic92

I don't see how to do it without changing or writing an alternative _read_objects method.

Another solution might be to give all possible delimiters, or a smaller set of them and let users append tags they might need. For instance:

# in mpd.py
COUNT_GROUPING = ['artist', 'albumartist', 'album', 'genre']
.
 .
  .
    def _fetch_count(self):
        return self._fetch_objects(COUNT_GROUPING)

Then it could be easily extend like that:

>>> mpd.COUNT_GROUPING += [MyGroupingTag]
>>> cli.count('group', MyGroupingTag]

mxjeff avatar Feb 16 '15 21:02 mxjeff

I've added a example of a grouping count command in my repo, ref. count#50.

mxjeff avatar Feb 23 '15 15:02 mxjeff

sorry for the delay. I will have a look at it tomorrow.

Mic92 avatar Feb 25 '15 23:02 Mic92