use of co.videofirst.vft.capture.model.capture.Capture in project vft-capture by videofirst.
the class FileSystemCaptureDao method findById.
@Override
public Capture findById(String captureId) {
// Check cache
if (captureIdCache.get(captureId) != null) {
try {
Capture capture = readVideoFromDataFile(captureIdCache.get(captureId), Capture.class);
if (capture != null && capture.getId().equals(captureId)) {
return capture;
}
} catch (VideoOpenException voEx) {
log.warn("Error opening capture", voEx.getMessage());
}
// remove from cache and continue
captureIdCache.remove(captureId);
}
FindFile findFile = new FindFile();
findVideoFile(captureId, videoFolder, findFile);
if (findFile.getFile() == null) {
throw new VideoOpenException("Cannot find a capture for ID - " + captureId);
}
Capture capture = readVideoFromDataFile(findFile.getFile(), Capture.class);
captureIdCache.put(captureId, findFile.getFile());
return capture;
}
use of co.videofirst.vft.capture.model.capture.Capture in project vft-capture by videofirst.
the class DefaultUploadService method upload.
// Methods from `UploadService`
@Override
public void upload(String captureId) {
if (!uploadConfig.isEnable()) {
throw new VideoUploadException("Please enable upload configuration (i.e. set `vft_config.upload.enable` property to `true`)");
}
Capture capture = getCapture(captureId);
// Check capture is finished i.e. the `finished` timestamp is set.
if (capture.getFinished() == null) {
throw new InvalidStateException("You can only upload a capture which is finished. Please try again later.");
}
// Mark capture that it's scheduled for upload
Upload upload = Upload.schedule(uploadConfig.getUrl());
capture.setUpload(upload);
captureDao.save(capture);
uploads.put(captureId, capture);
queue.add(capture);
}
use of co.videofirst.vft.capture.model.capture.Capture in project vft-capture by videofirst.
the class FileSystemCaptureDao method readVideoFromDataFile.
// private methods
private <V> V readVideoFromDataFile(File file, Class<V> videoType) {
try {
FileInputStream fileInputStream = new FileInputStream(file);
V v = objectMapper.readValue(fileInputStream, videoType);
// Set additional (non-saved) fields which can be useful e.g. uploading / streaming
if (v instanceof Capture) {
Capture capture = (Capture) v;
capture.setDataFile(getDataFile(capture));
capture.setVideoFile(getVideoFile(capture));
}
return v;
} catch (IOException e) {
throw new VideoOpenException("Error open video - " + file.getAbsolutePath(), e);
}
}
use of co.videofirst.vft.capture.model.capture.Capture in project vft-capture by videofirst.
the class FileSystemCaptureDao method delete.
@Override
public void delete(String captureId) {
Capture capture = findById(captureId);
if (capture != null) {
// delete files, first
File dir = capture.getDataFile().getParentFile();
capture.getDataFile().delete();
capture.getVideoFile().delete();
// now go up parent by parent until the capture dir ...
while (!dir.equals(videoFolder)) {
// .. but if you encounter a folder with other child folders / files then return
if (dir.list().length != 0) {
return;
}
dir.delete();
dir = dir.getParentFile();
}
}
}
use of co.videofirst.vft.capture.model.capture.Capture in project vft-capture by videofirst.
the class DefaultUploadService method purgeFinishedUploads.
@Scheduled(fixedDelayString = "${vft_config.upload.purgeFinishedUploadSchedule:2000}")
public void purgeFinishedUploads() {
for (String captureId : uploads.keySet()) {
Capture capture = uploads.get(captureId);
LocalDateTime time = LocalDateTime.now().minusSeconds(uploadConfig.getKeepFinishedUploadsInSecs());
if (capture.getUpload() != null && capture.getUpload().getState() == UploadState.finished && capture.getUpload().getFinished().isBefore(time)) {
log.info("Removing capture " + captureId);
uploads.remove(captureId);
}
log.debug("Not removing capture " + captureId);
}
}
Aggregations