hls fix
This commit is contained in:
parent
87925a57de
commit
1659298aff
@ -268,7 +268,7 @@ public final class XtreamPlayerApplication {
|
||||
return;
|
||||
}
|
||||
attemptErrors.add(maskUri(candidate) + " -> " + compactError(candidateException));
|
||||
LOGGER.warn("Stream proxy candidate failed uri={}", maskUri(candidate), candidateException);
|
||||
LOGGER.warn("Stream proxy candidate failed uri={} reason={}", maskUri(candidate), compactError(candidateException));
|
||||
}
|
||||
}
|
||||
if (response == null) {
|
||||
@ -858,9 +858,10 @@ public final class XtreamPlayerApplication {
|
||||
));
|
||||
copyRequestHeaderIfPresent(exchange, requestBuilder, "Range");
|
||||
copyRequestHeaderIfPresent(exchange, requestBuilder, "If-Range");
|
||||
if (sourceUrl != null && !sourceUrl.isBlank()) {
|
||||
requestBuilder.header("Referer", sourceUrl);
|
||||
String origin = originFromUrl(sourceUrl);
|
||||
String referer = resolveRefererForCandidate(candidate, sourceUrl);
|
||||
if (!referer.isBlank()) {
|
||||
requestBuilder.header("Referer", referer);
|
||||
String origin = originFromUrl(referer);
|
||||
if (!origin.isBlank()) {
|
||||
requestBuilder.header("Origin", origin);
|
||||
}
|
||||
@ -869,6 +870,32 @@ public final class XtreamPlayerApplication {
|
||||
return HTTP_CLIENT.send(request, HttpResponse.BodyHandlers.ofByteArray());
|
||||
}
|
||||
|
||||
private static String resolveRefererForCandidate(URI candidate, String sourceUrl) {
|
||||
URI candidateDir = directoryUri(candidate);
|
||||
if (candidateDir != null) {
|
||||
String path = candidateDir.getPath() == null ? "" : candidateDir.getPath().toLowerCase(Locale.ROOT);
|
||||
if (path.contains("/hls/")) {
|
||||
return candidateDir.toString();
|
||||
}
|
||||
}
|
||||
if (sourceUrl != null && !sourceUrl.isBlank()) {
|
||||
return sourceUrl;
|
||||
}
|
||||
return candidateDir == null ? "" : candidateDir.toString();
|
||||
}
|
||||
|
||||
private static URI directoryUri(URI uri) {
|
||||
if (uri == null || uri.getScheme() == null || uri.getRawAuthority() == null) {
|
||||
return null;
|
||||
}
|
||||
String path = uri.getPath() == null ? "" : uri.getPath();
|
||||
int slash = path.lastIndexOf('/');
|
||||
String dirPath = slash >= 0 ? path.substring(0, slash + 1) : "/";
|
||||
String query = uri.getRawQuery();
|
||||
return URI.create(uri.getScheme() + "://" + uri.getRawAuthority() + dirPath
|
||||
+ (query == null ? "" : "?" + query));
|
||||
}
|
||||
|
||||
private static String pathBasename(URI uri) {
|
||||
String path = uri == null || uri.getPath() == null ? "" : uri.getPath();
|
||||
int index = path.lastIndexOf('/');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user