Introduce new PostProcessingContext to pass around post-processing

related objects
This commit is contained in:
0xb00bface 2021-02-14 18:26:31 +01:00
parent 4fd7b7ddd0
commit d52b728c1c
27 changed files with 144 additions and 93 deletions

View File

@ -3,6 +3,7 @@ package ctbrec.ui;
import java.io.IOException;
import java.time.Instant;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import javax.xml.bind.JAXBException;
@ -13,6 +14,7 @@ import com.squareup.moshi.JsonReader;
import com.squareup.moshi.JsonWriter;
import ctbrec.Model;
import ctbrec.ModelGroupEntry;
import ctbrec.SubsequentAction;
import ctbrec.recorder.download.Download;
import ctbrec.recorder.download.HttpHeaderFactory;
@ -330,5 +332,15 @@ public class JavaFxModel implements Model {
delegate.setMarkedForLaterRecording(marked);
}
@Override
public void setModelGroup(ModelGroupEntry modelGroupEntry) {
delegate.setModelGroup(modelGroupEntry);
}
@Override
public Optional<ModelGroupEntry> getModelGroup() {
return delegate.getModelGroup();
}
}

View File

@ -2,10 +2,8 @@ package ctbrec.ui.tabs;
import java.io.IOException;
import ctbrec.Config;
import ctbrec.Recording;
import ctbrec.recorder.RecordingManager;
import ctbrec.recorder.postprocessing.AbstractPlaceholderAwarePostProcessor;
import ctbrec.recorder.postprocessing.PostProcessingContext;
public class DownloadPostprocessor extends AbstractPlaceholderAwarePostProcessor {
@ -15,7 +13,7 @@ public class DownloadPostprocessor extends AbstractPlaceholderAwarePostProcessor
}
@Override
public boolean postprocess(Recording rec, RecordingManager recordingManager, Config config) throws IOException, InterruptedException {
public boolean postprocess(PostProcessingContext ctx) throws IOException, InterruptedException {
// nothing really to do in here, we just inherit from AbstractPlaceholderAwarePostProcessor to use fillInPlaceHolders
return true;
}

View File

@ -40,6 +40,7 @@ import ctbrec.io.UrlUtil;
import ctbrec.recorder.ProgressListener;
import ctbrec.recorder.Recorder;
import ctbrec.recorder.RecordingPinnedException;
import ctbrec.recorder.postprocessing.PostProcessingContext;
import ctbrec.ui.AutosizeAlert;
import ctbrec.ui.CamrecApplication;
import ctbrec.ui.DesktopIntegration;
@ -688,7 +689,10 @@ public class RecordingsTab extends Tab implements TabSelectionListener, Shutdown
} else {
String downloadFilename = config.getSettings().downloadFilename;
String fileSuffix = config.getSettings().ffmpegFileSuffix;
return new DownloadPostprocessor().fillInPlaceHolders(downloadFilename, recording, config) + '.' + fileSuffix;
PostProcessingContext ctx = new PostProcessingContext();
ctx.setRecording(recording);
ctx.setConfig(config);
return new DownloadPostprocessor().fillInPlaceHolders(downloadFilename, ctx) + '.' + fileSuffix;
}
}

View File

@ -33,7 +33,9 @@ public abstract class AbstractPlaceholderAwarePostProcessor extends AbstractPost
"${absoluteParentPath}"
};
public String fillInPlaceHolders(String input, Recording rec, Config config) {
public String fillInPlaceHolders(String input, PostProcessingContext ctx) {
Recording rec = ctx.getRecording();
Config config = ctx.getConfig();
// @formatter:off
String output = input
.replace("${modelName}", ofNullable(rec.getModel().getName()).orElse("modelName"))

View File

@ -8,9 +8,7 @@ import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ctbrec.Config;
import ctbrec.Recording;
import ctbrec.recorder.RecordingManager;
public class Copy extends AbstractPostProcessor {
@ -22,7 +20,8 @@ public class Copy extends AbstractPostProcessor {
}
@Override
public boolean postprocess(Recording rec, RecordingManager recordingManager, Config config) throws IOException, InterruptedException {
public boolean postprocess(PostProcessingContext ctx) throws IOException, InterruptedException {
Recording rec = ctx.getRecording();
File orig = rec.getPostProcessedFile();
String copyFilename = getFilenameForCopy(orig);
File copy = new File(orig.getParentFile(), copyFilename);

View File

@ -22,7 +22,6 @@ import ctbrec.OS;
import ctbrec.Recording;
import ctbrec.io.IoUtils;
import ctbrec.recorder.FFmpeg;
import ctbrec.recorder.RecordingManager;
import ctbrec.recorder.download.ProcessExitedUncleanException;
@ThreadSafe
@ -45,7 +44,9 @@ public class CreateContactSheet extends AbstractPlaceholderAwarePostProcessor {
}
@Override
public boolean postprocess(Recording rec, RecordingManager recordingManager, Config config) throws IOException, InterruptedException {
public boolean postprocess(PostProcessingContext ctx) throws IOException, InterruptedException {
Recording rec = ctx.getRecording();
Config config = ctx.getConfig();
int totalWidth = Integer.parseInt(getConfig().getOrDefault(TOTAL_SIZE, "1920"));
int padding = Integer.parseInt(getConfig().getOrDefault(PADDING, "4"));
int cols = Integer.parseInt(getConfig().getOrDefault(COLS, "8"));
@ -65,7 +66,7 @@ public class CreateContactSheet extends AbstractPlaceholderAwarePostProcessor {
color},
new StringBuffer(), null).toString();
File executionDir = rec.getPostProcessedFile().isDirectory() ? rec.getPostProcessedFile() : rec.getPostProcessedFile().getParentFile();
File output = new File(executionDir, fillInPlaceHolders(filename, rec, config));
File output = new File(executionDir, fillInPlaceHolders(filename, ctx));
String[] args = {
"-y",

View File

@ -2,10 +2,7 @@ package ctbrec.recorder.postprocessing;
import java.io.IOException;
import ctbrec.Config;
import ctbrec.NotImplementedExcetion;
import ctbrec.Recording;
import ctbrec.recorder.RecordingManager;
public class CreateTimelineThumbs extends AbstractPlaceholderAwarePostProcessor {
@ -15,7 +12,7 @@ public class CreateTimelineThumbs extends AbstractPlaceholderAwarePostProcessor
}
@Override
public boolean postprocess(Recording rec, RecordingManager recordingManager, Config config) throws IOException, InterruptedException {
public boolean postprocess(PostProcessingContext ctx) throws IOException, InterruptedException {
// create 1 thumb every second with a width of 360 pixels and save it as jpeg with a 5-digit sequence number
// ffmpeg -i <file> -vf 'fps=1,scale=360:-1' thumbs/out%05d.jpg
throw new NotImplementedExcetion();

View File

@ -5,9 +5,7 @@ import static ctbrec.io.IoUtils.*;
import java.io.IOException;
import java.nio.file.Files;
import ctbrec.Config;
import ctbrec.Recording;
import ctbrec.recorder.RecordingManager;
public class DeleteOriginal extends AbstractPostProcessor {
@ -17,7 +15,8 @@ public class DeleteOriginal extends AbstractPostProcessor {
}
@Override
public boolean postprocess(Recording rec, RecordingManager recordingManager, Config config) throws IOException, InterruptedException {
public boolean postprocess(PostProcessingContext ctx) throws IOException, InterruptedException {
Recording rec = ctx.getRecording();
if (rec.getAbsoluteFile().isFile()) {
Files.deleteIfExists(rec.getAbsoluteFile().toPath());
deleteEmptyParents(rec.getAbsoluteFile().getParentFile());

View File

@ -6,7 +6,6 @@ import java.time.Duration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ctbrec.Config;
import ctbrec.Recording;
import ctbrec.recorder.RecordingManager;
@ -21,7 +20,9 @@ public class DeleteTooShort extends AbstractPostProcessor {
}
@Override
public boolean postprocess(Recording rec, RecordingManager recordingManager, Config config) throws IOException {
public boolean postprocess(PostProcessingContext ctx) throws IOException {
Recording rec = ctx.getRecording();
RecordingManager recordingManager = ctx.getRecordingManager();
Duration minimumLengthInSeconds = Duration.ofSeconds(Integer.parseInt(getConfig().getOrDefault(MIN_LEN_IN_SECS, "0")));
if (minimumLengthInSeconds.getSeconds() > 0) {
Duration recordingLength = rec.getLength();

View File

@ -10,9 +10,7 @@ import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ctbrec.Config;
import ctbrec.Recording;
import ctbrec.recorder.RecordingManager;
public class Move extends AbstractPlaceholderAwarePostProcessor {
@ -26,9 +24,10 @@ public class Move extends AbstractPlaceholderAwarePostProcessor {
}
@Override
public boolean postprocess(Recording rec, RecordingManager recordingManager, Config config) throws IOException {
public boolean postprocess(PostProcessingContext ctx) throws IOException {
Recording rec = ctx.getRecording();
String pathTemplate = getConfig().getOrDefault(PATH_TEMPLATE, DEFAULT);
String path = fillInPlaceHolders(pathTemplate, rec, config);
String path = fillInPlaceHolders(pathTemplate, ctx);
File src = rec.getPostProcessedFile();
boolean isFile = src.isFile();
File target = new File(path, src.getName());

View File

@ -0,0 +1,46 @@
package ctbrec.recorder.postprocessing;
import ctbrec.Config;
import ctbrec.Recording;
import ctbrec.recorder.Recorder;
import ctbrec.recorder.RecordingManager;
public class PostProcessingContext {
private Recorder recorder;
private Recording recording;
private RecordingManager recordingManager;
private Config config;
public Recorder getRecorder() {
return recorder;
}
public void setRecorder(Recorder recorder) {
this.recorder = recorder;
}
public Recording getRecording() {
return recording;
}
public void setRecording(Recording recording) {
this.recording = recording;
}
public RecordingManager getRecordingManager() {
return recordingManager;
}
public void setRecordingManager(RecordingManager recordingManager) {
this.recordingManager = recordingManager;
}
public Config getConfig() {
return config;
}
public void setConfig(Config config) {
this.config = config;
}
}

View File

@ -4,23 +4,17 @@ import java.io.IOException;
import java.io.Serializable;
import java.util.Map;
import ctbrec.Config;
import ctbrec.Recording;
import ctbrec.recorder.RecordingManager;
public interface PostProcessor extends Serializable {
String getName();
/**
* Runs the post-processing code on the given recording
* @param rec the recording to post-process
* @param recordingManager
* @param config
* @param ctx {@link PostProcessingContext}, which allows access to post-processing related objects
* @return false to stop futher post-processing, true to continue
* @throws IOException
* @throws InterruptedException
*/
boolean postprocess(Recording rec, RecordingManager recordingManager, Config config) throws IOException, InterruptedException;
boolean postprocess(PostProcessingContext ctx) throws IOException, InterruptedException;
Map<String, String> getConfig();
void setConfig(Map<String, String> conf);

View File

@ -2,10 +2,6 @@ package ctbrec.recorder.postprocessing;
import java.io.IOException;
import ctbrec.Config;
import ctbrec.Recording;
import ctbrec.recorder.RecordingManager;
public class RemoveKeepFile extends AbstractPostProcessor {
@Override
@ -14,9 +10,9 @@ public class RemoveKeepFile extends AbstractPostProcessor {
}
@Override
public boolean postprocess(Recording rec, RecordingManager recordingManager, Config config) throws IOException, InterruptedException {
recordingManager.remove(rec);
rec.setMetaDataFile(null);
public boolean postprocess(PostProcessingContext ctx) throws IOException, InterruptedException {
ctx.getRecordingManager().remove(ctx.getRecording());
ctx.getRecording().setMetaDataFile(null);
return true;
}
}

View File

@ -9,12 +9,10 @@ import java.util.Objects;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ctbrec.Config;
import ctbrec.OS;
import ctbrec.Recording;
import ctbrec.io.IoUtils;
import ctbrec.recorder.FFmpeg;
import ctbrec.recorder.RecordingManager;
public class Remux extends AbstractPostProcessor {
@ -29,7 +27,8 @@ public class Remux extends AbstractPostProcessor {
}
@Override
public boolean postprocess(Recording rec, RecordingManager recordingManager, Config config) throws IOException, InterruptedException {
public boolean postprocess(PostProcessingContext ctx) throws IOException, InterruptedException {
Recording rec = ctx.getRecording();
final File inputFile;
if (rec.getPostProcessedFile().isDirectory()) {
inputFile = new File(rec.getPostProcessedFile(), "playlist.m3u8");
@ -44,7 +43,7 @@ public class Remux extends AbstractPostProcessor {
File ffmpegLog = new File(System.getProperty("java.io.tmpdir"), "remux_" + rec.getId() + ".log");
FFmpeg ffmpeg = new FFmpeg.Builder()
.logOutput(config.getSettings().logFFmpegOutput)
.logOutput(ctx.getConfig().getSettings().logFFmpegOutput)
.logFile(ffmpegLog)
.onExit(exitCode -> finalizeStep(exitCode, rec, inputFile, remuxedFile))
.build();

View File

@ -7,9 +7,7 @@ import java.util.Objects;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ctbrec.Config;
import ctbrec.Recording;
import ctbrec.recorder.RecordingManager;
public class Rename extends AbstractPlaceholderAwarePostProcessor {
@ -24,10 +22,11 @@ public class Rename extends AbstractPlaceholderAwarePostProcessor {
}
@Override
public boolean postprocess(Recording rec, RecordingManager recordingManager, Config config) throws IOException {
public boolean postprocess(PostProcessingContext ctx) throws IOException {
Recording rec = ctx.getRecording();
String defaultTemplate = rec.isSingleFile() ? DEFAULT : DEFAULT_DIR;
String filenameTemplate = getConfig().getOrDefault(FILE_NAME_TEMPLATE, defaultTemplate);
String filename = fillInPlaceHolders(filenameTemplate, rec, config);
String filename = fillInPlaceHolders(filenameTemplate, ctx);
File src = rec.getPostProcessedFile();
File target = new File(src.getParentFile(), filename);
if (Objects.equals(src, target)) {

View File

@ -10,11 +10,9 @@ import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ctbrec.Config;
import ctbrec.OS;
import ctbrec.Recording;
import ctbrec.io.StreamRedirector;
import ctbrec.recorder.RecordingManager;
import ctbrec.recorder.download.ProcessExitedUncleanException;
public class Script extends AbstractPlaceholderAwarePostProcessor {
@ -29,8 +27,9 @@ public class Script extends AbstractPlaceholderAwarePostProcessor {
}
@Override
public boolean postprocess(Recording rec, RecordingManager recordingManager, Config config) throws IOException, InterruptedException {
List<String> cmdline = buildCommandLine(rec, config);
public boolean postprocess(PostProcessingContext ctx) throws IOException, InterruptedException {
Recording rec = ctx.getRecording();
List<String> cmdline = buildCommandLine(ctx);
Runtime rt = Runtime.getRuntime();
String[] args = cmdline.toArray(new String[0]);
if (LOG.isDebugEnabled()) {
@ -50,12 +49,12 @@ public class Script extends AbstractPlaceholderAwarePostProcessor {
return true;
}
private List<String> buildCommandLine(Recording rec, Config config) throws IOException {
private List<String> buildCommandLine(PostProcessingContext ctx) {
String script = getConfig().getOrDefault(SCRIPT_EXECUTABLE, "somescript");
String params = getConfig().getOrDefault(SCRIPT_PARAMS, "${absolutePath}");
List<String> cmdline = new ArrayList<>();
cmdline.add(script);
String replacedParams = fillInPlaceHolders(params, rec, config);
String replacedParams = fillInPlaceHolders(params, ctx);
Arrays.stream(replacedParams.split(" ")).forEach(cmdline::add);
return cmdline;
}

View File

@ -2,10 +2,7 @@ package ctbrec.recorder.postprocessing;
import java.io.IOException;
import ctbrec.Config;
import ctbrec.NotImplementedExcetion;
import ctbrec.Recording;
import ctbrec.recorder.RecordingManager;
public class Webhook extends AbstractPlaceholderAwarePostProcessor {
@ -21,7 +18,7 @@ public class Webhook extends AbstractPlaceholderAwarePostProcessor {
}
@Override
public boolean postprocess(Recording rec, RecordingManager recordingManager, Config config) throws IOException, InterruptedException {
public boolean postprocess(PostProcessingContext ctx) throws IOException, InterruptedException {
throw new NotImplementedExcetion();
}

View File

@ -37,19 +37,19 @@ public class AbstractPlaceholderAwarePostProcessorTest extends AbstractPpTest {
@Test
public void testModelNameReplacement() {
String input = "asdf_${modelName}_asdf";
assertEquals("asdf_Mockita Boobilicious_asdf", placeHolderAwarePp.fillInPlaceHolders(input, rec, config));
assertEquals("asdf_Mockita Boobilicious_asdf", placeHolderAwarePp.fillInPlaceHolders(input, createPostProcessingContext(rec, null, config)));
input = "asdf_${modelDisplayName}_asdf";
assertEquals("asdf_Mockita Boobilicious_asdf", placeHolderAwarePp.fillInPlaceHolders(input, rec, config));
assertEquals("asdf_Mockita Boobilicious_asdf", placeHolderAwarePp.fillInPlaceHolders(input, createPostProcessingContext(rec, null, config)));
input = "asdf_${modelSanitizedName}_asdf";
assertEquals("asdf_Mockita_Boobilicious_asdf", placeHolderAwarePp.fillInPlaceHolders(input, rec, config));
assertEquals("asdf_Mockita_Boobilicious_asdf", placeHolderAwarePp.fillInPlaceHolders(input, createPostProcessingContext(rec, null, config)));
}
@Test
public void testSiteNameReplacement() {
String input = "asdf_${siteName}_asdf";
assertEquals("asdf_Chaturbate_asdf", placeHolderAwarePp.fillInPlaceHolders(input, rec, config));
assertEquals("asdf_Chaturbate_asdf", placeHolderAwarePp.fillInPlaceHolders(input, createPostProcessingContext(rec, null, config)));
input = "asdf_${siteSanitizedName}_asdf";
assertEquals("asdf_Chaturbate_asdf", placeHolderAwarePp.fillInPlaceHolders(input, rec, config));
assertEquals("asdf_Chaturbate_asdf", placeHolderAwarePp.fillInPlaceHolders(input, createPostProcessingContext(rec, null, config)));
}
@Test
@ -60,7 +60,7 @@ public class AbstractPlaceholderAwarePostProcessorTest extends AbstractPpTest {
.withZone(ZoneOffset.UTC)
.format(rec.getStartDate());
String input = "asdf_${utcDateTime}_asdf";
assertEquals("asdf_" + date + "_asdf", placeHolderAwarePp.fillInPlaceHolders(input, rec, config));
assertEquals("asdf_" + date + "_asdf", placeHolderAwarePp.fillInPlaceHolders(input, createPostProcessingContext(rec, null, config)));
// with user defined pattern
date = DateTimeFormatter.ofPattern("yyyyMMdd-HHmmss")
@ -68,7 +68,7 @@ public class AbstractPlaceholderAwarePostProcessorTest extends AbstractPpTest {
.withZone(ZoneOffset.UTC)
.format(rec.getStartDate());
input = "asdf_${utcDateTime(yyyyMMdd-HHmmss)}_asdf";
assertEquals("asdf_" + date + "_asdf", placeHolderAwarePp.fillInPlaceHolders(input, rec, config));
assertEquals("asdf_" + date + "_asdf", placeHolderAwarePp.fillInPlaceHolders(input, createPostProcessingContext(rec, null, config)));
// multiple occurences with user defined patterns
date = DateTimeFormatter.ofPattern("yyyy-MM-dd/yyyy")
@ -76,7 +76,7 @@ public class AbstractPlaceholderAwarePostProcessorTest extends AbstractPpTest {
.withZone(ZoneOffset.UTC)
.format(rec.getStartDate());
input = "asdf_${utcDateTime(yyyy)}-${utcDateTime(MM)}-${utcDateTime(dd)}/${utcDateTime(yyyy)}_asdf";
assertEquals("asdf_" + date + "_asdf", placeHolderAwarePp.fillInPlaceHolders(input, rec, config));
assertEquals("asdf_" + date + "_asdf", placeHolderAwarePp.fillInPlaceHolders(input, createPostProcessingContext(rec, null, config)));
}
@Test
@ -86,50 +86,50 @@ public class AbstractPlaceholderAwarePostProcessorTest extends AbstractPpTest {
.withZone(ZoneId.systemDefault())
.format(rec.getStartDate());
String input = "asdf_${localDateTime}_asdf";
assertEquals("asdf_" + date + "_asdf", placeHolderAwarePp.fillInPlaceHolders(input, rec, config));
assertEquals("asdf_" + date + "_asdf", placeHolderAwarePp.fillInPlaceHolders(input, createPostProcessingContext(rec, null, config)));
date = DateTimeFormatter.ofPattern("yyyyMMdd-HHmmss")
.withLocale(Locale.US)
.withZone(ZoneId.systemDefault())
.format(rec.getStartDate());
input = "asdf_${localDateTime(yyyyMMdd-HHmmss)}_asdf";
assertEquals("asdf_" + date + "_asdf", placeHolderAwarePp.fillInPlaceHolders(input, rec, config));
assertEquals("asdf_" + date + "_asdf", placeHolderAwarePp.fillInPlaceHolders(input, createPostProcessingContext(rec, null, config)));
}
@Test
public void testEpochReplacement() {
long epoch = now.toEpochMilli() / 1000;
String input = "asdf_${epochSecond}_asdf";
assertEquals("asdf_" + epoch + "_asdf", placeHolderAwarePp.fillInPlaceHolders(input, rec, config));
assertEquals("asdf_" + epoch + "_asdf", placeHolderAwarePp.fillInPlaceHolders(input, createPostProcessingContext(rec, null, config)));
}
@Test
public void testFileSuffixReplacement() {
String input = "asdf_${fileSuffix}_asdf";
assertEquals("asdf_ts_asdf", placeHolderAwarePp.fillInPlaceHolders(input, rec, config));
assertEquals("asdf_ts_asdf", placeHolderAwarePp.fillInPlaceHolders(input, createPostProcessingContext(rec, null, config)));
}
@Test
public void testRecordingsDirReplacement() {
String input = "asdf_${recordingsDir}_asdf";
assertEquals("asdf_" + recDir.toString() + "_asdf", placeHolderAwarePp.fillInPlaceHolders(input, rec, config));
assertEquals("asdf_" + recDir.toString() + "_asdf", placeHolderAwarePp.fillInPlaceHolders(input, createPostProcessingContext(rec, null, config)));
}
@Test
public void testAbsolutePathReplacement() {
String input = "asdf_${absolutePath}_asdf";
assertEquals("asdf_" + postProcessed.getAbsolutePath().toString() + "_asdf", placeHolderAwarePp.fillInPlaceHolders(input, rec, config));
assertEquals("asdf_" + postProcessed.getAbsolutePath().toString() + "_asdf", placeHolderAwarePp.fillInPlaceHolders(input, createPostProcessingContext(rec, null, config)));
}
@Test
public void testAbsoluteParentPathReplacement() {
String input = "asdf_${absoluteParentPath}_asdf";
assertEquals("asdf_" + postProcessed.getParentFile().toString() + "_asdf", placeHolderAwarePp.fillInPlaceHolders(input, rec, config));
assertEquals("asdf_" + postProcessed.getParentFile().toString() + "_asdf", placeHolderAwarePp.fillInPlaceHolders(input, createPostProcessingContext(rec, null, config)));
}
@Test
public void testModelNotesReplacement() {
String input = "asdf_${modelNotes}_asdf";
assertEquals("asdf_tag,_foo,_bar_asdf", placeHolderAwarePp.fillInPlaceHolders(input, rec, config));
assertEquals("asdf_tag,_foo,_bar_asdf", placeHolderAwarePp.fillInPlaceHolders(input, createPostProcessingContext(rec, null, config)));
}
}

View File

@ -18,6 +18,7 @@ import org.mockito.MockedStatic;
import ctbrec.Config;
import ctbrec.Model;
import ctbrec.Recording;
import ctbrec.Settings;
import ctbrec.recorder.RecordingManager;
import ctbrec.sites.Site;
@ -81,4 +82,12 @@ public abstract class AbstractPpTest {
settings.recordingsDir = recDir.toString();
return settings;
}
PostProcessingContext createPostProcessingContext(Recording rec, RecordingManager recordingManager, Config config) {
PostProcessingContext ctx = new PostProcessingContext();
ctx.setConfig(config);
ctx.setRecording(rec);
ctx.setRecordingManager(recordingManager);
return ctx;
}
}

View File

@ -20,7 +20,7 @@ public class CopyTest extends AbstractPpTest {
rec.setStartDate(now);
rec.setSingleFile(false);
Copy pp = new Copy();
pp.postprocess(rec, recordingManager, config);
pp.postprocess(createPostProcessingContext(rec, recordingManager, config));
assertNotEquals(rec.getAbsoluteFile(), rec.getPostProcessedFile());
assertTrue(original.exists());
@ -36,7 +36,7 @@ public class CopyTest extends AbstractPpTest {
rec.setStartDate(now);
rec.setSingleFile(false);
Copy pp = new Copy();
pp.postprocess(rec, recordingManager, config);
pp.postprocess(createPostProcessingContext(rec, recordingManager, config));
assertNotEquals(rec.getAbsoluteFile(), rec.getPostProcessedFile());
assertTrue(originalDir.exists());

View File

@ -23,7 +23,7 @@ public class DeleteOriginalTest extends AbstractPpTest {
Config config = mockConfig();
DeleteOriginal pp = new DeleteOriginal();
pp.postprocess(rec, null, config);
pp.postprocess(createPostProcessingContext(rec, null, config));
assertEquals(postProcessed, rec.getAbsoluteFile());
assertTrue(rec.getAbsoluteFile().exists());
@ -42,7 +42,7 @@ public class DeleteOriginalTest extends AbstractPpTest {
Config config = mockConfig();
Files.createDirectories(postProcessedDir.toPath());
DeleteOriginal pp = new DeleteOriginal();
pp.postprocess(rec, null, config);
pp.postprocess(createPostProcessingContext(rec, null, config));
assertEquals(postProcessedDir, rec.getAbsoluteFile());
assertTrue(rec.getAbsoluteFile().exists());

View File

@ -42,7 +42,7 @@ public class DeleteTooShortTest extends AbstractPpTest {
DeleteTooShort pp = new DeleteTooShort();
pp.getConfig().put(DeleteTooShort.MIN_LEN_IN_SECS, "10");
pp.postprocess(rec, recordingManager, config);
pp.postprocess(createPostProcessingContext(rec, recordingManager, config));
assertFalse(rec.getAbsoluteFile().exists());
assertFalse(original.exists());
@ -66,7 +66,7 @@ public class DeleteTooShortTest extends AbstractPpTest {
DeleteTooShort pp = new DeleteTooShort();
pp.getConfig().put(DeleteTooShort.MIN_LEN_IN_SECS, "0");
pp.postprocess(rec, recordingManager, config);
pp.postprocess(createPostProcessingContext(rec, recordingManager, config));
assertTrue(rec.getAbsoluteFile().exists());
assertTrue(original.exists());
@ -83,7 +83,7 @@ public class DeleteTooShortTest extends AbstractPpTest {
DeleteTooShort pp = new DeleteTooShort();
pp.getConfig().put(DeleteTooShort.MIN_LEN_IN_SECS, "1");
pp.postprocess(rec, recordingManager, config);
pp.postprocess(createPostProcessingContext(rec, recordingManager, config));
assertTrue(rec.getAbsoluteFile().exists());
assertTrue(original.exists());

View File

@ -28,7 +28,7 @@ public class MoveDirectoryTest extends AbstractPpTest {
rec.setSingleFile(false);
Move pp = new Move();
pp.getConfig().put(Move.PATH_TEMPLATE, new File(baseDir.toFile(), Move.DEFAULT).getAbsolutePath());
pp.postprocess(rec, recordingManager, config);
pp.postprocess(createPostProcessingContext(rec, recordingManager, config));
Matcher m = Pattern.compile(baseDir.toString() + "/Mockita_Boobilicious/\\d{4}-\\d{2}-\\d{2}_\\d{2}-\\d{2}-\\d{2}/original").matcher(rec.getAbsoluteFile().getCanonicalPath());
assertTrue(m.matches());
@ -50,6 +50,6 @@ public class MoveDirectoryTest extends AbstractPpTest {
Move pp = new Move();
Config config = mockConfig();
pp.getConfig().put(Move.PATH_TEMPLATE, new File(baseDir.toFile(), Move.DEFAULT).getAbsolutePath());
pp.postprocess(rec, recordingManager, config);
pp.postprocess(createPostProcessingContext(rec, recordingManager, config));
}
}

View File

@ -28,7 +28,7 @@ public class MoveSingleFileTest extends AbstractPpTest {
Move pp = new Move();
pp.getConfig().put(Move.PATH_TEMPLATE, new File(baseDir.toFile(), Move.DEFAULT).getAbsolutePath());
pp.postprocess(rec, recordingManager, config);
pp.postprocess(createPostProcessingContext(rec, recordingManager, config));
Matcher m = Pattern.compile(baseDir.toFile() + "/Mockita_Boobilicious/\\d{4}-\\d{2}-\\d{2}_\\d{2}-\\d{2}-\\d{2}/original\\.ts").matcher(rec.getAbsoluteFile().toString());
assertTrue(m.matches());
@ -48,7 +48,7 @@ public class MoveSingleFileTest extends AbstractPpTest {
Move pp = new Move();
Config config = mockConfig();
pp.getConfig().put(Move.PATH_TEMPLATE, original.getParentFile().getCanonicalPath());
pp.postprocess(rec, recordingManager, config);
pp.postprocess(createPostProcessingContext(rec, recordingManager, config));
}
@Test
@ -63,7 +63,7 @@ public class MoveSingleFileTest extends AbstractPpTest {
Move pp = new Move();
Config config = mockConfig();
pp.getConfig().put(Move.PATH_TEMPLATE, new File(baseDir.toFile(), Move.DEFAULT).getAbsolutePath());
pp.postprocess(rec, recordingManager, config);
pp.postprocess(createPostProcessingContext(rec, recordingManager, config));
}
@Test

View File

@ -25,9 +25,9 @@ public class RemoveKeepFileTest extends AbstractPpTest {
Config config = mockConfig();
RecordingManager rm = new RecordingManager(config, Collections.emptyList());
rm.add(rec);
assertTrue(rm.getAll().size() == 1);
assertEquals(1, rm.getAll().size());
RemoveKeepFile pp = new RemoveKeepFile();
pp.postprocess(rec, rm, config);
pp.postprocess(createPostProcessingContext(rec, rm, config));
assertTrue(rec.getAbsoluteFile().exists());
assertTrue(rec.getPostProcessedFile().exists());

View File

@ -26,7 +26,7 @@ public class RenameDirectoryTest extends AbstractPpTest {
rec.setStartDate(now);
rec.setSingleFile(false);
Rename pp = new Rename();
pp.postprocess(rec, recordingManager, config);
pp.postprocess(createPostProcessingContext(rec, recordingManager, config));
Matcher m = Pattern.compile("Mockita_Boobilicious_\\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, recordingManager, config);
pp.postprocess(createPostProcessingContext(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, recordingManager, config);
pp.postprocess(createPostProcessingContext(rec, recordingManager, config));
Matcher m = Pattern.compile("Mockita_Boobilicious_\\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, recordingManager, config);
pp.postprocess(createPostProcessingContext(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, recordingManager, config);
pp.postprocess(createPostProcessingContext(rec, recordingManager, config));
}
@Test