From 4946d0161ad4fbaec60bc1e524ad95cd837847fa Mon Sep 17 00:00:00 2001 From: 0xb00bface <0xboobface@gmail.com> Date: Sun, 8 Aug 2021 12:57:57 +0200 Subject: [PATCH] Improve error handling for playlist errors 403 and 404 --- CHANGELOG.md | 2 ++ .../download/hls/AbstractHlsDownload.java | 35 +++++++++++-------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb5b4643..be1c2f5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,8 +5,10 @@ * Added Chaturbate configuration parameter to throttle requests to avoid 429 errors. Be aware that this also slows down the online check for Chaturbate models, especially, if you have a lot of models in your list. + You have to play around a bit to find a value, which works for you. * Fixed ConcurrentModificationException, which caused the recorded models tab to turn blank +* Fixed recordings not stopping, if playlist requests returned 403 or 404 4.4.3 ======================== 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 c1578162..ab10fd53 100644 --- a/common/src/main/java/ctbrec/recorder/download/hls/AbstractHlsDownload.java +++ b/common/src/main/java/ctbrec/recorder/download/hls/AbstractHlsDownload.java @@ -71,7 +71,7 @@ import okhttp3.Response; public abstract class AbstractHlsDownload extends AbstractDownload { private static final transient Logger LOG = LoggerFactory.getLogger(AbstractHlsDownload.class); - private static final int TEN_SECONDS = 10_000; + private static final int A_FEW_SECONDS = 10_000; private transient NumberFormat nf = new DecimalFormat("000000"); private transient int playlistEmptyCount = 0; @@ -144,6 +144,10 @@ public abstract class AbstractHlsDownload extends AbstractDownload { } catch (Exception e) { LOG.error("Couldn't download segment for model {}", model, e); stop(); + } finally { + if (consecutivePlaylistErrors > 0) { + LOG.debug("Consecutive playlist errors: {}", consecutivePlaylistErrors); + } } return this; } @@ -163,17 +167,17 @@ public abstract class AbstractHlsDownload extends AbstractDownload { } protected void handleHttpException(HttpException e) throws IOException { + consecutivePlaylistErrors++; if (e.getResponseCode() == 404) { checkIfModelIsStillOnline("Playlist not found (404). Model {} probably went offline. Model state: {}"); } else if (e.getResponseCode() == 403) { checkIfModelIsStillOnline("Playlist access forbidden (403). Model {} probably went private or offline. Model state: {}"); + } + if (consecutivePlaylistErrors >= 3) { + LOG.info("Playlist couldn't not be downloaded for model {} {} times. Stopping recording", model, consecutivePlaylistErrors, e); + stop(); } else { - if (consecutivePlaylistErrors >= 3) { - LOG.info("Playlist couldn't not be downloaded for model {} {} times. Stopping recording", model, (consecutivePlaylistErrors + 1), e); - stop(); - } else { - LOG.info("Playlist couldn't not be downloaded for model {} {} times: {}", model, (consecutivePlaylistErrors + 1), e.getLocalizedMessage()); - } + LOG.info("Playlist couldn't not be downloaded for model {} {} times: {}", model, consecutivePlaylistErrors, e.getLocalizedMessage()); } } @@ -181,17 +185,21 @@ public abstract class AbstractHlsDownload extends AbstractDownload { ctbrec.Model.State modelState; try { modelState = model.getOnlineState(false); - if (modelState == State.ONLINE) { - segmentPlaylistUrl = getSegmentPlaylistUrl(model); - waitSomeTime(TEN_SECONDS); - } } catch (Exception e1) { modelState = State.UNKNOWN; } + LOG.info(errorMsg, model, modelState); if (modelState != State.ONLINE) { stop(); + return; + } + try { + LOG.debug("Trying to update playlist URL after waiting {}ms", A_FEW_SECONDS); + waitSomeTime(A_FEW_SECONDS); + segmentPlaylistUrl = getSegmentPlaylistUrl(model); + } catch (Exception e) { + LOG.error("Playlist URL couldn't be updated after waiting for {}ms", A_FEW_SECONDS, e); } - LOG.info(errorMsg, model, modelState); } protected String getSegmentPlaylistUrl(Model model) throws IOException, ExecutionException, ParseException, PlaylistException, JAXBException { @@ -230,8 +238,7 @@ public abstract class AbstractHlsDownload extends AbstractDownload { Instant start = Instant.now(); recordingEvents.add(RecordingEvent.of("Playlist request")); URL segmentsUrl = new URL(segmentPlaylistUrl); - Builder builder = new Request.Builder() - .url(segmentsUrl); + Builder builder = new Request.Builder().url(segmentsUrl); addHeaders(builder, Optional.ofNullable(model).map(Model::getHttpHeaderFactory).map(HttpHeaderFactory::createSegmentPlaylistHeaders).orElse(new HashMap<>()), model); Request request = builder.build();