From f485d3255df1d6d553a75d4d951f9ab6727f6a77 Mon Sep 17 00:00:00 2001 From: 0xboobface <0xboobface@gmail.com> Date: Thu, 9 Aug 2018 19:38:55 +0200 Subject: [PATCH] Improved logging --- .../java/ctbrec/recorder/download/HlsDownload.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/ctbrec/recorder/download/HlsDownload.java b/src/main/java/ctbrec/recorder/download/HlsDownload.java index 5aeb3f55..e220d64b 100644 --- a/src/main/java/ctbrec/recorder/download/HlsDownload.java +++ b/src/main/java/ctbrec/recorder/download/HlsDownload.java @@ -1,5 +1,6 @@ package ctbrec.recorder.download; +import java.io.EOFException; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; @@ -128,6 +129,9 @@ public class HlsDownload implements Download { throw new IOException("Couldn't parse stream information", e); } catch(PlaylistException e) { throw new IOException("Couldn't parse HLS playlist", e); + } catch(EOFException e) { + // end of playlist reached + LOG.debug("Reached end of playlist for model {}", model); } catch(Exception e) { throw new IOException("Couldn't download segment", e); } finally { @@ -228,7 +232,8 @@ public class HlsDownload implements Download { @Override public Boolean call() throws Exception { LOG.trace("Downloading segment to " + file); - for (int i = 0; i < 3; i++) { + int maxTries = 3; + for (int i = 1; i <= maxTries; i++) { Request request = new Request.Builder().url(url).addHeader("connection", "keep-alive").build(); Response response = client.execute(request); try ( @@ -245,7 +250,11 @@ public class HlsDownload implements Download { LOG.debug("Segment does not exist {}", url.getFile()); break; } catch(Exception e) { - LOG.error("Error while downloading segment. Retrying " + i, e); + if (i == maxTries) { + LOG.warn("Error while downloading segment. Segment finally {} failed", file.toFile().getName()); + } else { + LOG.warn("Error while downloading segment on try {}", i); + } } finally { response.close(); }