Allow 3 playlist download errors before stopping a recording

This commit is contained in:
0xb00bface 2021-01-01 15:45:04 +01:00
parent a1a5fbc3a6
commit 9dde3fe842
1 changed files with 11 additions and 3 deletions

View File

@ -87,6 +87,7 @@ public abstract class AbstractHlsDownload extends AbstractDownload {
private transient Instant afterLastPlaylistRequest= Instant.EPOCH; private transient Instant afterLastPlaylistRequest= Instant.EPOCH;
private transient Instant beforeLastPlaylistRequest= Instant.EPOCH; private transient Instant beforeLastPlaylistRequest= Instant.EPOCH;
private transient int consecutivePlaylistTimeouts = 0; private transient int consecutivePlaylistTimeouts = 0;
private transient int consecutivePlaylistErrors = 0;
protected Model model = new UnknownModel(); protected Model model = new UnknownModel();
@ -171,10 +172,12 @@ public abstract class AbstractHlsDownload extends AbstractDownload {
} else if (e.getResponseCode() == 403) { } else if (e.getResponseCode() == 403) {
checkIfModelIsStillOnline("Playlist access forbidden (403). Model {} probably went private or offline. Model state: {}"); checkIfModelIsStillOnline("Playlist access forbidden (403). Model {} probably went private or offline. Model state: {}");
} else { } else {
if (consecutivePlaylistErrors >= 3) {
LOG.info("Playlist couldn't not be downloaded for model {}. Stopping recording", model, e); LOG.info("Playlist couldn't not be downloaded for model {}. Stopping recording", model, e);
running = false; running = false;
} }
} }
}
protected void checkIfModelIsStillOnline(String errorMsg) throws IOException { protected void checkIfModelIsStillOnline(String errorMsg) throws IOException {
ctbrec.Model.State modelState; ctbrec.Model.State modelState;
@ -243,7 +246,9 @@ public abstract class AbstractHlsDownload extends AbstractDownload {
byte[] bytes = body.getBytes(UTF_8); byte[] bytes = body.getBytes(UTF_8);
BandwidthMeter.add(bytes.length); BandwidthMeter.add(bytes.length);
InputStream inputStream = new ByteArrayInputStream(bytes); InputStream inputStream = new ByteArrayInputStream(bytes);
return parsePlaylist(segmentPlaylistUrl, inputStream); SegmentPlaylist playList = parsePlaylist(segmentPlaylistUrl, inputStream);
consecutivePlaylistErrors = 0;
return playList;
} else { } else {
throw new HttpException(response.code(), response.message()); 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' : ""); 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 // times out, return an empty playlist, so that the process can continue without wasting much more time
throw new PlaylistTimeoutException(e); throw new PlaylistTimeoutException(e);
} catch (Exception e) {
consecutivePlaylistErrors++;
throw e;
} }
} }