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 16cd935f..d14c17b6 100644 --- a/common/src/main/java/ctbrec/recorder/download/hls/AbstractHlsDownload.java +++ b/common/src/main/java/ctbrec/recorder/download/hls/AbstractHlsDownload.java @@ -136,11 +136,6 @@ public abstract class AbstractHlsDownload extends AbstractDownload { recordingEvents.remove(0); } - if (Duration.between(lastSegmentDownload, Instant.now()).getSeconds() > MAX_SECONDS_WITHOUT_TRANSFER) { - LOG.info("No video data received for {} seconds. Stopping recording for model {}", MAX_SECONDS_WITHOUT_TRANSFER, model); - stop(); - return this; - } } catch (ParseException e) { LOG.error("Couldn't parse HLS playlist for model {}\n{}", model, e.getInput(), e); model.delay(); @@ -167,11 +162,17 @@ public abstract class AbstractHlsDownload extends AbstractDownload { LOG.error("Couldn't download segment for model {}", model, e); model.delay(); stop(); - } finally { + } finally { if (consecutivePlaylistErrors > 0) { LOG.debug("Consecutive playlist errors: {}", consecutivePlaylistErrors); } } + + if (Duration.between(lastSegmentDownload, Instant.now()).getSeconds() > MAX_SECONDS_WITHOUT_TRANSFER) { + LOG.info("No video data received for {} seconds. Stopping recording for model {}", MAX_SECONDS_WITHOUT_TRANSFER, model); + stop(); + } + return this; } @@ -280,7 +281,7 @@ public abstract class AbstractHlsDownload extends AbstractDownload { 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(); - + try (Response response = client.execute(request, config.getSettings().playlistRequestTimeout)) { if (response.isSuccessful()) { consecutivePlaylistTimeouts = 0; @@ -302,16 +303,21 @@ public abstract class AbstractHlsDownload extends AbstractDownload { recordingEvents.add(RecordingEvent.of("HTTP code " + response.code())); throw new HttpException(response.code(), response.message()); } - } catch (SocketTimeoutException e) { - LOG.debug("Playlist request timed out ({}ms) for model {}:{} {} time{}", config.getSettings().playlistRequestTimeout, model.getSite().getName(), model, - ++consecutivePlaylistTimeouts, (consecutivePlaylistTimeouts > 1) ? 's' : ""); + } catch (SocketTimeoutException e) { + LOG.debug("Playlist request timed out ({}ms) for model {}:{} {} time{} (took {}ms)", + config.getSettings().playlistRequestTimeout, + model.getSite().getName(), + model, + ++consecutivePlaylistTimeouts, + (consecutivePlaylistTimeouts > 1) ? 's' : "", + (Duration.between(start, Instant.now()).toMillis())); // times out, return an empty playlist, so that the process can continue without wasting much more time - recordingEvents.add(RecordingEvent.of("Playlist request timed out " + consecutivePlaylistTimeouts)); + recordingEvents.add(RecordingEvent.of("Playlist request timed out " + consecutivePlaylistTimeouts)); throw new PlaylistTimeoutException(e); } catch (Exception e) { consecutivePlaylistErrors++; throw e; - } + } } private SegmentPlaylist parsePlaylist(String segmentPlaylistUrl, InputStream inputStream) throws IOException, ParseException, PlaylistException {