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

Support Danbooru "Common Search Parameters" ; at least 'page' and 'limit' #55

Open
fire-eggs opened this issue Nov 8, 2021 · 1 comment

Comments

@fire-eggs
Copy link

fire-eggs commented Nov 8, 2021

Detailed Description

The Danbooru API docs mention that all searches support a common set of parameters.

None of these common parameters are supported in api_danbooru.py.

I'm specifically interested in the "page" parameter.

Context

I am attempting to use pybooru to fetch notes for all posts [see my project Danbooru2019]. This because qwern doesn't include notes in his dataset.

Anywho, I found the note API will only return 20 notes for a given post. I.e. I'm using pybooru as follows:

nl = client.note_list(post_id=77, is_active=True)

And this only returns 20 notes, whereas post id 77 actually has 21 notes.

So I need to be able to request pages to get all notes, e.g.:

nl = client.note_list(post_id=77, is_active=True, page=1)
if (len(nl) == 20):
  nl = client.note_list(post_id=77, is_active=True, page=2)

Possible Implementation

Reworking api_danbooru.py, note_list as follows appears to do the trick [documentation removed for conciseness]:

    def note_list(self, body_matches=None, post_id=None, post_tags_match=None,
                  creator_name=None, creator_id=None, is_active=None, page=1):

        params = {
            'search[body_matches]': body_matches,
            'search[post_id]': post_id,
            'search[post_tags_match]': post_tags_match,
            'search[creator_name]': creator_name,
            'search[creator_id]': creator_id,
            'search[is_active]': is_active,
            'page' : page
            }
        return self._get('notes.json', params)

Your Environment

  • Pybooru Version: 4.2.2
  • Python Version: 3.8.10
  • Danbooru / Moebooru site: danbooru
  • Operating System and version: Linux Mint 20.1
  • Link to your project: Danbooru2019
@fire-eggs
Copy link
Author

Mucking about a little more, supporting the "limit" parameter might actually be more useful, as it extends the number of entries returned. E.g.:

    def note_list(self, body_matches=None, post_id=None, post_tags_match=None,
                  creator_name=None, creator_id=None, is_active=None, page=1, limit=20):

        params = {
            'search[body_matches]': body_matches,
            'search[post_id]': post_id,
            'search[post_tags_match]': post_tags_match,
            'search[creator_name]': creator_name,
            'search[creator_id]': creator_id,
            'search[is_active]': is_active,
            'page' : page,
            'limit' : limit
            }
        return self._get('notes.json', params)

@fire-eggs fire-eggs changed the title Support Danbooru "Common Search Parameters" ; at least 'page' Support Danbooru "Common Search Parameters" ; at least 'page' and 'limit' Nov 8, 2021
@LuqueDaniel LuqueDaniel added this to the Pybooru 5.0 milestone Dec 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants