From 4f852bd5f313c69159ede61c0a0383a8108ad084 Mon Sep 17 00:00:00 2001 From: 0xboobface <0xboobface@gmail.com> Date: Fri, 27 Dec 2019 14:26:48 +0100 Subject: [PATCH] Create a temporary directory for HLS downloads Create a temporary download directory similar to DASH downloads --- .../download/hls/MergedHlsDownload.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/ctbrec/recorder/download/hls/MergedHlsDownload.java b/common/src/main/java/ctbrec/recorder/download/hls/MergedHlsDownload.java index 3f6f8e79..14cb2445 100644 --- a/common/src/main/java/ctbrec/recorder/download/hls/MergedHlsDownload.java +++ b/common/src/main/java/ctbrec/recorder/download/hls/MergedHlsDownload.java @@ -10,6 +10,7 @@ import java.time.Duration; import java.time.Instant; import java.util.Arrays; import java.util.Objects; +import java.util.regex.Pattern; import org.jcodec.containers.mp4.MP4Util; import org.jcodec.containers.mp4.boxes.MovieBox; @@ -32,6 +33,7 @@ public class MergedHlsDownload extends HlsDownload { private static final Logger LOG = LoggerFactory.getLogger(MergedHlsDownload.class); private File finalFile; + private File targetFile; public MergedHlsDownload(HttpClient client) { super(client); @@ -46,7 +48,8 @@ public class MergedHlsDownload extends HlsDownload { Thread.currentThread().interrupt(); } finalFile = Config.getInstance().getFileForRecording(model, "mp4", startTime); - downloadDir = finalFile.getParentFile().toPath(); + targetFile = new File(finalFile.getParentFile(), finalFile.getName() + ".part"); + downloadDir = targetFile.toPath(); } @Override @@ -169,4 +172,17 @@ public class MergedHlsDownload extends HlsDownload { return Duration.ofSeconds(0); } } + + @Override + public File getTarget() { + return targetFile; + } + + @Override + public String getPath(Model model) { + String absolutePath = targetFile.getAbsolutePath(); + String recordingsDir = Config.getInstance().getSettings().recordingsDir; + String relativePath = absolutePath.replaceFirst(Pattern.quote(recordingsDir), ""); + return relativePath; + } }