python-mpd2
python-mpd2 copied to clipboard
Grouping count command
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
it could use the first key received on the wire as delimiter.
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]
I've added a example of a grouping count command in my repo, ref. count#50.
sorry for the delay. I will have a look at it tomorrow.