From cf5df3fcff4af0463e45844b570b0e4d9773e5bc Mon Sep 17 00:00:00 2001 From: litetex <40789489+litetex@users.noreply.github.com> Date: Tue, 11 Feb 2025 21:50:38 +0100 Subject: [PATCH] Improve rate limiting * Bandcamp also has rate-limiting (but a lot more req are allowed than with YT) * Shorten default warm up time * Fix typo --- .../ratelimiting/RateLimitedClientWrapper.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/extractor/src/test/java/org/schabi/newpipe/downloader/ratelimiting/RateLimitedClientWrapper.java b/extractor/src/test/java/org/schabi/newpipe/downloader/ratelimiting/RateLimitedClientWrapper.java index cea39d148..39899a090 100644 --- a/extractor/src/test/java/org/schabi/newpipe/downloader/ratelimiting/RateLimitedClientWrapper.java +++ b/extractor/src/test/java/org/schabi/newpipe/downloader/ratelimiting/RateLimitedClientWrapper.java @@ -21,7 +21,9 @@ public class RateLimitedClientWrapper { private static final int REQUEST_RATE_LIMITED_WAIT_MS = 5_000; private static final Map, RateLimiter> FORCED_RATE_LIMITERS = Map.ofEntries( Map.entry(host -> host.endsWith("youtube.com"), - RateLimiter.create(1.6, Duration.ofSeconds(1), 3.0)) + RateLimiter.create(1.6, Duration.ofSeconds(1))), + Map.entry(host -> host.endsWith("bandcamp.com"), + RateLimiter.create(2.5, Duration.ofSeconds(1))) ); private final OkHttpClient client; @@ -40,7 +42,7 @@ public class RateLimitedClientWrapper { .map(Map.Entry::getValue) .orElseGet(() -> // Default rate limiter per domain - RateLimiter.create(5, Duration.ofSeconds(5), 3.0))); + RateLimiter.create(5, Duration.ofSeconds(3)))); } public Response executeRequestWithLimit(final Request request) throws IOException { @@ -76,6 +78,7 @@ public class RateLimitedClientWrapper { Thread.currentThread().interrupt(); } } - throw new IllegalStateException("Retrying/Rate-limiting for " + request.url() + "failed", cause); + throw new IllegalStateException( + "Retrying/Rate-limiting for " + request.url() + " failed", cause); } }