mirror of
https://github.com/TeamNewPipe/NewPipeExtractor.git
synced 2025-04-27 23:40:36 +05:30
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
This commit is contained in:
parent
287123b0fd
commit
cf5df3fcff
@ -21,7 +21,9 @@ public class RateLimitedClientWrapper {
|
|||||||
private static final int REQUEST_RATE_LIMITED_WAIT_MS = 5_000;
|
private static final int REQUEST_RATE_LIMITED_WAIT_MS = 5_000;
|
||||||
private static final Map<Predicate<String>, RateLimiter> FORCED_RATE_LIMITERS = Map.ofEntries(
|
private static final Map<Predicate<String>, RateLimiter> FORCED_RATE_LIMITERS = Map.ofEntries(
|
||||||
Map.entry(host -> host.endsWith("youtube.com"),
|
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;
|
private final OkHttpClient client;
|
||||||
@ -40,7 +42,7 @@ public class RateLimitedClientWrapper {
|
|||||||
.map(Map.Entry::getValue)
|
.map(Map.Entry::getValue)
|
||||||
.orElseGet(() ->
|
.orElseGet(() ->
|
||||||
// Default rate limiter per domain
|
// 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 {
|
public Response executeRequestWithLimit(final Request request) throws IOException {
|
||||||
@ -76,6 +78,7 @@ public class RateLimitedClientWrapper {
|
|||||||
Thread.currentThread().interrupt();
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user