Skip to content

Commit cf5df3f

Browse files
committed
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
1 parent 287123b commit cf5df3f

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

extractor/src/test/java/org/schabi/newpipe/downloader/ratelimiting/RateLimitedClientWrapper.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ public class RateLimitedClientWrapper {
2121
private static final int REQUEST_RATE_LIMITED_WAIT_MS = 5_000;
2222
private static final Map<Predicate<String>, RateLimiter> FORCED_RATE_LIMITERS = Map.ofEntries(
2323
Map.entry(host -> host.endsWith("youtube.com"),
24-
RateLimiter.create(1.6, Duration.ofSeconds(1), 3.0))
24+
RateLimiter.create(1.6, Duration.ofSeconds(1))),
25+
Map.entry(host -> host.endsWith("bandcamp.com"),
26+
RateLimiter.create(2.5, Duration.ofSeconds(1)))
2527
);
2628

2729
private final OkHttpClient client;
@@ -40,7 +42,7 @@ protected RateLimiter getRateLimiterFor(final Request request) {
4042
.map(Map.Entry::getValue)
4143
.orElseGet(() ->
4244
// Default rate limiter per domain
43-
RateLimiter.create(5, Duration.ofSeconds(5), 3.0)));
45+
RateLimiter.create(5, Duration.ofSeconds(3))));
4446
}
4547

4648
public Response executeRequestWithLimit(final Request request) throws IOException {
@@ -76,6 +78,7 @@ public Response executeRequestWithLimit(final Request request) throws IOExceptio
7678
Thread.currentThread().interrupt();
7779
}
7880
}
79-
throw new IllegalStateException("Retrying/Rate-limiting for " + request.url() + "failed", cause);
81+
throw new IllegalStateException(
82+
"Retrying/Rate-limiting for " + request.url() + " failed", cause);
8083
}
8184
}

0 commit comments

Comments
 (0)