Apply preprocessing into HLS stream

This commit is contained in:
2025-10-22 01:14:05 +05:00
parent 7c85e05e02
commit ea3eb33e8d
14 changed files with 505 additions and 40 deletions

View File

@ -27,19 +27,22 @@ public class FetchService {
* @throws FetchFailException
*/
@Cacheable("hlsPlaylistContent")
public String fetchTextContent(String url) throws IOException, InterruptedException, FetchFailException {
public String fetchTextContent(String url) throws FetchFailException {
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.build();
HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() != 200) {
throw new FetchFailException("Failed to fetch content from " + url + ", status: " + response.statusCode(),
response);
try {
HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() != 200) {
throw new FetchFailException(
"Failed to fetch content from " + url + ", status: " + response.statusCode(),
response);
}
return response.body();
} catch (IOException | InterruptedException e) {
throw new FetchFailException("Failed to fetch content from " + url, e);
}
return response.body();
}
/**
@ -48,8 +51,7 @@ public class FetchService {
* @throws FetchFailException
*/
@Cacheable("playlistSegmentContent")
public SimpleResponse<byte[]> fetchBinaryContent(String url)
throws IOException, InterruptedException, FetchFailException {
public SimpleResponse<byte[]> fetchBinaryContent(String url) throws FetchFailException {
return fetchBinaryContent(url, null);
}
@ -60,7 +62,7 @@ public class FetchService {
*/
@Cacheable("playlistSegmentContent")
public SimpleResponse<byte[]> fetchBinaryContent(String url, String rangeHeader)
throws IOException, InterruptedException, FetchFailException {
throws FetchFailException {
HttpRequest.Builder builder = HttpRequest.newBuilder()
.uri(URI.create(url));
@ -68,14 +70,20 @@ public class FetchService {
builder.header("Range", rangeHeader);
}
HttpResponse<byte[]> response = httpClient.send(builder.build(), HttpResponse.BodyHandlers.ofByteArray());
try {
if (response.statusCode() >= 400) {
throw new FetchFailException("Failed to fetch content from " + url + ", status: " + response.statusCode(),
response);
HttpResponse<byte[]> response = httpClient.send(builder.build(), HttpResponse.BodyHandlers.ofByteArray());
if (response.statusCode() >= 400) {
throw new FetchFailException(
"Failed to fetch content from " + url + ", status: " + response.statusCode(),
response);
}
return new SimpleResponse<byte[]>(response.body(), response.headers());
} catch (IOException | InterruptedException e) {
throw new FetchFailException("Failed to fetch content from " + url, e);
}
return new SimpleResponse<byte[]>(response.body(), response.headers());
}
/**