forked from j62/ctbrec
1
0
Fork 0

Add setting to remove recordings after post-processing

This commit is contained in:
0xboobface 2020-05-29 19:50:03 +02:00
parent 0858941b50
commit 258334b637
5 changed files with 88 additions and 42 deletions

View File

@ -92,6 +92,7 @@ public class SettingsTab extends Tab implements TabSelectionListener {
private CheckBox updateThumbnails = new CheckBox();
private CheckBox livePreviews = new CheckBox();
private CheckBox showPlayerStarting = new CheckBox();
private CheckBox removeRecordingAfterPp = new CheckBox();
private RadioButton recordLocal;
private ProxySettingsPane proxySettingsPane;
private TextField maxResolution;
@ -284,7 +285,7 @@ public class SettingsTab extends Tab implements TabSelectionListener {
private Node createRecorderPanel() {
int row = 0;
GridPane layout = createGridLayout();
layout.getColumnConstraints().add(new ColumnConstraints(260));
layout.getColumnConstraints().add(new ColumnConstraints(270));
layout.getColumnConstraints().add(new ColumnConstraints(100, 400, Double.MAX_VALUE, Priority.ALWAYS, HPos.LEFT, true));
layout.getColumnConstraints().add(new ColumnConstraints(80));
layout.getColumnConstraints().add(new ColumnConstraints(40));
@ -390,44 +391,6 @@ public class SettingsTab extends Tab implements TabSelectionListener {
GridPane.setColumnSpan(concurrentRecordings, 3);
GridPane.setMargin(concurrentRecordings, new Insets(0, 0, 0, CHECKBOX_MARGIN));
layout.add(new Label("Post-Processing"), 0, row);
postProcessing = new ProgramSelectionBox(Config.getInstance().getSettings().postProcessing);
postProcessing.allowEmptyValue();
postProcessing.fileProperty().addListener((obs, o, n) -> {
String path = n;
if(!Objects.equals(path, Config.getInstance().getSettings().postProcessing)) {
Config.getInstance().getSettings().postProcessing = path;
saveConfig();
}
});
GridPane.setFillWidth(postProcessing, true);
GridPane.setHgrow(postProcessing, Priority.ALWAYS);
GridPane.setMargin(postProcessing, new Insets(0, 0, 0, CHECKBOX_MARGIN));
layout.add(postProcessing, 1, row);
l = new Label("PP-Threads");
layout.add(l, 2, row);
GridPane.setMargin(l, new Insets(0, 0, 0, CHECKBOX_MARGIN));
GridPane.setHalignment(l, HPos.RIGHT);
ppThreads = new TextField(Integer.toString(Config.getInstance().getSettings().postProcessingThreads));
ppThreads.prefWidth(40);
ppThreads.minWidth(40);
ppThreads.maxWidth(40);
ppThreads.textProperty().addListener((observable, oldValue, newValue) -> {
if (!newValue.matches("\\d*")) {
ppThreads.setText(newValue.replaceAll(PATTERN_NOT_A_DIGIT, ""));
}
if (!ppThreads.getText().isEmpty()) {
int newPpThreads = Integer.parseInt(ppThreads.getText());
if (newPpThreads != Config.getInstance().getSettings().postProcessingThreads) {
Config.getInstance().getSettings().postProcessingThreads = newPpThreads;
saveConfig();
showRestartRequired();
}
}
});
layout.add(ppThreads, 3, row++);
tt = new Tooltip("Check every x seconds, if a model came online");
l = new Label("Check online state every (seconds)");
l.setTooltip(tt);
@ -522,7 +485,56 @@ public class SettingsTab extends Tab implements TabSelectionListener {
});
GridPane.setColumnSpan(fileExtension, 3);
GridPane.setMargin(fileExtension, new Insets(0, 0, 0, CHECKBOX_MARGIN));
layout.add(fileExtension, 1, row);
layout.add(fileExtension, 1, row++);
layout.add(new Label("Post-Processing"), 0, row);
postProcessing = new ProgramSelectionBox(Config.getInstance().getSettings().postProcessing);
postProcessing.allowEmptyValue();
postProcessing.fileProperty().addListener((obs, o, n) -> {
String path = n;
if(!Objects.equals(path, Config.getInstance().getSettings().postProcessing)) {
Config.getInstance().getSettings().postProcessing = path;
saveConfig();
}
});
GridPane.setFillWidth(postProcessing, true);
GridPane.setHgrow(postProcessing, Priority.ALWAYS);
GridPane.setMargin(postProcessing, new Insets(0, 0, 0, CHECKBOX_MARGIN));
layout.add(postProcessing, 1, row);
l = new Label("PP-Threads");
layout.add(l, 2, row);
GridPane.setMargin(l, new Insets(0, 0, 0, CHECKBOX_MARGIN));
GridPane.setHalignment(l, HPos.RIGHT);
ppThreads = new TextField(Integer.toString(Config.getInstance().getSettings().postProcessingThreads));
ppThreads.prefWidth(40);
ppThreads.minWidth(40);
ppThreads.maxWidth(40);
ppThreads.textProperty().addListener((observable, oldValue, newValue) -> {
if (!newValue.matches("\\d*")) {
ppThreads.setText(newValue.replaceAll(PATTERN_NOT_A_DIGIT, ""));
}
if (!ppThreads.getText().isEmpty()) {
int newPpThreads = Integer.parseInt(ppThreads.getText());
if (newPpThreads != Config.getInstance().getSettings().postProcessingThreads) {
Config.getInstance().getSettings().postProcessingThreads = newPpThreads;
saveConfig();
showRestartRequired();
}
}
});
layout.add(ppThreads, 3, row++);
l = new Label("Remove recording after post-processing");
layout.add(l, 0, row);
removeRecordingAfterPp.setSelected(Config.getInstance().getSettings().removeRecordingAfterPostProcessing);
removeRecordingAfterPp.setOnAction(e -> {
Config.getInstance().getSettings().removeRecordingAfterPostProcessing = removeRecordingAfterPp.isSelected();
saveConfig();
});
GridPane.setMargin(l, new Insets(4, CHECKBOX_MARGIN, 0, 0));
GridPane.setMargin(removeRecordingAfterPp, new Insets(4, 0, 0, CHECKBOX_MARGIN));
layout.add(removeRecordingAfterPp, 1, row);
TitledPane locations = new TitledPane("Recorder", layout);
locations.setCollapsible(false);

View File

@ -107,6 +107,7 @@ public class Settings {
public String recordingsSortColumn = "";
public String recordingsSortType = "";
public boolean recordSingleFile = false;
public boolean removeRecordingAfterPostProcessing = false;
public boolean requireAuthentication = false;
public String servletContext = "";
public boolean showPlayerStarting = false;

View File

@ -157,6 +157,9 @@ public class NextGenLocalRecorder implements Recorder {
recordingManager.saveRecording(recording);
deleteIfTooShort(recording);
LOG.info("Post-processing finished for {}", recording.getModel().getName());
if (config.getSettings().removeRecordingAfterPostProcessing) {
recordingManager.remove(recording);
}
} catch (Exception e) {
if (e instanceof InterruptedException) { // NOSONAR
Thread.currentThread().interrupt();

View File

@ -102,6 +102,11 @@ public class RecordingManager {
return recordingsMetaDir;
}
/**
* Deletes a recording from disk and removes it from ctbrec
* @param recording
* @throws IOException
*/
public void delete(Recording recording) throws IOException {
if (recording.isPinned()) {
throw new RecordingPinnedException(recording);
@ -137,6 +142,28 @@ public class RecordingManager {
}
}
/**
* Removes the recording from ctbrec, but does not touch the actual file
* @param recording
* @throws IOException
*/
public void remove(Recording recording) throws IOException {
recordingsLock.lock();
try {
int idx = recordings.indexOf(recording);
recording = recordings.get(idx);
File recordingsDir = new File(config.getSettings().recordingsDir);
File path = new File(recordingsDir, recording.getPath());
deleteEmptyParents(path.getParentFile());
// delete the meta data
Files.deleteIfExists(new File(recording.getMetaDataFile()).toPath());
// remove from data structure
recordings.remove(recording);
} finally {
recordingsLock.unlock();
}
}
public List<Recording> getAll() {
recordingsLock.lock();
try {

View File

@ -46,8 +46,11 @@ public abstract class AbstractDownload implements Download {
err.setDaemon(true);
err.start();
process.waitFor();
LOG.debug("Process finished.");
int exitCode = process.waitFor();
LOG.debug("Process finished with exit code {}", exitCode);
if (exitCode != 0) {
throw new ProcessExitedUncleanException("Post-Processing finished with exit code " + exitCode);
}
}
}