forked from j62/ctbrec
Use AtomicBoolen to indicate, if a download has finished
This commit is contained in:
parent
4dd99a6dd3
commit
16dfc07a8e
|
@ -21,6 +21,7 @@ import java.util.Locale;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import javax.xml.bind.JAXBContext;
|
import javax.xml.bind.JAXBContext;
|
||||||
|
@ -56,7 +57,7 @@ public class DashDownload extends AbstractDownload {
|
||||||
private boolean audioInitLoaded = false;
|
private boolean audioInitLoaded = false;
|
||||||
private BigInteger lastAudioTimestamp = BigInteger.ZERO;
|
private BigInteger lastAudioTimestamp = BigInteger.ZERO;
|
||||||
private BigInteger lastVideoTimestamp = BigInteger.ZERO;
|
private BigInteger lastVideoTimestamp = BigInteger.ZERO;
|
||||||
private transient Object downloadFinished = new Object();
|
private transient AtomicBoolean downloadFinished = new AtomicBoolean(false);
|
||||||
private transient HttpClient httpClient;
|
private transient HttpClient httpClient;
|
||||||
private transient Config config;
|
private transient Config config;
|
||||||
private Model model;
|
private Model model;
|
||||||
|
@ -255,11 +256,11 @@ public class DashDownload extends AbstractDownload {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch(HttpException e) {
|
} catch (HttpException e) {
|
||||||
if(e.getResponseCode() == 404) {
|
if (e.getResponseCode() == 404) {
|
||||||
LOG.debug("Manifest not found (404). Model {} probably went offline", model);
|
LOG.debug("Manifest not found (404). Model {} probably went offline", model);
|
||||||
waitSomeTime(10_000);
|
waitSomeTime(10_000);
|
||||||
} else if(e.getResponseCode() == 403) {
|
} else if (e.getResponseCode() == 403) {
|
||||||
LOG.debug("Manifest access forbidden (403). Model {} probably went private or offline", model);
|
LOG.debug("Manifest access forbidden (403). Model {} probably went private or offline", model);
|
||||||
waitSomeTime(10_000);
|
waitSomeTime(10_000);
|
||||||
} else {
|
} else {
|
||||||
|
@ -270,6 +271,7 @@ public class DashDownload extends AbstractDownload {
|
||||||
} finally {
|
} finally {
|
||||||
running = false;
|
running = false;
|
||||||
endTime = Instant.now();
|
endTime = Instant.now();
|
||||||
|
downloadFinished.set(true);
|
||||||
synchronized (downloadFinished) {
|
synchronized (downloadFinished) {
|
||||||
downloadFinished.notifyAll();
|
downloadFinished.notifyAll();
|
||||||
}
|
}
|
||||||
|
@ -348,8 +350,8 @@ public class DashDownload extends AbstractDownload {
|
||||||
if (running) {
|
if (running) {
|
||||||
internalStop();
|
internalStop();
|
||||||
try {
|
try {
|
||||||
while (running) {
|
synchronized (downloadFinished) {
|
||||||
synchronized (downloadFinished) {
|
while (!downloadFinished.get()) {
|
||||||
downloadFinished.wait(TimeUnit.SECONDS.toMillis(1));
|
downloadFinished.wait(TimeUnit.SECONDS.toMillis(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,11 +52,11 @@ public abstract class AbstractHlsDownload extends AbstractDownload {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(AbstractHlsDownload.class);
|
private static final Logger LOG = LoggerFactory.getLogger(AbstractHlsDownload.class);
|
||||||
private static int threadCounter = 0;
|
private static int threadCounter = 0;
|
||||||
|
|
||||||
protected HttpClient client;
|
protected transient HttpClient client;
|
||||||
protected volatile boolean running = false;
|
protected volatile boolean running = false;
|
||||||
protected Model model = new UnknownModel();
|
protected Model model = new UnknownModel();
|
||||||
protected LinkedBlockingQueue<Runnable> downloadQueue = new LinkedBlockingQueue<>(50);
|
protected transient LinkedBlockingQueue<Runnable> downloadQueue = new LinkedBlockingQueue<>(50);
|
||||||
protected ExecutorService downloadThreadPool = new ThreadPoolExecutor(5, 5, 2, TimeUnit.MINUTES, downloadQueue, createThreadFactory());
|
protected transient ExecutorService downloadThreadPool = new ThreadPoolExecutor(5, 5, 2, TimeUnit.MINUTES, downloadQueue, createThreadFactory());
|
||||||
protected State state = State.UNKNOWN;
|
protected State state = State.UNKNOWN;
|
||||||
private int playlistEmptyCount = 0;
|
private int playlistEmptyCount = 0;
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.RejectedExecutionException;
|
import java.util.concurrent.RejectedExecutionException;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -57,7 +58,7 @@ public class HlsDownload extends AbstractHlsDownload {
|
||||||
|
|
||||||
private int segmentCounter = 1;
|
private int segmentCounter = 1;
|
||||||
private NumberFormat nf = new DecimalFormat("000000");
|
private NumberFormat nf = new DecimalFormat("000000");
|
||||||
private transient Object downloadFinished = new Object();
|
private transient AtomicBoolean downloadFinished = new AtomicBoolean(false);
|
||||||
private ZonedDateTime splitRecStartTime;
|
private ZonedDateTime splitRecStartTime;
|
||||||
private transient Config config;
|
private transient Config config;
|
||||||
|
|
||||||
|
@ -171,6 +172,7 @@ public class HlsDownload extends AbstractHlsDownload {
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
}
|
}
|
||||||
|
downloadFinished.set(true);
|
||||||
synchronized (downloadFinished) {
|
synchronized (downloadFinished) {
|
||||||
downloadFinished.notifyAll();
|
downloadFinished.notifyAll();
|
||||||
}
|
}
|
||||||
|
@ -242,7 +244,9 @@ public class HlsDownload extends AbstractHlsDownload {
|
||||||
internalStop();
|
internalStop();
|
||||||
try {
|
try {
|
||||||
synchronized (downloadFinished) {
|
synchronized (downloadFinished) {
|
||||||
downloadFinished.wait(TimeUnit.SECONDS.toMillis(60));
|
while (!downloadFinished.get()) {
|
||||||
|
downloadFinished.wait(TimeUnit.SECONDS.toMillis(60));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
|
|
Loading…
Reference in New Issue