From cea5eac9de8fa334279b97d8e71f674355e6d685 Mon Sep 17 00:00:00 2001 From: 0xb00bface <0xboobface@gmail.com> Date: Thu, 23 Dec 2021 13:43:27 +0100 Subject: [PATCH] Fix log message --- .../sites/mfc/HlsStreamSourceProvider.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/common/src/main/java/ctbrec/sites/mfc/HlsStreamSourceProvider.java b/common/src/main/java/ctbrec/sites/mfc/HlsStreamSourceProvider.java index 3b1ff192..01bf6e4a 100644 --- a/common/src/main/java/ctbrec/sites/mfc/HlsStreamSourceProvider.java +++ b/common/src/main/java/ctbrec/sites/mfc/HlsStreamSourceProvider.java @@ -7,6 +7,7 @@ import java.io.InputStream; import java.util.ArrayList; import java.util.List; import java.util.Locale; +import java.util.Objects; import java.util.concurrent.ExecutionException; import org.slf4j.Logger; @@ -29,14 +30,9 @@ import ctbrec.recorder.download.StreamSource; import okhttp3.Request; 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 HttpClient httpClient; - - public HlsStreamSourceProvider(HttpClient httpClient) { - this.httpClient = httpClient; - } @Override public List getStreamSources(String streamUrl) throws IOException, ExecutionException, ParseException, PlaylistException { @@ -46,7 +42,7 @@ public class HlsStreamSourceProvider implements StreamSourceProvider { if (playlist.hasStreamInfo()) { StreamSource src = new StreamSource(); src.bandwidth = playlist.getStreamInfo().getBandwidth(); - if(playlist.getStreamInfo().getResolution() != null) { + if (playlist.getStreamInfo().getResolution() != null) { src.width = playlist.getStreamInfo().getResolution().width; src.height = playlist.getStreamInfo().getResolution().height; } else { @@ -65,7 +61,7 @@ public class HlsStreamSourceProvider implements StreamSourceProvider { } private MasterPlaylist getMasterPlaylist(String streamUrl) throws IOException, ParseException, PlaylistException { - if(streamUrl == null) { + if (streamUrl == null) { throw new IllegalStateException("Stream url unknown"); } LOG.trace("Loading master playlist {}", streamUrl); @@ -80,13 +76,13 @@ public class HlsStreamSourceProvider implements StreamSourceProvider { .build(); try (Response response = httpClient.execute(req)) { 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); Playlist playlist = parser.parse(); MasterPlaylist master = playlist.getMasterPlaylist(); return master; } else { - throw new HttpException(response.code(), response.message() + " - Forbidden: " + streamUrl); + throw new HttpException(response.code(), response.message() + " - " + streamUrl); } } }