reduced the timeout for requesting video segments
from the default 30 to 3
This commit is contained in:
parent
d80013ee48
commit
baba2032a3
2 changed files with 29 additions and 2 deletions
|
@ -52,6 +52,7 @@ public final class DownloaderImpl extends Downloader {
|
|||
private static DownloaderImpl instance;
|
||||
private final Map<String, String> mCookies;
|
||||
private final OkHttpClient client;
|
||||
private Integer customTimeout;
|
||||
|
||||
private DownloaderImpl(final OkHttpClient.Builder builder) {
|
||||
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
|
||||
|
@ -130,6 +131,11 @@ public final class DownloaderImpl extends Downloader {
|
|||
}
|
||||
}
|
||||
|
||||
public DownloaderImpl setCustomTimeout(final Integer value) {
|
||||
this.customTimeout = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getCookies(final String url) {
|
||||
final List<String> resultCookies = new ArrayList<>();
|
||||
if (url.contains(YOUTUBE_DOMAIN)) {
|
||||
|
@ -205,7 +211,18 @@ public final class DownloaderImpl extends Downloader {
|
|||
}
|
||||
|
||||
final okhttp3.Request request = requestBuilder.build();
|
||||
final okhttp3.Response response = client.newCall(request).execute();
|
||||
|
||||
OkHttpClient tmpClient = client;
|
||||
final okhttp3.Response response;
|
||||
|
||||
if (customTimeout != null) {
|
||||
tmpClient = new OkHttpClient.Builder()
|
||||
.readTimeout(customTimeout, TimeUnit.SECONDS)
|
||||
.build();
|
||||
}
|
||||
|
||||
response = tmpClient.newCall(request).execute();
|
||||
|
||||
final ResponseBody body = response.body();
|
||||
|
||||
if (response.code() == 429) {
|
||||
|
@ -260,7 +277,16 @@ public final class DownloaderImpl extends Downloader {
|
|||
|
||||
}
|
||||
|
||||
final okhttp3.Response response = client.newCall(requestBuilder.build()).execute();
|
||||
OkHttpClient tmpClient = client;
|
||||
final okhttp3.Response response;
|
||||
|
||||
if (customTimeout != null) {
|
||||
tmpClient = new OkHttpClient.Builder()
|
||||
.readTimeout(customTimeout, TimeUnit.SECONDS)
|
||||
.build();
|
||||
}
|
||||
|
||||
response = tmpClient.newCall(requestBuilder.build()).execute();
|
||||
|
||||
if (response.code() == 429) {
|
||||
response.close();
|
||||
|
|
|
@ -115,6 +115,7 @@ public final class SponsorBlockUtils {
|
|||
final String responseBody =
|
||||
DownloaderImpl
|
||||
.getInstance()
|
||||
.setCustomTimeout(3)
|
||||
.get(apiUrl + params)
|
||||
.responseBody();
|
||||
|
||||
|
|
Loading…
Reference in a new issue