forked from j62/ctbrec
1
0
Fork 0

Pass RecordingManager to post-processors

This commit is contained in:
0xb00bface 2020-09-22 22:15:28 +02:00
parent 7b1898072f
commit 67ff48e2dc
16 changed files with 44 additions and 26 deletions

View File

@ -10,6 +10,7 @@ import ctbrec.recorder.postprocessing.Copy;
import ctbrec.recorder.postprocessing.DeleteOriginal;
import ctbrec.recorder.postprocessing.Move;
import ctbrec.recorder.postprocessing.PostProcessor;
import ctbrec.recorder.postprocessing.RemoveKeepFile;
import ctbrec.recorder.postprocessing.Remux;
import ctbrec.recorder.postprocessing.Rename;
import ctbrec.ui.controls.Dialogs;
@ -36,7 +37,8 @@ public class PostProcessingStepPanel extends GridPane {
Remux.class,
Rename.class,
Move.class,
DeleteOriginal.class
DeleteOriginal.class,
RemoveKeepFile.class
}; // @formatter: on
ListView<PostProcessor> stepListView;

View File

@ -165,7 +165,7 @@ public class NextGenLocalRecorder implements Recorder {
List<PostProcessor> postProcessors = config.getSettings().postProcessors;
for (PostProcessor postProcessor : postProcessors) {
LOG.debug("Running post-processor: {}", postProcessor.getName());
postProcessor.postprocess(recording, config);
postProcessor.postprocess(recording, recordingManager, config);
}
setRecordingStatus(recording, State.FINISHED);
recordingManager.saveRecording(recording);

View File

@ -54,6 +54,10 @@ public class RecordingManager {
}
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);
recordingsLock.lock();
try {
@ -64,13 +68,13 @@ public class RecordingManager {
}
public void saveRecording(Recording rec) throws IOException {
String json = adapter.toJson(rec);
File recordingsMetaDir = getDir();
String filename = rec.toString() + ".json";
File recordingMetaData = new File(recordingsMetaDir, filename);
rec.setMetaDataFile(recordingMetaData.getAbsolutePath());
Files.createDirectories(recordingsMetaDir.toPath());
Files.write(recordingMetaData.toPath(), json.getBytes(UTF_8), CREATE, WRITE, TRUNCATE_EXISTING);
if (rec.getMetaDataFile() != null) {
File recordingMetaData = new File(rec.getMetaDataFile());
String json = adapter.toJson(rec);
rec.setMetaDataFile(recordingMetaData.getAbsolutePath());
Files.createDirectories(recordingMetaData.getParentFile().toPath());
Files.write(recordingMetaData.toPath(), json.getBytes(UTF_8), CREATE, WRITE, TRUNCATE_EXISTING);
}
}
private void loadRecordings() throws IOException {

View File

@ -10,6 +10,7 @@ import org.slf4j.LoggerFactory;
import ctbrec.Config;
import ctbrec.Recording;
import ctbrec.recorder.RecordingManager;
public class Copy extends AbstractPostProcessor {
@ -21,7 +22,7 @@ public class Copy extends AbstractPostProcessor {
}
@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();
String copyFilename = getFilenameForCopy(orig);
File copy = new File(orig.getParentFile(), copyFilename);

View File

@ -5,6 +5,7 @@ import java.io.IOException;
import ctbrec.Config;
import ctbrec.NotImplementedExcetion;
import ctbrec.Recording;
import ctbrec.recorder.RecordingManager;
public class CreateContactSheet extends AbstractPlaceholderAwarePostProcessor {
@ -14,7 +15,7 @@ public class CreateContactSheet extends AbstractPlaceholderAwarePostProcessor {
}
@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();
}
}

View File

@ -5,6 +5,7 @@ import java.io.IOException;
import ctbrec.Config;
import ctbrec.NotImplementedExcetion;
import ctbrec.Recording;
import ctbrec.recorder.RecordingManager;
public class CreateTimelineThumbs extends AbstractPlaceholderAwarePostProcessor {
@ -14,7 +15,7 @@ public class CreateTimelineThumbs extends AbstractPlaceholderAwarePostProcessor
}
@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();
}
}

View File

@ -7,6 +7,7 @@ import java.nio.file.Files;
import ctbrec.Config;
import ctbrec.Recording;
import ctbrec.recorder.RecordingManager;
public class DeleteOriginal extends AbstractPostProcessor {
@ -16,7 +17,7 @@ public class DeleteOriginal extends AbstractPostProcessor {
}
@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()) {
Files.deleteIfExists(rec.getAbsoluteFile().toPath());
deleteEmptyParents(rec.getAbsoluteFile().getParentFile());

View File

@ -11,6 +11,7 @@ import org.slf4j.LoggerFactory;
import ctbrec.Config;
import ctbrec.Recording;
import ctbrec.recorder.RecordingManager;
public class Move extends AbstractPlaceholderAwarePostProcessor {
@ -24,7 +25,7 @@ public class Move extends AbstractPlaceholderAwarePostProcessor {
}
@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 path = fillInPlaceHolders(pathTemplate, rec, config);
File src = rec.getPostProcessedFile();

View File

@ -6,11 +6,12 @@ import java.util.Map;
import ctbrec.Config;
import ctbrec.Recording;
import ctbrec.recorder.RecordingManager;
public interface PostProcessor extends Serializable {
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();
void setConfig(Map<String, String> conf);

View File

@ -3,8 +3,8 @@ package ctbrec.recorder.postprocessing;
import java.io.IOException;
import ctbrec.Config;
import ctbrec.NotImplementedExcetion;
import ctbrec.Recording;
import ctbrec.recorder.RecordingManager;
public class RemoveKeepFile extends AbstractPostProcessor {
@ -14,7 +14,8 @@ public class RemoveKeepFile extends AbstractPostProcessor {
}
@Override
public void postprocess(Recording rec, Config config) throws IOException, InterruptedException {
throw new NotImplementedExcetion();
public void postprocess(Recording rec, RecordingManager recordingManager, Config config) throws IOException, InterruptedException {
recordingManager.remove(rec);
rec.setMetaDataFile(null);
}
}

View File

@ -15,6 +15,7 @@ import ctbrec.OS;
import ctbrec.Recording;
import ctbrec.io.IoUtils;
import ctbrec.io.StreamRedirectThread;
import ctbrec.recorder.RecordingManager;
import ctbrec.recorder.download.ProcessExitedUncleanException;
public class Remux extends AbstractPostProcessor {
@ -30,7 +31,7 @@ public class Remux extends AbstractPostProcessor {
}
@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[] args = getConfig().get(FFMPEG_ARGS).split(" ");
String[] argsPlusFile = new String[args.length + 3];

View File

@ -9,6 +9,7 @@ import org.slf4j.LoggerFactory;
import ctbrec.Config;
import ctbrec.Recording;
import ctbrec.recorder.RecordingManager;
public class Rename extends AbstractPlaceholderAwarePostProcessor {
@ -23,7 +24,7 @@ public class Rename extends AbstractPlaceholderAwarePostProcessor {
}
@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 filenameTemplate = getConfig().getOrDefault(FILE_NAME_TEMPLATE, defaultTemplate);
String filename = fillInPlaceHolders(filenameTemplate, rec, config);

View File

@ -5,6 +5,7 @@ import java.io.IOException;
import ctbrec.Config;
import ctbrec.NotImplementedExcetion;
import ctbrec.Recording;
import ctbrec.recorder.RecordingManager;
public class Script extends AbstractPlaceholderAwarePostProcessor {
@ -14,7 +15,7 @@ public class Script extends AbstractPlaceholderAwarePostProcessor {
}
@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
throw new NotImplementedExcetion();
}

View File

@ -18,6 +18,7 @@ import org.junit.Before;
import ctbrec.Config;
import ctbrec.Model;
import ctbrec.Settings;
import ctbrec.recorder.RecordingManager;
import ctbrec.sites.Site;
import ctbrec.sites.chaturbate.Chaturbate;
@ -29,6 +30,7 @@ public abstract class AbstractPpTest {
File originalDir;
File postProcessedDir;
Instant now = Instant.now();
RecordingManager recordingManager;
@Before
public void setup() throws IOException {

View File

@ -26,7 +26,7 @@ public class RenameDirectoryTest extends AbstractPpTest {
rec.setStartDate(now);
rec.setSingleFile(false);
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());
assertTrue(m.matches());
@ -47,6 +47,6 @@ public class RenameDirectoryTest extends AbstractPpTest {
Files.createDirectories(postProcessedDir.toPath());
Rename pp = new Rename();
pp.postprocess(rec, config);
pp.postprocess(rec, recordingManager, config);
}
}

View File

@ -25,7 +25,7 @@ public class RenameSingleFileTest extends AbstractPpTest {
rec.setStartDate(now);
rec.setSingleFile(true);
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());
assertTrue(m.matches());
@ -45,7 +45,7 @@ public class RenameSingleFileTest extends AbstractPpTest {
doThrow(new RuntimeException("Unexpected call of setAbsoluteFile")).when(rec).setAbsoluteFile(any());
Rename pp = new Rename();
pp.getConfig().put(Rename.FILE_NAME_TEMPLATE, original.getName());
pp.postprocess(rec, config);
pp.postprocess(rec, recordingManager, config);
}
@Test
@ -59,7 +59,7 @@ public class RenameSingleFileTest extends AbstractPpTest {
when(rec.getStartDate()).thenReturn(now);
doThrow(new RuntimeException("Unexpected call of setAbsoluteFile")).when(rec).setAbsoluteFile(any());
Rename pp = new Rename();
pp.postprocess(rec, config);
pp.postprocess(rec, recordingManager, config);
}
@Test