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

Received HTTP 422 from booru: 'PostQuery::TagLimitError' #87

Open
Hatsune-Mikun opened this issue May 29, 2022 · 9 comments
Open

Received HTTP 422 from booru: 'PostQuery::TagLimitError' #87

Hatsune-Mikun opened this issue May 29, 2022 · 9 comments
Assignees

Comments

@Hatsune-Mikun
Copy link

Hello! It's me, again c:

I got this error while trying to get 1 post from danbooru with tags: angel, white_hair, rating:safe
image

await Booru.search(site, tag, { limit: 1, random: true }).then(posts => posts[0])

I guess isn't your issue, is it API, but anyway, can you recommend something or do with this?

@AtoraSuunva
Copy link
Owner

Using random: true will make booru add order:random to the tags before searching, so you'd have to disable random (random: false) and select a random result yourself

https://github.com/AtoraSuunva/booru/blob/master/src/boorus/Booru.ts#L166=

I could add a fakeRandom option that would use the same logic for boorus that don't support order:random (fetch 100 results, then sort them randomly)

@Hatsune-Mikun
Copy link
Author

Sounds like a good solution to create a minor update

But doesn't danbooru support random? It always worked with a large number of tags and randomly before, the problem arose only on these tags, which was shocking for me, so i'm here

@Skitteyy
Copy link

So is this gonna be a thing or not?

@AtoraSuunva
Copy link
Owner

@Hatsune-Mikun danbooru does support order:random, but it seems to make the database time out often for some reason

Danbooru also does not let you search using more than 2 tags unless you have a paid account

@Skitteyy I was planning to add it in to the rewrite of booru, but I've been busy updating my other code first

If you have a use for this right now I can try adding it in

@Hatsune-Mikun
Copy link
Author

I take a big break on programming because depression, so you can make it when it gonna be comfortable for you, and i just update it after, i will use you library anyway

@Skitteyy
Copy link

Ah I see. No worries

@Skitteyy
Copy link

Skitteyy commented Aug 14, 2023

Well I don't know if anything will happen but I use booru for my discord bot and I found out that you can put a limit of 100 when you search with 2 tags and then put something like
"const random = Math.floor(Math.random() * 100) +1"
and then put image.posts[random].file_url instead which will get you a random post of 100, but it sometimes just says
"Cannot read properties of undefined (reading 'file_url')".

Seems to also error sometimes when searching with only one tag

@AtoraSuunva
Copy link
Owner

@Skitteyy You're probably searching tags that have less than 100 results, which then makes random go out of bounds and you get undefined

You'll need to generate a random number based on the number of search results:

const random = Math.floor(Math.random() * post.images.length)
const image = post.images[random]

@Skitteyy
Copy link

I see, works perfectly, thanks

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

3 participants