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

Calling find with a search window (startend) fails

Open joshaw opened this issue 3 years ago • 1 comments

I'm trying to work out the syntax for using a search window when using find(). The MPD documentation says:

find {FILTER} [sort {TYPE}] [window {START:END}] ... window can be used to query only a portion of the real response. The parameter is two zero-based record numbers; a start number and an end number.

And the python-mpd2 documentation says

MPDClient.find(type, what[, ..., startend]) ... window can be used to query only a portion of the real response. The parameter is two zero-based record numbers; a start number and an end number.

But I can't find a syntax that doesn't give an error.

  • Using a single string in the form from the MPD docs like client.find("any", query, "1:100") gives

    mpd.base.CommandError: [2@0] {search} Incorrect number of filter arguments
    

    I also tried using space instead of : and using window 1:100 in case the window string is necessary.

  • Doing the same but adding in the sort parameter (client.find("any", query, "title", "1:100")) gives no search results - I guess it's now trying to find tracks with a title of 1:100.

  • Using two separate parameters like client.find("any", query, "1", "100") gives

    mpd.base.CommandError: [2@0] {search} Unknown filter type
    

My query is working fine without the window, I'd just like to enable pagination so I don't get thousands of results returned for short queries. I couldn't find any examples in the examples directory and none of the tests use this feature either. Any help would be greatly appreciated. Thanks.

joshaw avatar Oct 28 '21 11:10 joshaw

Hi, this is super late, but I was just messing around with this library tonight and randomly discovered how to call this. You have to use the literal string "window" and pass a tuple. So your example should work with client.find("any", query, "window", (0, 99)) (the window is zero-based).

Note that other fixed keywords like "group" and "sort" that you might see in the MPD docs work the same way. So if you want to add sorting by artist name to your query, it would look like: client.find("any", query, "sort", "Artist", "window", (0, 99))

You can see the tuple parameter handling here: https://github.com/Mic92/python-mpd2/blob/41459b544d2e90eb878a4cb43191f314217fda9f/mpd/base.py#L555

valrus avatar Aug 10 '22 04:08 valrus