Fix LBRY timeouts.

This commit is contained in:
FireMaskterK 2021-11-09 08:06:13 +00:00
parent 3de3b55d3c
commit 1c8e8b190e
No known key found for this signature in database
GPG key ID: 49451E4482CC5BCD

View file

@ -116,7 +116,7 @@ public class ResponseHelper {
ExceptionUtils.rethrow(e);
}
return null;
});
}, Multithreading.getCachedExecutor());
CompletableFuture<String> futureLbryId = CompletableFuture.supplyAsync(() -> {
try {
@ -125,16 +125,20 @@ public class ResponseHelper {
ExceptionHandler.handle(e);
}
return null;
});
}, Multithreading.getCachedExecutor());
CompletableFuture<String> futureLBRY = CompletableFuture.supplyAsync(() -> {
try {
return getLBRYStreamURL(futureLbryId);
String lbryId = null;
lbryId = futureLbryId.completeOnTimeout(null, 2, TimeUnit.SECONDS).get();
return getLBRYStreamURL(lbryId);
} catch (Exception e) {
ExceptionHandler.handle(e);
}
return null;
});
}, Multithreading.getCachedExecutor());
final List<Subtitle> subtitles = new ObjectArrayList<>();
final List<ChapterSegment> chapters = new ObjectArrayList<>();
@ -157,7 +161,7 @@ public class ResponseHelper {
String lbryURL = null;
try {
lbryURL = futureLBRY.get(3, TimeUnit.SECONDS);
lbryURL = futureLBRY.completeOnTimeout(null, 3, TimeUnit.SECONDS).get();
} catch (Exception e) {
// ignored
}
@ -970,17 +974,10 @@ public class ResponseHelper {
.getJSONObject("data").getJSONObject("videos").optString(videoId);
}
private static final String getLBRYStreamURL(CompletableFuture<String> futureLbryId)
private static final String getLBRYStreamURL(String lbryId)
throws IOException, InterruptedException, ExecutionException {
String lbryId = "";
try {
lbryId = futureLbryId.get(2, TimeUnit.SECONDS);
} catch (Exception e) {
// ignored
}
if (!lbryId.isEmpty())
if (lbryId != null && !lbryId.isEmpty())
return new JSONObject(
Constants.h2client.send(
HttpRequest.newBuilder(URI.create("https://api.lbry.tv/api/v1/proxy?m=get"))