From 9dde3fe842f4c46cdc90908bc72c6aa7fc6f2aa0 Mon Sep 17 00:00:00 2001 From: 0xb00bface <0xboobface@gmail.com> Date: Fri, 1 Jan 2021 15:45:04 +0100 Subject: [PATCH] Allow 3 playlist download errors before stopping a recording --- .../recorder/download/hls/AbstractHlsDownload.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 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 db6d548a..e437eb4b 100644 --- a/common/src/main/java/ctbrec/recorder/download/hls/AbstractHlsDownload.java +++ b/common/src/main/java/ctbrec/recorder/download/hls/AbstractHlsDownload.java @@ -87,6 +87,7 @@ public abstract class AbstractHlsDownload extends AbstractDownload { private transient Instant afterLastPlaylistRequest= Instant.EPOCH; private transient Instant beforeLastPlaylistRequest= Instant.EPOCH; private transient int consecutivePlaylistTimeouts = 0; + private transient int consecutivePlaylistErrors = 0; protected Model model = new UnknownModel(); @@ -171,8 +172,10 @@ public abstract class AbstractHlsDownload extends AbstractDownload { } else if (e.getResponseCode() == 403) { checkIfModelIsStillOnline("Playlist access forbidden (403). Model {} probably went private or offline. Model state: {}"); } else { - LOG.info("Playlist couldn't not be downloaded for model {}. Stopping recording", model, e); - running = false; + if (consecutivePlaylistErrors >= 3) { + LOG.info("Playlist couldn't not be downloaded for model {}. Stopping recording", model, e); + running = false; + } } } @@ -243,7 +246,9 @@ public abstract class AbstractHlsDownload extends AbstractDownload { byte[] bytes = body.getBytes(UTF_8); BandwidthMeter.add(bytes.length); InputStream inputStream = new ByteArrayInputStream(bytes); - return parsePlaylist(segmentPlaylistUrl, inputStream); + SegmentPlaylist playList = parsePlaylist(segmentPlaylistUrl, inputStream); + consecutivePlaylistErrors = 0; + return playList; } else { throw new HttpException(response.code(), response.message()); } @@ -251,6 +256,9 @@ public abstract class AbstractHlsDownload extends AbstractDownload { LOG.debug("Playlist request timed out for model {} {} time{}", model, ++consecutivePlaylistTimeouts, (consecutivePlaylistTimeouts > 1) ? 's' : ""); // times out, return an empty playlist, so that the process can continue without wasting much more time throw new PlaylistTimeoutException(e); + } catch (Exception e) { + consecutivePlaylistErrors++; + throw e; } }