Search in sources :

Example 1 with Capture

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;
}
Also used : VideoOpenException(co.videofirst.vft.capture.exception.VideoOpenException) Capture(co.videofirst.vft.capture.model.capture.Capture)

Example 2 with 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);
}
Also used : VideoUploadException(co.videofirst.vft.capture.exception.VideoUploadException) Upload(co.videofirst.vft.capture.model.capture.Upload) InvalidStateException(co.videofirst.vft.capture.exception.InvalidStateException) Capture(co.videofirst.vft.capture.model.capture.Capture)

Example 3 with 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);
    }
}
Also used : IOException(java.io.IOException) VideoOpenException(co.videofirst.vft.capture.exception.VideoOpenException) FileInputStream(java.io.FileInputStream) Capture(co.videofirst.vft.capture.model.capture.Capture)

Example 4 with Capture

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();
        }
    }
}
Also used : File(java.io.File) Capture(co.videofirst.vft.capture.model.capture.Capture)

Example 5 with Capture

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);
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) Capture(co.videofirst.vft.capture.model.capture.Capture) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Aggregations

Capture (co.videofirst.vft.capture.model.capture.Capture)8 VideoOpenException (co.videofirst.vft.capture.exception.VideoOpenException)2 DisplayCapture (co.videofirst.vft.capture.model.display.DisplayCapture)2 File (java.io.File)2 Test (org.junit.Test)2 InvalidStateException (co.videofirst.vft.capture.exception.InvalidStateException)1 VideoUploadException (co.videofirst.vft.capture.exception.VideoUploadException)1 Upload (co.videofirst.vft.capture.model.capture.Upload)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 LocalDateTime (java.time.LocalDateTime)1 Scheduled (org.springframework.scheduling.annotation.Scheduled)1