forked from j62/ctbrec
Pass RecordingManager to post-processors
This commit is contained in:
parent
7b1898072f
commit
67ff48e2dc
|
@ -10,6 +10,7 @@ import ctbrec.recorder.postprocessing.Copy;
|
||||||
import ctbrec.recorder.postprocessing.DeleteOriginal;
|
import ctbrec.recorder.postprocessing.DeleteOriginal;
|
||||||
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.Remux;
|
import ctbrec.recorder.postprocessing.Remux;
|
||||||
import ctbrec.recorder.postprocessing.Rename;
|
import ctbrec.recorder.postprocessing.Rename;
|
||||||
import ctbrec.ui.controls.Dialogs;
|
import ctbrec.ui.controls.Dialogs;
|
||||||
|
@ -36,7 +37,8 @@ public class PostProcessingStepPanel extends GridPane {
|
||||||
Remux.class,
|
Remux.class,
|
||||||
Rename.class,
|
Rename.class,
|
||||||
Move.class,
|
Move.class,
|
||||||
DeleteOriginal.class
|
DeleteOriginal.class,
|
||||||
|
RemoveKeepFile.class
|
||||||
}; // @formatter: on
|
}; // @formatter: on
|
||||||
|
|
||||||
ListView<PostProcessor> stepListView;
|
ListView<PostProcessor> stepListView;
|
||||||
|
|
|
@ -165,7 +165,7 @@ public class NextGenLocalRecorder implements Recorder {
|
||||||
List<PostProcessor> postProcessors = config.getSettings().postProcessors;
|
List<PostProcessor> postProcessors = config.getSettings().postProcessors;
|
||||||
for (PostProcessor postProcessor : postProcessors) {
|
for (PostProcessor postProcessor : postProcessors) {
|
||||||
LOG.debug("Running post-processor: {}", postProcessor.getName());
|
LOG.debug("Running post-processor: {}", postProcessor.getName());
|
||||||
postProcessor.postprocess(recording, config);
|
postProcessor.postprocess(recording, recordingManager, config);
|
||||||
}
|
}
|
||||||
setRecordingStatus(recording, State.FINISHED);
|
setRecordingStatus(recording, State.FINISHED);
|
||||||
recordingManager.saveRecording(recording);
|
recordingManager.saveRecording(recording);
|
||||||
|
|
|
@ -54,6 +54,10 @@ public class RecordingManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(Recording rec) throws IOException {
|
public void add(Recording rec) throws IOException {
|
||||||
|
File recordingsMetaDir = getDir();
|
||||||
|
String filename = rec.toString() + ".json";
|
||||||
|
File recordingMetaData = new File(recordingsMetaDir, filename);
|
||||||
|
rec.setMetaDataFile(recordingMetaData.getCanonicalPath());
|
||||||
saveRecording(rec);
|
saveRecording(rec);
|
||||||
recordingsLock.lock();
|
recordingsLock.lock();
|
||||||
try {
|
try {
|
||||||
|
@ -64,13 +68,13 @@ public class RecordingManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveRecording(Recording rec) throws IOException {
|
public void saveRecording(Recording rec) throws IOException {
|
||||||
String json = adapter.toJson(rec);
|
if (rec.getMetaDataFile() != null) {
|
||||||
File recordingsMetaDir = getDir();
|
File recordingMetaData = new File(rec.getMetaDataFile());
|
||||||
String filename = rec.toString() + ".json";
|
String json = adapter.toJson(rec);
|
||||||
File recordingMetaData = new File(recordingsMetaDir, filename);
|
rec.setMetaDataFile(recordingMetaData.getAbsolutePath());
|
||||||
rec.setMetaDataFile(recordingMetaData.getAbsolutePath());
|
Files.createDirectories(recordingMetaData.getParentFile().toPath());
|
||||||
Files.createDirectories(recordingsMetaDir.toPath());
|
Files.write(recordingMetaData.toPath(), json.getBytes(UTF_8), CREATE, WRITE, TRUNCATE_EXISTING);
|
||||||
Files.write(recordingMetaData.toPath(), json.getBytes(UTF_8), CREATE, WRITE, TRUNCATE_EXISTING);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadRecordings() throws IOException {
|
private void loadRecordings() throws IOException {
|
||||||
|
|
|
@ -10,6 +10,7 @@ import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import ctbrec.Config;
|
import ctbrec.Config;
|
||||||
import ctbrec.Recording;
|
import ctbrec.Recording;
|
||||||
|
import ctbrec.recorder.RecordingManager;
|
||||||
|
|
||||||
public class Copy extends AbstractPostProcessor {
|
public class Copy extends AbstractPostProcessor {
|
||||||
|
|
||||||
|
@ -21,7 +22,7 @@ public class Copy extends AbstractPostProcessor {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void postprocess(Recording rec, Config config) throws IOException, InterruptedException {
|
public void postprocess(Recording rec, RecordingManager recordingManager, Config config) throws IOException, InterruptedException {
|
||||||
File orig = rec.getPostProcessedFile();
|
File orig = rec.getPostProcessedFile();
|
||||||
String copyFilename = getFilenameForCopy(orig);
|
String copyFilename = getFilenameForCopy(orig);
|
||||||
File copy = new File(orig.getParentFile(), copyFilename);
|
File copy = new File(orig.getParentFile(), copyFilename);
|
||||||
|
|
|
@ -5,6 +5,7 @@ import java.io.IOException;
|
||||||
import ctbrec.Config;
|
import ctbrec.Config;
|
||||||
import ctbrec.NotImplementedExcetion;
|
import ctbrec.NotImplementedExcetion;
|
||||||
import ctbrec.Recording;
|
import ctbrec.Recording;
|
||||||
|
import ctbrec.recorder.RecordingManager;
|
||||||
|
|
||||||
public class CreateContactSheet extends AbstractPlaceholderAwarePostProcessor {
|
public class CreateContactSheet extends AbstractPlaceholderAwarePostProcessor {
|
||||||
|
|
||||||
|
@ -14,7 +15,7 @@ public class CreateContactSheet extends AbstractPlaceholderAwarePostProcessor {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void postprocess(Recording rec, Config config) throws IOException, InterruptedException {
|
public void postprocess(Recording rec, RecordingManager recordingManager, Config config) throws IOException, InterruptedException {
|
||||||
throw new NotImplementedExcetion();
|
throw new NotImplementedExcetion();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import java.io.IOException;
|
||||||
import ctbrec.Config;
|
import ctbrec.Config;
|
||||||
import ctbrec.NotImplementedExcetion;
|
import ctbrec.NotImplementedExcetion;
|
||||||
import ctbrec.Recording;
|
import ctbrec.Recording;
|
||||||
|
import ctbrec.recorder.RecordingManager;
|
||||||
|
|
||||||
public class CreateTimelineThumbs extends AbstractPlaceholderAwarePostProcessor {
|
public class CreateTimelineThumbs extends AbstractPlaceholderAwarePostProcessor {
|
||||||
|
|
||||||
|
@ -14,7 +15,7 @@ public class CreateTimelineThumbs extends AbstractPlaceholderAwarePostProcessor
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void postprocess(Recording rec, Config config) throws IOException, InterruptedException {
|
public void postprocess(Recording rec, RecordingManager recordingManager, Config config) throws IOException, InterruptedException {
|
||||||
throw new NotImplementedExcetion();
|
throw new NotImplementedExcetion();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import java.nio.file.Files;
|
||||||
|
|
||||||
import ctbrec.Config;
|
import ctbrec.Config;
|
||||||
import ctbrec.Recording;
|
import ctbrec.Recording;
|
||||||
|
import ctbrec.recorder.RecordingManager;
|
||||||
|
|
||||||
public class DeleteOriginal extends AbstractPostProcessor {
|
public class DeleteOriginal extends AbstractPostProcessor {
|
||||||
|
|
||||||
|
@ -16,7 +17,7 @@ public class DeleteOriginal extends AbstractPostProcessor {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void postprocess(Recording rec, Config config) throws IOException, InterruptedException {
|
public void postprocess(Recording rec, RecordingManager recordingManager, Config config) throws IOException, InterruptedException {
|
||||||
if (rec.getAbsoluteFile().isFile()) {
|
if (rec.getAbsoluteFile().isFile()) {
|
||||||
Files.deleteIfExists(rec.getAbsoluteFile().toPath());
|
Files.deleteIfExists(rec.getAbsoluteFile().toPath());
|
||||||
deleteEmptyParents(rec.getAbsoluteFile().getParentFile());
|
deleteEmptyParents(rec.getAbsoluteFile().getParentFile());
|
||||||
|
|
|
@ -11,6 +11,7 @@ import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import ctbrec.Config;
|
import ctbrec.Config;
|
||||||
import ctbrec.Recording;
|
import ctbrec.Recording;
|
||||||
|
import ctbrec.recorder.RecordingManager;
|
||||||
|
|
||||||
public class Move extends AbstractPlaceholderAwarePostProcessor {
|
public class Move extends AbstractPlaceholderAwarePostProcessor {
|
||||||
|
|
||||||
|
@ -24,7 +25,7 @@ public class Move extends AbstractPlaceholderAwarePostProcessor {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void postprocess(Recording rec, Config config) throws IOException {
|
public void postprocess(Recording rec, RecordingManager recordingManager, Config config) throws IOException {
|
||||||
String pathTemplate = getConfig().getOrDefault(PATH_TEMPLATE, DEFAULT);
|
String pathTemplate = getConfig().getOrDefault(PATH_TEMPLATE, DEFAULT);
|
||||||
String path = fillInPlaceHolders(pathTemplate, rec, config);
|
String path = fillInPlaceHolders(pathTemplate, rec, config);
|
||||||
File src = rec.getPostProcessedFile();
|
File src = rec.getPostProcessedFile();
|
||||||
|
|
|
@ -6,11 +6,12 @@ import java.util.Map;
|
||||||
|
|
||||||
import ctbrec.Config;
|
import ctbrec.Config;
|
||||||
import ctbrec.Recording;
|
import ctbrec.Recording;
|
||||||
|
import ctbrec.recorder.RecordingManager;
|
||||||
|
|
||||||
public interface PostProcessor extends Serializable {
|
public interface PostProcessor extends Serializable {
|
||||||
String getName();
|
String getName();
|
||||||
|
|
||||||
void postprocess(Recording rec, Config config) throws IOException, InterruptedException;
|
void postprocess(Recording rec, RecordingManager recordingManager, Config config) throws IOException, InterruptedException;
|
||||||
|
|
||||||
Map<String, String> getConfig();
|
Map<String, String> getConfig();
|
||||||
void setConfig(Map<String, String> conf);
|
void setConfig(Map<String, String> conf);
|
||||||
|
|
|
@ -3,8 +3,8 @@ package ctbrec.recorder.postprocessing;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import ctbrec.Config;
|
import ctbrec.Config;
|
||||||
import ctbrec.NotImplementedExcetion;
|
|
||||||
import ctbrec.Recording;
|
import ctbrec.Recording;
|
||||||
|
import ctbrec.recorder.RecordingManager;
|
||||||
|
|
||||||
public class RemoveKeepFile extends AbstractPostProcessor {
|
public class RemoveKeepFile extends AbstractPostProcessor {
|
||||||
|
|
||||||
|
@ -14,7 +14,8 @@ public class RemoveKeepFile extends AbstractPostProcessor {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void postprocess(Recording rec, Config config) throws IOException, InterruptedException {
|
public void postprocess(Recording rec, RecordingManager recordingManager, Config config) throws IOException, InterruptedException {
|
||||||
throw new NotImplementedExcetion();
|
recordingManager.remove(rec);
|
||||||
|
rec.setMetaDataFile(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ import ctbrec.OS;
|
||||||
import ctbrec.Recording;
|
import ctbrec.Recording;
|
||||||
import ctbrec.io.IoUtils;
|
import ctbrec.io.IoUtils;
|
||||||
import ctbrec.io.StreamRedirectThread;
|
import ctbrec.io.StreamRedirectThread;
|
||||||
|
import ctbrec.recorder.RecordingManager;
|
||||||
import ctbrec.recorder.download.ProcessExitedUncleanException;
|
import ctbrec.recorder.download.ProcessExitedUncleanException;
|
||||||
|
|
||||||
public class Remux extends AbstractPostProcessor {
|
public class Remux extends AbstractPostProcessor {
|
||||||
|
@ -30,7 +31,7 @@ public class Remux extends AbstractPostProcessor {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void postprocess(Recording rec, Config config) throws IOException, InterruptedException {
|
public void postprocess(Recording rec, RecordingManager recordingManager, Config config) throws IOException, InterruptedException {
|
||||||
String fileExt = getConfig().get(FILE_EXT);
|
String fileExt = getConfig().get(FILE_EXT);
|
||||||
String[] args = getConfig().get(FFMPEG_ARGS).split(" ");
|
String[] args = getConfig().get(FFMPEG_ARGS).split(" ");
|
||||||
String[] argsPlusFile = new String[args.length + 3];
|
String[] argsPlusFile = new String[args.length + 3];
|
||||||
|
|
|
@ -9,6 +9,7 @@ import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import ctbrec.Config;
|
import ctbrec.Config;
|
||||||
import ctbrec.Recording;
|
import ctbrec.Recording;
|
||||||
|
import ctbrec.recorder.RecordingManager;
|
||||||
|
|
||||||
public class Rename extends AbstractPlaceholderAwarePostProcessor {
|
public class Rename extends AbstractPlaceholderAwarePostProcessor {
|
||||||
|
|
||||||
|
@ -23,7 +24,7 @@ public class Rename extends AbstractPlaceholderAwarePostProcessor {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void postprocess(Recording rec, Config config) throws IOException {
|
public void postprocess(Recording rec, RecordingManager recordingManager, Config config) throws IOException {
|
||||||
String defaultTemplate = rec.isSingleFile() ? DEFAULT : DEFAULT_DIR;
|
String defaultTemplate = rec.isSingleFile() ? DEFAULT : DEFAULT_DIR;
|
||||||
String filenameTemplate = getConfig().getOrDefault(FILE_NAME_TEMPLATE, defaultTemplate);
|
String filenameTemplate = getConfig().getOrDefault(FILE_NAME_TEMPLATE, defaultTemplate);
|
||||||
String filename = fillInPlaceHolders(filenameTemplate, rec, config);
|
String filename = fillInPlaceHolders(filenameTemplate, rec, config);
|
||||||
|
|
|
@ -5,6 +5,7 @@ import java.io.IOException;
|
||||||
import ctbrec.Config;
|
import ctbrec.Config;
|
||||||
import ctbrec.NotImplementedExcetion;
|
import ctbrec.NotImplementedExcetion;
|
||||||
import ctbrec.Recording;
|
import ctbrec.Recording;
|
||||||
|
import ctbrec.recorder.RecordingManager;
|
||||||
|
|
||||||
public class Script extends AbstractPlaceholderAwarePostProcessor {
|
public class Script extends AbstractPlaceholderAwarePostProcessor {
|
||||||
|
|
||||||
|
@ -14,7 +15,7 @@ public class Script extends AbstractPlaceholderAwarePostProcessor {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void postprocess(Recording rec, Config config) throws IOException, InterruptedException {
|
public void postprocess(Recording rec, RecordingManager recordingManager, Config config) throws IOException, InterruptedException {
|
||||||
// TODO make it possible to choose, which placeholders to pass to the script
|
// TODO make it possible to choose, which placeholders to pass to the script
|
||||||
throw new NotImplementedExcetion();
|
throw new NotImplementedExcetion();
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ import org.junit.Before;
|
||||||
import ctbrec.Config;
|
import ctbrec.Config;
|
||||||
import ctbrec.Model;
|
import ctbrec.Model;
|
||||||
import ctbrec.Settings;
|
import ctbrec.Settings;
|
||||||
|
import ctbrec.recorder.RecordingManager;
|
||||||
import ctbrec.sites.Site;
|
import ctbrec.sites.Site;
|
||||||
import ctbrec.sites.chaturbate.Chaturbate;
|
import ctbrec.sites.chaturbate.Chaturbate;
|
||||||
|
|
||||||
|
@ -29,6 +30,7 @@ public abstract class AbstractPpTest {
|
||||||
File originalDir;
|
File originalDir;
|
||||||
File postProcessedDir;
|
File postProcessedDir;
|
||||||
Instant now = Instant.now();
|
Instant now = Instant.now();
|
||||||
|
RecordingManager recordingManager;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() throws IOException {
|
public void setup() throws IOException {
|
||||||
|
|
|
@ -26,7 +26,7 @@ public class RenameDirectoryTest extends AbstractPpTest {
|
||||||
rec.setStartDate(now);
|
rec.setStartDate(now);
|
||||||
rec.setSingleFile(false);
|
rec.setSingleFile(false);
|
||||||
Rename pp = new Rename();
|
Rename pp = new Rename();
|
||||||
pp.postprocess(rec, config);
|
pp.postprocess(rec, recordingManager, config);
|
||||||
|
|
||||||
Matcher m = Pattern.compile("Mockita_\\d{4}-\\d{2}-\\d{2}_\\d{2}-\\d{2}-\\d{2}").matcher(rec.getAbsoluteFile().getName());
|
Matcher m = Pattern.compile("Mockita_\\d{4}-\\d{2}-\\d{2}_\\d{2}-\\d{2}-\\d{2}").matcher(rec.getAbsoluteFile().getName());
|
||||||
assertTrue(m.matches());
|
assertTrue(m.matches());
|
||||||
|
@ -47,6 +47,6 @@ public class RenameDirectoryTest extends AbstractPpTest {
|
||||||
|
|
||||||
Files.createDirectories(postProcessedDir.toPath());
|
Files.createDirectories(postProcessedDir.toPath());
|
||||||
Rename pp = new Rename();
|
Rename pp = new Rename();
|
||||||
pp.postprocess(rec, config);
|
pp.postprocess(rec, recordingManager, config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ public class RenameSingleFileTest extends AbstractPpTest {
|
||||||
rec.setStartDate(now);
|
rec.setStartDate(now);
|
||||||
rec.setSingleFile(true);
|
rec.setSingleFile(true);
|
||||||
Rename pp = new Rename();
|
Rename pp = new Rename();
|
||||||
pp.postprocess(rec, config);
|
pp.postprocess(rec, recordingManager, config);
|
||||||
|
|
||||||
Matcher m = Pattern.compile("Mockita_\\d{4}-\\d{2}-\\d{2}_\\d{2}-\\d{2}-\\d{2}\\.ts").matcher(rec.getAbsoluteFile().getName());
|
Matcher m = Pattern.compile("Mockita_\\d{4}-\\d{2}-\\d{2}_\\d{2}-\\d{2}-\\d{2}\\.ts").matcher(rec.getAbsoluteFile().getName());
|
||||||
assertTrue(m.matches());
|
assertTrue(m.matches());
|
||||||
|
@ -45,7 +45,7 @@ public class RenameSingleFileTest extends AbstractPpTest {
|
||||||
doThrow(new RuntimeException("Unexpected call of setAbsoluteFile")).when(rec).setAbsoluteFile(any());
|
doThrow(new RuntimeException("Unexpected call of setAbsoluteFile")).when(rec).setAbsoluteFile(any());
|
||||||
Rename pp = new Rename();
|
Rename pp = new Rename();
|
||||||
pp.getConfig().put(Rename.FILE_NAME_TEMPLATE, original.getName());
|
pp.getConfig().put(Rename.FILE_NAME_TEMPLATE, original.getName());
|
||||||
pp.postprocess(rec, config);
|
pp.postprocess(rec, recordingManager, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -59,7 +59,7 @@ public class RenameSingleFileTest extends AbstractPpTest {
|
||||||
when(rec.getStartDate()).thenReturn(now);
|
when(rec.getStartDate()).thenReturn(now);
|
||||||
doThrow(new RuntimeException("Unexpected call of setAbsoluteFile")).when(rec).setAbsoluteFile(any());
|
doThrow(new RuntimeException("Unexpected call of setAbsoluteFile")).when(rec).setAbsoluteFile(any());
|
||||||
Rename pp = new Rename();
|
Rename pp = new Rename();
|
||||||
pp.postprocess(rec, config);
|
pp.postprocess(rec, recordingManager, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue