From 7542da7cf51fe41f6d5a8259f5e4a46427a1e5fd Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sat, 30 Mar 2013 03:44:24 +0000 Subject: [PATCH] * respect anidb flood protection limits --- source/net/sourceforge/filebot/web/AnidbClient.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/source/net/sourceforge/filebot/web/AnidbClient.java b/source/net/sourceforge/filebot/web/AnidbClient.java index 19b9d6b6..7c389430 100644 --- a/source/net/sourceforge/filebot/web/AnidbClient.java +++ b/source/net/sourceforge/filebot/web/AnidbClient.java @@ -17,6 +17,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Scanner; import java.util.Set; +import java.util.concurrent.TimeUnit; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.zip.GZIPInputStream; @@ -32,6 +33,8 @@ import org.w3c.dom.Node; public class AnidbClient extends AbstractEpisodeListProvider { + private static final FloodLimit REQUEST_LIMIT = new FloodLimit(5, 12, TimeUnit.SECONDS); // no more than 5 requests within a 10 second window (+2 seconds for good measure) + private final String host = "anidb.net"; private final String client; @@ -102,6 +105,9 @@ public class AnidbClient extends AbstractEpisodeListProvider { // e.g. http://api.anidb.net:9001/httpapi?request=anime&client=filebot&clientver=1&protover=1&aid=4521 URL url = new URL("http", "api." + host, 9001, "/httpapi?request=anime&client=" + client + "&clientver=" + clientver + "&protover=1&aid=" + anime.getAnimeId()); + // respect flood protection limits + REQUEST_LIMIT.acquirePermit(); + // get anime page as xml Document dom = getDocument(url);