REFACTOR to be more modular

This commit is contained in:
2025-05-09 18:56:24 +02:00
parent de382feeff
commit 4d59456292
7 changed files with 36 additions and 68 deletions

View File

@@ -1,5 +1,6 @@
package com.ddf.vodsystem.services;
import com.ddf.vodsystem.entities.ClipConfig;
import lombok.Data;
import java.io.BufferedReader;
@@ -27,17 +28,14 @@ public class CompressionService {
@Getter @Setter
private File outputFile;
@Getter @Setter
private Float startPoint;
@Getter @Setter
private Float endPoint;
@Getter @Setter
private Integer width;
@Getter @Setter
private Integer height;
@Getter @Setter
private Float fps;
@Getter @Setter
private Float fileSize;
private ClipConfig clipConfig;
private final Float startPoint;
private final Float endPoint;
private final Integer width;
private final Integer height;
private final Float fps;
private final Float fileSize;
private static final float AUDIO_RATIO = 0.15f;
private static final float MAX_AUDIO_BITRATE = 128f;
@@ -46,7 +44,7 @@ public class CompressionService {
private Pattern timePattern = Pattern.compile("time=([\\d:.]+)");
private long out_time_ms;
public CompressionService(File file, File output) {
public CompressionService(File file, File output, ClipConfig clipConfig) {
command = new ArrayList<>();
command.add("ffmpeg");
command.add("-progress");
@@ -55,15 +53,16 @@ public class CompressionService {
this.inputFile = file;
this.outputFile = output;
this.clipConfig = clipConfig;
this.startPoint = clipConfig.getStartPoint();
this.endPoint = clipConfig.getEndPoint();
this.fps = clipConfig.getFps();
this.fileSize = clipConfig.getFileSize();
this.width = clipConfig.getWidth();
this.height = clipConfig.getHeight();
}
public void setResolution(Integer width, Integer height) {
this.width = width;
this.height = height;
}
private void buildFilters() {
List<String> filters = new ArrayList<>();

View File

@@ -1,7 +1,7 @@
package com.ddf.vodsystem.services;
import com.ddf.vodsystem.entities.EditDTO;
import com.ddf.vodsystem.entities.Job;
import com.ddf.vodsystem.entities.ClipConfig;
import com.ddf.vodsystem.tools.Job;
import org.springframework.stereotype.Service;
@Service
@@ -12,40 +12,18 @@ public class EditService {
this.jobService = jobService;
}
public void edit(String uuid, EditDTO editDTO) {
public void edit(String uuid, ClipConfig clipConfig) {
Job job = jobService.get(uuid);
if (editDTO.getStartPoint() != null) {
if (editDTO.getStartPoint() < 0) {
if (clipConfig.getStartPoint() != null) {
if (clipConfig.getStartPoint() < 0) {
throw new IllegalArgumentException("Start point cannot be negative");
}
job.setStartPoint(editDTO.getStartPoint());
}
if (editDTO.getEndPoint() != null) {
job.setEndPoint(editDTO.getEndPoint());
}
job.setClipConfig(clipConfig);
if (editDTO.getFps() != null) {
job.setFps(editDTO.getFps());
}
if (editDTO.getWidth() != null) {
job.setWidth(editDTO.getWidth());
}
if (editDTO.getHeight() != null) {
job.setHeight(editDTO.getHeight());
}
if (editDTO.getFileSize() != null) {
if (editDTO.getFileSize() < 0) {
throw new IllegalArgumentException("File size cannot be negative");
}
job.setFileSize(editDTO.getFileSize());
}
}
public void jobReady(String uuid) {

View File

@@ -1,6 +1,6 @@
package com.ddf.vodsystem.services;
import com.ddf.vodsystem.entities.Job;
import com.ddf.vodsystem.tools.Job;
import com.ddf.vodsystem.entities.JobStatus;
import jakarta.annotation.PostConstruct;
import org.springframework.stereotype.Service;
@@ -12,7 +12,7 @@ import java.util.HashMap;
import java.util.LinkedList;
@Service
class JobService {
public class JobService {
private static final Logger logger = LoggerFactory.getLogger(JobService.class);
private final HashMap<String, Job> jobs = new HashMap<>();
private final LinkedList<Job> jobQueue = new LinkedList<>();
@@ -39,7 +39,7 @@ class JobService {
}
@PostConstruct
public void startProcessingLoop() {
private void startProcessingLoop() {
Thread thread = new Thread(() -> {
while (true) {
if (!jobQueue.isEmpty()) {

View File

@@ -1,6 +1,6 @@
package com.ddf.vodsystem.services;
import com.ddf.vodsystem.entities.Job;
import com.ddf.vodsystem.tools.Job;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;