Fix download of recordings
This commit is contained in:
parent
4ebc847720
commit
4f9c1606fc
|
@ -506,6 +506,7 @@ public class RecordingsTab extends Tab implements TabSelectionListener {
|
|||
if (recording.isSegmented()) {
|
||||
URL url = new URL(hlsBase + recording.getPath() + "/playlist.m3u8");
|
||||
MergedFfmpegHlsDownload download = new MergedFfmpegHlsDownload(CamrecApplication.httpClient);
|
||||
download.init(config, recording.getModel(), Instant.now());
|
||||
LOG.info("Downloading {}", url);
|
||||
download.downloadFinishedRecording(url.toString(), target, createDownloadListener(recording));
|
||||
} else {
|
||||
|
|
|
@ -12,6 +12,7 @@ import java.util.Collections;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
@ -44,6 +45,7 @@ import ctbrec.io.HttpException;
|
|||
import ctbrec.recorder.PlaylistGenerator.InvalidPlaylistException;
|
||||
import ctbrec.recorder.download.AbstractDownload;
|
||||
import ctbrec.recorder.download.StreamSource;
|
||||
import ctbrec.sites.Site;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
|
@ -80,10 +82,11 @@ public abstract class AbstractHlsDownload extends AbstractDownload {
|
|||
.header(ACCEPT, "*/*")
|
||||
.header(ACCEPT_LANGUAGE, Locale.ENGLISH.getLanguage())
|
||||
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||
.header(ORIGIN, model.getSite().getBaseUrl())
|
||||
.header(REFERER, model.getSite().getBaseUrl())
|
||||
.header(CONNECTION, KEEP_ALIVE)
|
||||
.header(ORIGIN, Optional.ofNullable(model).map(Model::getSite).map(Site::getBaseUrl).orElse(""))
|
||||
.header(REFERER, Optional.ofNullable(model).map(Model::getSite).map(Site::getBaseUrl).orElse(""))
|
||||
.build();
|
||||
|
||||
Exception lastException = null;
|
||||
for (int tries = 1; tries <= 10 && running; tries++) {
|
||||
try (Response response = client.execute(request)) {
|
||||
|
|
|
@ -21,8 +21,6 @@ import java.util.concurrent.Future;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.jcodec.containers.mp4.MP4Util;
|
||||
import org.jcodec.containers.mp4.boxes.MovieBox;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -121,7 +119,7 @@ public class MergedFfmpegHlsDownload extends AbstractHlsDownload {
|
|||
argsPlusFile[i++] = "-i";
|
||||
argsPlusFile[i++] = "-";
|
||||
System.arraycopy(args, 0, argsPlusFile, i, args.length);
|
||||
argsPlusFile[argsPlusFile.length - 1] = targetFile.getAbsolutePath();
|
||||
argsPlusFile[argsPlusFile.length - 1] = target.getAbsolutePath();
|
||||
String[] cmdline = OS.getFFmpegCommand(argsPlusFile);
|
||||
|
||||
LOG.debug("Command line: {}", Arrays.toString(cmdline));
|
||||
|
@ -441,6 +439,7 @@ public class MergedFfmpegHlsDownload extends AbstractHlsDownload {
|
|||
}
|
||||
|
||||
public void downloadFinishedRecording(String segmentPlaylistUri, File target, ProgressListener progressListener) throws Exception {
|
||||
running = true;
|
||||
if (Config.getInstance().getSettings().requireAuthentication) {
|
||||
URL u = new URL(segmentPlaylistUri);
|
||||
String path = u.getPath();
|
||||
|
@ -453,6 +452,9 @@ public class MergedFfmpegHlsDownload extends AbstractHlsDownload {
|
|||
}
|
||||
|
||||
startFfmpegProcess(target);
|
||||
for (int i = 0; i < 10 && ffmpegStdIn == null; i++) {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
|
||||
SegmentPlaylist segmentPlaylist = getNextSegments(segmentPlaylistUri);
|
||||
int fileCounter = 0;
|
||||
|
@ -485,13 +487,6 @@ public class MergedFfmpegHlsDownload extends AbstractHlsDownload {
|
|||
|
||||
@Override
|
||||
public Duration getLength() {
|
||||
try {
|
||||
MovieBox movieBox = MP4Util.parseMovie(targetFile);
|
||||
double lengthInSeconds = (double) movieBox.getDuration() / movieBox.getTimescale();
|
||||
return Duration.ofSeconds((long) Math.ceil(lengthInSeconds));
|
||||
} catch (IOException e) {
|
||||
LOG.error("Couldn't determine length of MP4 file {}", getTarget(), e);
|
||||
return Duration.ofSeconds(0);
|
||||
}
|
||||
return Duration.between(getStartTime(), Instant.now());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue