Take into account all files of a recording to determine its size
This commit is contained in:
parent
f7b22ff57b
commit
19da3c43bf
|
@ -3,6 +3,7 @@ package ctbrec;
|
|||
import static ctbrec.Recording.State.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
|
@ -13,6 +14,9 @@ import java.util.HashSet;
|
|||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ctbrec.event.EventBusHolder;
|
||||
import ctbrec.event.RecordingStateChangedEvent;
|
||||
import ctbrec.io.IoUtils;
|
||||
|
@ -20,6 +24,8 @@ import ctbrec.recorder.download.Download;
|
|||
import ctbrec.recorder.download.VideoLengthDetector;
|
||||
|
||||
public class Recording implements Serializable {
|
||||
private static final transient Logger LOG = LoggerFactory.getLogger(Recording.class);
|
||||
|
||||
private String id;
|
||||
private Model model;
|
||||
private transient Download download;
|
||||
|
@ -239,20 +245,41 @@ public class Recording implements Serializable {
|
|||
}
|
||||
|
||||
private long getSize() {
|
||||
File rec = getAbsoluteFile();
|
||||
if (rec.isDirectory()) {
|
||||
return IoUtils.getDirectorySize(rec);
|
||||
try {
|
||||
Set<File> files = getAllRecordingFiles();
|
||||
long sum = 0;
|
||||
for (File file : files) {
|
||||
if (file.isDirectory()) {
|
||||
sum += IoUtils.getDirectorySize(file);
|
||||
} else {
|
||||
if (!rec.exists()) {
|
||||
if (rec.getName().endsWith(".m3u8")) {
|
||||
return IoUtils.getDirectorySize(rec.getParentFile());
|
||||
if (!file.exists()) {
|
||||
if (file.getName().endsWith(".m3u8")) {
|
||||
sum += IoUtils.getDirectorySize(file.getParentFile());
|
||||
}
|
||||
} else {
|
||||
sum += file.length();
|
||||
}
|
||||
}
|
||||
}
|
||||
return sum;
|
||||
} catch (IOException e) {
|
||||
LOG.error("Couldn't determine recording size", e);
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
return rec.length();
|
||||
}
|
||||
|
||||
private Set<File> getAllRecordingFiles() throws IOException {
|
||||
Set<File> files = new HashSet<>();
|
||||
if (absoluteFile != null) {
|
||||
files.add(absoluteFile.getCanonicalFile());
|
||||
}
|
||||
if (postProcessedFile != null) {
|
||||
files.add(postProcessedFile.getCanonicalFile());
|
||||
}
|
||||
for (String associatedFile : associatedFiles) {
|
||||
files.add(new File(associatedFile).getCanonicalFile());
|
||||
}
|
||||
return files;
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
|
|
|
@ -1,17 +1,7 @@
|
|||
package ctbrec.recorder;
|
||||
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
import ctbrec.Config;
|
||||
import ctbrec.Model;
|
||||
import ctbrec.Recording;
|
||||
import ctbrec.Recording.State;
|
||||
import ctbrec.event.*;
|
||||
import ctbrec.io.HttpClient;
|
||||
import ctbrec.recorder.download.Download;
|
||||
import ctbrec.recorder.postprocessing.PostProcessor;
|
||||
import ctbrec.sites.Site;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import static ctbrec.SubsequentAction.*;
|
||||
import static ctbrec.event.Event.Type.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
@ -21,14 +11,50 @@ import java.security.InvalidKeyException;
|
|||
import java.security.NoSuchAlgorithmException;
|
||||
import java.time.Instant;
|
||||
import java.time.ZoneId;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorCompletionService;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.SynchronousQueue;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static ctbrec.SubsequentAction.PAUSE;
|
||||
import static ctbrec.SubsequentAction.REMOVE;
|
||||
import static ctbrec.event.Event.Type.MODEL_ONLINE;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
|
||||
import ctbrec.Config;
|
||||
import ctbrec.Model;
|
||||
import ctbrec.Recording;
|
||||
import ctbrec.Recording.State;
|
||||
import ctbrec.event.Event;
|
||||
import ctbrec.event.EventBusHolder;
|
||||
import ctbrec.event.ModelIsOnlineEvent;
|
||||
import ctbrec.event.NoSpaceLeftEvent;
|
||||
import ctbrec.event.RecordingStateChangedEvent;
|
||||
import ctbrec.io.HttpClient;
|
||||
import ctbrec.recorder.download.Download;
|
||||
import ctbrec.recorder.postprocessing.PostProcessor;
|
||||
import ctbrec.sites.Site;
|
||||
|
||||
public class NextGenLocalRecorder implements Recorder {
|
||||
|
||||
|
@ -145,6 +171,7 @@ public class NextGenLocalRecorder implements Recorder {
|
|||
break;
|
||||
}
|
||||
}
|
||||
recording.refresh();
|
||||
setRecordingStatus(recording, State.FINISHED);
|
||||
recordingManager.saveRecording(recording);
|
||||
LOG.info("Post-processing finished for {}", recording.getModel().getName());
|
||||
|
|
Loading…
Reference in New Issue