Merge pull request #536 from TeamPiped/lbry-hls

Fetch LBRY HLS stream separately
This commit is contained in:
Kavin 2023-02-27 11:43:08 +00:00 committed by GitHub
commit 460bdb274e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 0 deletions

View File

@ -94,6 +94,25 @@ public class StreamHandlers {
return null;
});
final var futureLBRYHls = Multithreading.supplyAsync(() -> {
Sentry.setExtra("videoId", videoId);
ITransaction transaction = Sentry.startTransaction("LBRY HLS fetch", "fetch");
try {
var childTask = transaction.startChild("fetch", "LBRY Stream URL fetch");
String lbryUrl = futureLBRY.get(2, TimeUnit.SECONDS);
Sentry.setExtra("lbryUrl", lbryUrl);
childTask.finish();
return LbryHelper.getLBRYHlsUrl(lbryUrl);
} catch (TimeoutException ignored) {
} catch (Exception e) {
ExceptionHandler.handle(e);
} finally {
transaction.finish();
}
return null;
});
final var futureDislikeRating = Multithreading.supplyAsync(() -> {
Sentry.setExtra("videoId", videoId);
ITransaction transaction = Sentry.startTransaction("Dislike Rating", "fetch");
@ -232,6 +251,17 @@ public class StreamHandlers {
// ignored
}
String lbryHlsURL = null;
try {
lbryHlsURL = futureLBRYHls.get(4, TimeUnit.SECONDS);
} catch (Exception e) {
// ignored
}
if (lbryHlsURL != null)
streams.videoStreams.add(0, new PipedStream(lbryHlsURL, "HLS", "LBRY HLS", "application/x-mpegurl", false));
if (lbryURL != null)
streams.videoStreams.add(0, new PipedStream(lbryURL, "MP4", "LBRY", "video/mp4", false));

View File

@ -1,6 +1,7 @@
package me.kavin.piped.utils;
import me.kavin.piped.consts.Constants;
import okhttp3.Request;
import org.apache.commons.lang3.StringUtils;
import rocks.kavin.reqwest4j.ReqwestUtils;
@ -49,4 +50,22 @@ public class LbryHelper {
return null;
}
public static String getLBRYHlsUrl(String streamUrl) throws Exception {
try (var resp = Constants.h2_no_redir_client
.newCall(
new Request.Builder()
.url(streamUrl)
.method("HEAD", null)
.header("User-Agent", Constants.USER_AGENT)
.header("Origin", "https://odysee.com")
.header("Referer", "https://odysee.com/")
.build()
)
.execute()) {
return resp.header("Location");
}
}
}