From d820d611f1e83032d5414c9a857fbcbcb9fbe88d Mon Sep 17 00:00:00 2001 From: 0xboobface <0xboobface@gmail.com> Date: Sat, 28 Dec 2019 16:59:20 +0100 Subject: [PATCH] Try to update the segment playlist URL, if loading the playlist fails --- .../download/hls/AbstractHlsDownload.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/common/src/main/java/ctbrec/recorder/download/hls/AbstractHlsDownload.java b/common/src/main/java/ctbrec/recorder/download/hls/AbstractHlsDownload.java index bcb32389..4ab69fe8 100644 --- a/common/src/main/java/ctbrec/recorder/download/hls/AbstractHlsDownload.java +++ b/common/src/main/java/ctbrec/recorder/download/hls/AbstractHlsDownload.java @@ -124,6 +124,9 @@ public abstract class AbstractHlsDownload extends AbstractDownload { } throw new InvalidPlaylistException("Playlist has no media playlist"); } else { + // update playlist url in case the streaming server has switched or something + LOG.debug("Loading segment playlist failed - trying to get a playlist URL"); + segmentsURL = getSegmentPlaylistUrl(getModel()); throw new HttpException(response.code(), response.message()); } } catch (Exception e) { @@ -148,27 +151,27 @@ public abstract class AbstractHlsDownload extends AbstractDownload { LOG.debug("{} src {}", model.getName(), streamSource); } String url = null; - if(model.getStreamUrlIndex() >= 0 && model.getStreamUrlIndex() < streamSources.size()) { + if (model.getStreamUrlIndex() >= 0 && model.getStreamUrlIndex() < streamSources.size()) { // TODO don't use the index, but the bandwidth. if the bandwidth does not match, take the closest one LOG.debug("{} selected {}", model.getName(), streamSources.get(model.getStreamUrlIndex())); url = streamSources.get(model.getStreamUrlIndex()).getMediaPlaylistUrl(); } else { // filter out stream resolutions, which are too high int maxRes = Config.getInstance().getSettings().maximumResolution; - if(maxRes > 0) { + if (maxRes > 0) { for (Iterator iterator = streamSources.iterator(); iterator.hasNext();) { StreamSource streamSource = iterator.next(); - if(streamSource.height > 0 && maxRes < streamSource.height) { + if (streamSource.height > 0 && maxRes < streamSource.height) { LOG.trace("Res too high {} > {}", streamSource.height, maxRes); iterator.remove(); } } } - if(streamSources.isEmpty()) { + if (streamSources.isEmpty()) { throw new ExecutionException(new RuntimeException("No stream left in playlist")); } else { - LOG.debug("{} selected {}", model.getName(), streamSources.get(streamSources.size()-1)); - url = streamSources.get(streamSources.size()-1).getMediaPlaylistUrl(); + LOG.debug("{} selected {}", model.getName(), streamSources.get(streamSources.size() - 1)); + url = streamSources.get(streamSources.size() - 1).getMediaPlaylistUrl(); } } LOG.debug("Segment playlist url {}", url);