forked from j62/ctbrec
1
0
Fork 0

Stop immediately, if the manifest download fails and the model is

offline
This commit is contained in:
0xboobface 2019-12-28 19:51:59 +01:00
parent 678a6e5513
commit 672d7c23ec
1 changed files with 15 additions and 12 deletions

View File

@ -56,12 +56,12 @@ public class DashDownload extends AbstractDownload {
private boolean audioInitLoaded = false;
private BigInteger lastAudioTimestamp = BigInteger.ZERO;
private BigInteger lastVideoTimestamp = BigInteger.ZERO;
private Object downloadFinished = new Object();
private HttpClient httpClient;
private Config config;
private transient Object downloadFinished = new Object();
private transient HttpClient httpClient;
private transient Config config;
private Model model;
private Instant endTime;
private Path downloadDir;
private transient Path downloadDir;
private String manifestUrl;
private boolean running = false;
private ZonedDateTime splitRecStartTime;
@ -74,7 +74,7 @@ public class DashDownload extends AbstractDownload {
this.manifestUrl = manifestUrl;
}
private String getManifest(String url) throws IOException {
private String getManifest(String url) throws IOException, ExecutionException, InterruptedException {
// @formatter:off
Request request = new Request.Builder()
.url(url)
@ -92,11 +92,15 @@ public class DashDownload extends AbstractDownload {
return response.body().string();
} else {
HttpException httpException = new HttpException(response.code(), "Couldn't load manifest: " + response.message());
if (tries == 10) {
throw httpException;
if (model.isOnline(true)) {
if (tries == 10) {
throw httpException;
} else {
LOG.debug("Couldn't load manifest", httpException);
waitSomeTime(100 * tries);
}
} else {
LOG.debug("Couldn't load manifest", httpException);
waitSomeTime(100 * tries);
internalStop();
}
}
}
@ -195,11 +199,10 @@ public class DashDownload extends AbstractDownload {
.header(CONNECTION, KEEP_ALIVE)
.build(); // @formatter:on
int tries = 1;
while (tries <= 10) {
for (tries = 1; tries <= 10; tries++) {
try (Response response = httpClient.execute(request)) {
if (!response.isSuccessful()) {
LOG.trace("Loading segment failed, try {}, {} size:{} {}", tries, response.code(), response.headers().values(CONTENT_LENGTH), url);
tries++;
waitSomeTime(tries * 80);
} else {
InputStream in = response.body().byteStream();
@ -285,7 +288,7 @@ public class DashDownload extends AbstractDownload {
return false;
}
private void downloadManifestAndItsSegments(Unmarshaller u) throws IOException, JAXBException, ExecutionException {
private void downloadManifestAndItsSegments(Unmarshaller u) throws IOException, JAXBException, ExecutionException, InterruptedException {
String manifest = getManifest(manifestUrl);
LOG.trace("Manifest: {}", manifest);
@SuppressWarnings("unchecked")