Kylart / Nyaapi

Non-official api to access Nyaa.si and Nyaa.pantsu.cat (search, upload,...)
MIT License
108 stars 17 forks source link

nyaa returns 403, DDoS protection #5

Closed Fodark closed 5 years ago

Fodark commented 5 years ago

Nyaa.si implemented a DDoS protection system, which most of the times blocks requests from your package. Sometimes they get through and I get a response but even if I wait 6 seconds between each call (usually I make 6 calls totally in my application) they're blocked. I don't know if it a matter of user-agent.

I hope the project is still active!

Kylart commented 5 years ago

Yes it is!

What is your usecase? What are you 6 calls like?

I can't really do anything concerning that limit, nyaa.si does not offer any official API nor documentation for theirs, all we can do is optimize our logic to reduce the number of calls. 😢

Fodark commented 5 years ago

Thank you for your reply!

I'll start saying that today I'm not having this problem, the calls respond successfully, weird.

I wrote a program to check if the latest episode of the seasonal animes I follow was released on nyaa, so I have a call for each one (they're six) delayed by setInterval, the relevant pieces of code are these:

setInterval(() => {
    let name = anime[i]
    searchAnime(i++, name, info[name])
}, 6000)

And in searchAnime function:

si.search('[HorribleSubs] ' + name, 20, { category: '1_2' })
    .then(data => {
        ...
    }

So I cannot really reduce the number of calls...

Since today it has no problem I'm wondering if it was a temporary problem of mine with my line

Kylart commented 5 years ago

Actually you can do all that in only one request!

The Help section shows how to use the nyaa.si search engine. nyaapi does respect this so you can do this for example:

const { si } = require('nyaapi')

si.search('([HorribleSubs]) "Sakura Trick"|"Made in Abyss"')
  .then(console.log)
  .catch(console.error)

This will give these results.

Fodark commented 5 years ago

Sorry for my late reply, I'll look how to implement this in my program! Thank you for your time!

Kylart commented 5 years ago

No problem, feel free to update this issue whenever you tried this 😄