mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2024-08-14 23:51:41 +00:00
Fix LBRY timeouts.
This commit is contained in:
parent
3de3b55d3c
commit
1c8e8b190e
1 changed files with 11 additions and 14 deletions
|
@ -116,7 +116,7 @@ public class ResponseHelper {
|
||||||
ExceptionUtils.rethrow(e);
|
ExceptionUtils.rethrow(e);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
});
|
}, Multithreading.getCachedExecutor());
|
||||||
|
|
||||||
CompletableFuture<String> futureLbryId = CompletableFuture.supplyAsync(() -> {
|
CompletableFuture<String> futureLbryId = CompletableFuture.supplyAsync(() -> {
|
||||||
try {
|
try {
|
||||||
|
@ -125,16 +125,20 @@ public class ResponseHelper {
|
||||||
ExceptionHandler.handle(e);
|
ExceptionHandler.handle(e);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
});
|
}, Multithreading.getCachedExecutor());
|
||||||
|
|
||||||
CompletableFuture<String> futureLBRY = CompletableFuture.supplyAsync(() -> {
|
CompletableFuture<String> futureLBRY = CompletableFuture.supplyAsync(() -> {
|
||||||
try {
|
try {
|
||||||
return getLBRYStreamURL(futureLbryId);
|
String lbryId = null;
|
||||||
|
|
||||||
|
lbryId = futureLbryId.completeOnTimeout(null, 2, TimeUnit.SECONDS).get();
|
||||||
|
|
||||||
|
return getLBRYStreamURL(lbryId);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ExceptionHandler.handle(e);
|
ExceptionHandler.handle(e);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
});
|
}, Multithreading.getCachedExecutor());
|
||||||
|
|
||||||
final List<Subtitle> subtitles = new ObjectArrayList<>();
|
final List<Subtitle> subtitles = new ObjectArrayList<>();
|
||||||
final List<ChapterSegment> chapters = new ObjectArrayList<>();
|
final List<ChapterSegment> chapters = new ObjectArrayList<>();
|
||||||
|
@ -157,7 +161,7 @@ public class ResponseHelper {
|
||||||
String lbryURL = null;
|
String lbryURL = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
lbryURL = futureLBRY.get(3, TimeUnit.SECONDS);
|
lbryURL = futureLBRY.completeOnTimeout(null, 3, TimeUnit.SECONDS).get();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// ignored
|
// ignored
|
||||||
}
|
}
|
||||||
|
@ -970,17 +974,10 @@ public class ResponseHelper {
|
||||||
.getJSONObject("data").getJSONObject("videos").optString(videoId);
|
.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 {
|
throws IOException, InterruptedException, ExecutionException {
|
||||||
|
|
||||||
String lbryId = "";
|
if (lbryId != null && !lbryId.isEmpty())
|
||||||
try {
|
|
||||||
lbryId = futureLbryId.get(2, TimeUnit.SECONDS);
|
|
||||||
} catch (Exception e) {
|
|
||||||
// ignored
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!lbryId.isEmpty())
|
|
||||||
return new JSONObject(
|
return new JSONObject(
|
||||||
Constants.h2client.send(
|
Constants.h2client.send(
|
||||||
HttpRequest.newBuilder(URI.create("https://api.lbry.tv/api/v1/proxy?m=get"))
|
HttpRequest.newBuilder(URI.create("https://api.lbry.tv/api/v1/proxy?m=get"))
|
||||||
|
|
Loading…
Reference in a new issue