ADD file size retrieval and update VideoMetadata object

This commit is contained in:
2025-07-03 22:40:29 +02:00
parent 8de4a147f2
commit 3abdfe3978
2 changed files with 55 additions and 16 deletions

View File

@@ -1,6 +1,5 @@
package com.ddf.vodsystem.services;
import com.ddf.vodsystem.entities.Job;
import com.ddf.vodsystem.entities.VideoMetadata;
import com.ddf.vodsystem.exceptions.FFMPEGException;
import com.fasterxml.jackson.databind.JsonNode;
@@ -16,7 +15,7 @@ import java.io.InputStreamReader;
@Service
public class MetadataService {
private static Logger logger = LoggerFactory.getLogger(MetadataService.class);
private static final Logger logger = LoggerFactory.getLogger(MetadataService.class);
public VideoMetadata getVideoMetadata(File file) {
logger.info("Getting metadata for file {}", file.getAbsolutePath());
@@ -44,6 +43,26 @@ public class MetadataService {
}
}
public Float getFileSize(File file) {
logger.info("Getting file size for {}", file.getAbsolutePath());
VideoMetadata metadata = getVideoMetadata(file);
if (metadata.getFileSize() == null) {
throw new FFMPEGException("File size not found");
}
return metadata.getFileSize();
}
public Float getVideoDuration(File file) {
logger.info("Getting video duration for {}", file.getAbsolutePath());
VideoMetadata metadata = getVideoMetadata(file);
if (metadata.getEndPoint() == null) {
throw new FFMPEGException("Video duration not found");
}
return metadata.getEndPoint();
}
private JsonNode readStandardOutput(Process process) throws IOException{
// Read the standard output (JSON metadata)
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));