From df3e87f1dd3195eeba8325d8b089d156c75d2d55 Mon Sep 17 00:00:00 2001 From: 0xboobface <0xboobface@gmail.com> Date: Thu, 26 Dec 2019 22:19:25 +0100 Subject: [PATCH] Add loop to get manifest for retries Try to download the manifest 10 times with a little break in between before giving up causing the download to terminate --- .../recorder/download/dash/DashDownload.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/common/src/main/java/ctbrec/recorder/download/dash/DashDownload.java b/common/src/main/java/ctbrec/recorder/download/dash/DashDownload.java index 515e5640..a9055d33 100644 --- a/common/src/main/java/ctbrec/recorder/download/dash/DashDownload.java +++ b/common/src/main/java/ctbrec/recorder/download/dash/DashDownload.java @@ -81,14 +81,22 @@ public class DashDownload extends AbstractDownload { .header("Connection", "keep-alive") .build(); // @formatter:on LOG.trace("Loading manifest {}", url); - // TODO try 10 times - try (Response response = httpClient.execute(request)) { - if (response.isSuccessful()) { - return response.body().string(); - } else { - throw new HttpException(response.code(), "Couldn't load manifest: " + response.message()); + for (int tries = 1; tries <= 10; tries++) { + try (Response response = httpClient.execute(request)) { + if (response.isSuccessful()) { + return response.body().string(); + } else { + HttpException httpException = new HttpException(response.code(), "Couldn't load manifest: " + response.message()); + if (tries == 10) { + throw httpException; + } else { + LOG.debug("Couldn't load manifest", httpException); + waitSomeTime(100 * tries); + } + } } } + throw new IOException("Couldn't load manifest"); } private int downloadSegments(MPDtype mpd, AdaptationSetType adaptationSet, boolean isVideo) throws IOException {