forked from j62/ctbrec
Add DeleteTooShort post-processor
This commit is contained in:
parent
f6afed3717
commit
30021d184d
|
@ -0,0 +1,24 @@
|
||||||
|
package ctbrec.ui.settings;
|
||||||
|
|
||||||
|
import ctbrec.recorder.postprocessing.DeleteTooShort;
|
||||||
|
import ctbrec.recorder.postprocessing.PostProcessor;
|
||||||
|
import ctbrec.ui.settings.api.Category;
|
||||||
|
import ctbrec.ui.settings.api.Preferences;
|
||||||
|
import ctbrec.ui.settings.api.Setting;
|
||||||
|
import javafx.beans.property.SimpleStringProperty;
|
||||||
|
|
||||||
|
public class DeleteTooShortPaneFactory extends AbstractPostProcessingPaneFactory {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Preferences doCreatePostProcessorPane(PostProcessor pp) {
|
||||||
|
SimpleStringProperty minimumLengthInSeconds = new SimpleStringProperty(null, DeleteTooShort.MIN_LEN_IN_SECS, pp.getConfig().getOrDefault(DeleteTooShort.MIN_LEN_IN_SECS, "10"));
|
||||||
|
properties.add(minimumLengthInSeconds);
|
||||||
|
|
||||||
|
return Preferences.of(new MapPreferencesStorage(),
|
||||||
|
Category.of(pp.getName(),
|
||||||
|
Setting.of("Minimum length in seconds", minimumLengthInSeconds)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -7,6 +7,7 @@ import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import ctbrec.Config;
|
import ctbrec.Config;
|
||||||
|
import ctbrec.recorder.postprocessing.DeleteTooShort;
|
||||||
import ctbrec.recorder.postprocessing.Move;
|
import ctbrec.recorder.postprocessing.Move;
|
||||||
import ctbrec.recorder.postprocessing.PostProcessor;
|
import ctbrec.recorder.postprocessing.PostProcessor;
|
||||||
import ctbrec.recorder.postprocessing.Remux;
|
import ctbrec.recorder.postprocessing.Remux;
|
||||||
|
@ -26,6 +27,7 @@ public class PostProcessingDialogFactory {
|
||||||
ppToDialogMap.put(Script.class, ScriptPaneFactory.class);
|
ppToDialogMap.put(Script.class, ScriptPaneFactory.class);
|
||||||
ppToDialogMap.put(Rename.class, RenamerPaneFactory.class);
|
ppToDialogMap.put(Rename.class, RenamerPaneFactory.class);
|
||||||
ppToDialogMap.put(Move.class, MoverPaneFactory.class);
|
ppToDialogMap.put(Move.class, MoverPaneFactory.class);
|
||||||
|
ppToDialogMap.put(DeleteTooShort.class, DeleteTooShortPaneFactory.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private PostProcessingDialogFactory() {
|
private PostProcessingDialogFactory() {
|
||||||
|
|
|
@ -8,6 +8,7 @@ import java.util.Optional;
|
||||||
import ctbrec.Config;
|
import ctbrec.Config;
|
||||||
import ctbrec.recorder.postprocessing.Copy;
|
import ctbrec.recorder.postprocessing.Copy;
|
||||||
import ctbrec.recorder.postprocessing.DeleteOriginal;
|
import ctbrec.recorder.postprocessing.DeleteOriginal;
|
||||||
|
import ctbrec.recorder.postprocessing.DeleteTooShort;
|
||||||
import ctbrec.recorder.postprocessing.Move;
|
import ctbrec.recorder.postprocessing.Move;
|
||||||
import ctbrec.recorder.postprocessing.PostProcessor;
|
import ctbrec.recorder.postprocessing.PostProcessor;
|
||||||
import ctbrec.recorder.postprocessing.RemoveKeepFile;
|
import ctbrec.recorder.postprocessing.RemoveKeepFile;
|
||||||
|
@ -40,6 +41,7 @@ public class PostProcessingStepPanel extends GridPane {
|
||||||
Remux.class,
|
Remux.class,
|
||||||
Script.class,
|
Script.class,
|
||||||
DeleteOriginal.class,
|
DeleteOriginal.class,
|
||||||
|
DeleteTooShort.class,
|
||||||
RemoveKeepFile.class
|
RemoveKeepFile.class
|
||||||
}; // @formatter: on
|
}; // @formatter: on
|
||||||
|
|
||||||
|
|
|
@ -88,7 +88,6 @@ public class SettingsTab extends Tab implements TabSelectionListener {
|
||||||
private SimpleIntegerProperty onlineCheckIntervalInSecs;
|
private SimpleIntegerProperty onlineCheckIntervalInSecs;
|
||||||
private SimpleBooleanProperty onlineCheckSkipsPausedModels;
|
private SimpleBooleanProperty onlineCheckSkipsPausedModels;
|
||||||
private SimpleLongProperty leaveSpaceOnDevice;
|
private SimpleLongProperty leaveSpaceOnDevice;
|
||||||
private SimpleIntegerProperty minimumLengthInSecs;
|
|
||||||
private SimpleStringProperty ffmpegParameters;
|
private SimpleStringProperty ffmpegParameters;
|
||||||
private SimpleStringProperty fileExtension;
|
private SimpleStringProperty fileExtension;
|
||||||
private SimpleStringProperty server;
|
private SimpleStringProperty server;
|
||||||
|
@ -97,9 +96,7 @@ public class SettingsTab extends Tab implements TabSelectionListener {
|
||||||
private SimpleBooleanProperty requireAuthentication;
|
private SimpleBooleanProperty requireAuthentication;
|
||||||
private SimpleBooleanProperty transportLayerSecurity;
|
private SimpleBooleanProperty transportLayerSecurity;
|
||||||
private ExclusiveSelectionProperty recordLocal;
|
private ExclusiveSelectionProperty recordLocal;
|
||||||
private SimpleFileProperty postProcessing;
|
|
||||||
private SimpleIntegerProperty postProcessingThreads;
|
private SimpleIntegerProperty postProcessingThreads;
|
||||||
private SimpleBooleanProperty removeRecordingAfterPp;
|
|
||||||
private IgnoreList ignoreList;
|
private IgnoreList ignoreList;
|
||||||
|
|
||||||
public SettingsTab(List<Site> sites, Recorder recorder) {
|
public SettingsTab(List<Site> sites, Recorder recorder) {
|
||||||
|
@ -137,7 +134,6 @@ public class SettingsTab extends Tab implements TabSelectionListener {
|
||||||
concurrentRecordings = new SimpleIntegerProperty(null, "concurrentRecordings", settings.concurrentRecordings);
|
concurrentRecordings = new SimpleIntegerProperty(null, "concurrentRecordings", settings.concurrentRecordings);
|
||||||
onlineCheckIntervalInSecs = new SimpleIntegerProperty(null, "onlineCheckIntervalInSecs", settings.onlineCheckIntervalInSecs);
|
onlineCheckIntervalInSecs = new SimpleIntegerProperty(null, "onlineCheckIntervalInSecs", settings.onlineCheckIntervalInSecs);
|
||||||
leaveSpaceOnDevice = new SimpleLongProperty(null, "minimumSpaceLeftInBytes", (long) new GigabytesConverter().convertTo(settings.minimumSpaceLeftInBytes));
|
leaveSpaceOnDevice = new SimpleLongProperty(null, "minimumSpaceLeftInBytes", (long) new GigabytesConverter().convertTo(settings.minimumSpaceLeftInBytes));
|
||||||
minimumLengthInSecs = new SimpleIntegerProperty(null, "minimumLengthInSeconds", settings.minimumLengthInSeconds);
|
|
||||||
ffmpegParameters = new SimpleStringProperty(null, "ffmpegMergedDownloadArgs", settings.ffmpegMergedDownloadArgs);
|
ffmpegParameters = new SimpleStringProperty(null, "ffmpegMergedDownloadArgs", settings.ffmpegMergedDownloadArgs);
|
||||||
fileExtension = new SimpleStringProperty(null, "ffmpegFileSuffix", settings.ffmpegFileSuffix);
|
fileExtension = new SimpleStringProperty(null, "ffmpegFileSuffix", settings.ffmpegFileSuffix);
|
||||||
server = new SimpleStringProperty(null, "httpServer", settings.httpServer);
|
server = new SimpleStringProperty(null, "httpServer", settings.httpServer);
|
||||||
|
@ -147,9 +143,7 @@ public class SettingsTab extends Tab implements TabSelectionListener {
|
||||||
requireAuthentication.addListener(this::requireAuthenticationChanged);
|
requireAuthentication.addListener(this::requireAuthenticationChanged);
|
||||||
transportLayerSecurity = new SimpleBooleanProperty(null, "transportLayerSecurity", settings.transportLayerSecurity);
|
transportLayerSecurity = new SimpleBooleanProperty(null, "transportLayerSecurity", settings.transportLayerSecurity);
|
||||||
recordLocal = new ExclusiveSelectionProperty(null, "localRecording", settings.localRecording, "Local", "Remote");
|
recordLocal = new ExclusiveSelectionProperty(null, "localRecording", settings.localRecording, "Local", "Remote");
|
||||||
postProcessing = new SimpleFileProperty(null, "postProcessing", settings.postProcessing);
|
|
||||||
postProcessingThreads = new SimpleIntegerProperty(null, "postProcessingThreads", settings.postProcessingThreads);
|
postProcessingThreads = new SimpleIntegerProperty(null, "postProcessingThreads", settings.postProcessingThreads);
|
||||||
removeRecordingAfterPp = new SimpleBooleanProperty(null, "removeRecordingAfterPostProcessing", settings.removeRecordingAfterPostProcessing);
|
|
||||||
onlineCheckSkipsPausedModels = new SimpleBooleanProperty(null, "onlineCheckSkipsPausedModels", settings.onlineCheckSkipsPausedModels);
|
onlineCheckSkipsPausedModels = new SimpleBooleanProperty(null, "onlineCheckSkipsPausedModels", settings.onlineCheckSkipsPausedModels);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,10 +200,7 @@ public class SettingsTab extends Tab implements TabSelectionListener {
|
||||||
),
|
),
|
||||||
Category.of("Post-Processing",
|
Category.of("Post-Processing",
|
||||||
Group.of("Post-Processing",
|
Group.of("Post-Processing",
|
||||||
Setting.of("Post-Processing", postProcessing),
|
|
||||||
Setting.of("Threads", postProcessingThreads),
|
Setting.of("Threads", postProcessingThreads),
|
||||||
Setting.of("Delete recordings shorter than (secs)", minimumLengthInSecs, "Delete recordings, which are shorter than x seconds. 0 to disable"),
|
|
||||||
Setting.of("Remove recording after post-processing", removeRecordingAfterPp),
|
|
||||||
Setting.of("Steps", new PostProcessingStepPanel(config))
|
Setting.of("Steps", new PostProcessingStepPanel(config))
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
|
|
|
@ -9,7 +9,6 @@ import java.nio.file.FileStore;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.security.InvalidKeyException;
|
import java.security.InvalidKeyException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.time.Duration;
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -169,7 +168,6 @@ public class NextGenLocalRecorder implements Recorder {
|
||||||
}
|
}
|
||||||
setRecordingStatus(recording, State.FINISHED);
|
setRecordingStatus(recording, State.FINISHED);
|
||||||
recordingManager.saveRecording(recording);
|
recordingManager.saveRecording(recording);
|
||||||
deleteIfTooShort(recording);
|
|
||||||
LOG.info("Post-processing finished for {}", recording.getModel().getName());
|
LOG.info("Post-processing finished for {}", recording.getModel().getName());
|
||||||
if (config.getSettings().removeRecordingAfterPostProcessing) {
|
if (config.getSettings().removeRecordingAfterPostProcessing) {
|
||||||
recordingManager.remove(recording);
|
recordingManager.remove(recording);
|
||||||
|
@ -307,22 +305,6 @@ public class NextGenLocalRecorder implements Recorder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean deleteIfTooShort(Recording rec) throws IOException, InvalidKeyException, NoSuchAlgorithmException {
|
|
||||||
Duration minimumLengthInSeconds = Duration.ofSeconds(Config.getInstance().getSettings().minimumLengthInSeconds);
|
|
||||||
if (minimumLengthInSeconds.getSeconds() <= 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Duration recordingLength = rec.getLength();
|
|
||||||
if (recordingLength.compareTo(minimumLengthInSeconds) < 0) {
|
|
||||||
LOG.info("Deleting too short recording {} [{} < {}]", rec, recordingLength, minimumLengthInSeconds);
|
|
||||||
delete(rec);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stopRecording(Model model) throws IOException, InvalidKeyException, NoSuchAlgorithmException {
|
public void stopRecording(Model model) throws IOException, InvalidKeyException, NoSuchAlgorithmException {
|
||||||
recorderLock.lock();
|
recorderLock.lock();
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
package ctbrec.recorder.postprocessing;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.time.Duration;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import ctbrec.Config;
|
||||||
|
import ctbrec.Recording;
|
||||||
|
import ctbrec.recorder.RecordingManager;
|
||||||
|
|
||||||
|
public class DeleteTooShort extends AbstractPostProcessor {
|
||||||
|
|
||||||
|
private static final transient Logger LOG = LoggerFactory.getLogger(DeleteTooShort.class);
|
||||||
|
public static final String MIN_LEN_IN_SECS = "minimumLengthInSeconds";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "delete too short";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void postprocess(Recording rec, RecordingManager recordingManager, Config config) throws IOException {
|
||||||
|
Duration minimumLengthInSeconds = Duration.ofSeconds(Integer.parseInt(getConfig().getOrDefault(MIN_LEN_IN_SECS, "0")));
|
||||||
|
if (minimumLengthInSeconds.getSeconds() > 0) {
|
||||||
|
Duration recordingLength = rec.getLength();
|
||||||
|
if (recordingLength.compareTo(minimumLengthInSeconds) < 0) {
|
||||||
|
LOG.info("Deleting too short recording {} [{} < {}]", rec, recordingLength, minimumLengthInSeconds);
|
||||||
|
recordingManager.delete(rec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue