Fetch LBRY HLS stream.

This commit is contained in:
Kavin 2023-02-27 11:41:06 +00:00
parent f1ccd759ad
commit d74d683615
No known key found for this signature in database
GPG key ID: 49451E4482CC5BCD
2 changed files with 49 additions and 0 deletions

View file

@ -94,6 +94,25 @@ public class StreamHandlers {
return null; 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(() -> { final var futureDislikeRating = Multithreading.supplyAsync(() -> {
Sentry.setExtra("videoId", videoId); Sentry.setExtra("videoId", videoId);
ITransaction transaction = Sentry.startTransaction("Dislike Rating", "fetch"); ITransaction transaction = Sentry.startTransaction("Dislike Rating", "fetch");
@ -232,6 +251,17 @@ public class StreamHandlers {
// ignored // 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) if (lbryURL != null)
streams.videoStreams.add(0, new PipedStream(lbryURL, "MP4", "LBRY", "video/mp4", false)); streams.videoStreams.add(0, new PipedStream(lbryURL, "MP4", "LBRY", "video/mp4", false));

View file

@ -1,6 +1,7 @@
package me.kavin.piped.utils; package me.kavin.piped.utils;
import me.kavin.piped.consts.Constants; import me.kavin.piped.consts.Constants;
import okhttp3.Request;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import rocks.kavin.reqwest4j.ReqwestUtils; import rocks.kavin.reqwest4j.ReqwestUtils;
@ -49,4 +50,22 @@ public class LbryHelper {
return null; 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");
}
}
} }