Skip to content

Calling find with a search window (startend) fails #180

Open

Description

@joshaw

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.

Activity

  1. valrus commented on Aug 10, 2022

    @valrus

    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:

    def _write_command(self, command, args=[]):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions