mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2024-08-14 23:51:41 +00:00
Fetch LBRY HLS stream.
This commit is contained in:
parent
f1ccd759ad
commit
d74d683615
2 changed files with 49 additions and 0 deletions
|
@ -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));
|
||||
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue