Fix log message
This commit is contained in:
parent
fafd9268e7
commit
cea5eac9de
|
@ -7,6 +7,7 @@ import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -29,14 +30,9 @@ import ctbrec.recorder.download.StreamSource;
|
||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
|
|
||||||
public class HlsStreamSourceProvider implements StreamSourceProvider {
|
public record HlsStreamSourceProvider(HttpClient httpClient) implements StreamSourceProvider {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(HlsStreamSourceProvider.class);
|
private static final Logger LOG = LoggerFactory.getLogger(HlsStreamSourceProvider.class);
|
||||||
private HttpClient httpClient;
|
|
||||||
|
|
||||||
public HlsStreamSourceProvider(HttpClient httpClient) {
|
|
||||||
this.httpClient = httpClient;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<StreamSource> getStreamSources(String streamUrl) throws IOException, ExecutionException, ParseException, PlaylistException {
|
public List<StreamSource> getStreamSources(String streamUrl) throws IOException, ExecutionException, ParseException, PlaylistException {
|
||||||
|
@ -46,7 +42,7 @@ public class HlsStreamSourceProvider implements StreamSourceProvider {
|
||||||
if (playlist.hasStreamInfo()) {
|
if (playlist.hasStreamInfo()) {
|
||||||
StreamSource src = new StreamSource();
|
StreamSource src = new StreamSource();
|
||||||
src.bandwidth = playlist.getStreamInfo().getBandwidth();
|
src.bandwidth = playlist.getStreamInfo().getBandwidth();
|
||||||
if(playlist.getStreamInfo().getResolution() != null) {
|
if (playlist.getStreamInfo().getResolution() != null) {
|
||||||
src.width = playlist.getStreamInfo().getResolution().width;
|
src.width = playlist.getStreamInfo().getResolution().width;
|
||||||
src.height = playlist.getStreamInfo().getResolution().height;
|
src.height = playlist.getStreamInfo().getResolution().height;
|
||||||
} else {
|
} else {
|
||||||
|
@ -65,7 +61,7 @@ public class HlsStreamSourceProvider implements StreamSourceProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
private MasterPlaylist getMasterPlaylist(String streamUrl) throws IOException, ParseException, PlaylistException {
|
private MasterPlaylist getMasterPlaylist(String streamUrl) throws IOException, ParseException, PlaylistException {
|
||||||
if(streamUrl == null) {
|
if (streamUrl == null) {
|
||||||
throw new IllegalStateException("Stream url unknown");
|
throw new IllegalStateException("Stream url unknown");
|
||||||
}
|
}
|
||||||
LOG.trace("Loading master playlist {}", streamUrl);
|
LOG.trace("Loading master playlist {}", streamUrl);
|
||||||
|
@ -80,13 +76,13 @@ public class HlsStreamSourceProvider implements StreamSourceProvider {
|
||||||
.build();
|
.build();
|
||||||
try (Response response = httpClient.execute(req)) {
|
try (Response response = httpClient.execute(req)) {
|
||||||
if (response.isSuccessful()) {
|
if (response.isSuccessful()) {
|
||||||
InputStream inputStream = response.body().byteStream();
|
InputStream inputStream = Objects.requireNonNull(response.body(), "HTTP response is null").byteStream();
|
||||||
PlaylistParser parser = new PlaylistParser(inputStream, Format.EXT_M3U, Encoding.UTF_8, ParsingMode.LENIENT);
|
PlaylistParser parser = new PlaylistParser(inputStream, Format.EXT_M3U, Encoding.UTF_8, ParsingMode.LENIENT);
|
||||||
Playlist playlist = parser.parse();
|
Playlist playlist = parser.parse();
|
||||||
MasterPlaylist master = playlist.getMasterPlaylist();
|
MasterPlaylist master = playlist.getMasterPlaylist();
|
||||||
return master;
|
return master;
|
||||||
} else {
|
} else {
|
||||||
throw new HttpException(response.code(), response.message() + " - Forbidden: " + streamUrl);
|
throw new HttpException(response.code(), response.message() + " - " + streamUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue