refactor(command): inject CommandRunner instead of static

This commit is contained in:
2026-07-02 20:04:04 +01:00
parent 947c8261fd
commit 5bebea3f95
6 changed files with 36 additions and 34 deletions

View File

@@ -9,12 +9,14 @@ import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@Service
public class RemuxService {
private final Pattern timePattern = Pattern.compile("out_time_ms=(\\d+)");
private final CommandRunner commandRunner;
public RemuxService(CommandRunner commandRunner) {
this.commandRunner = commandRunner;
}
@Async("ffmpegTaskExecutor")
public CompletableFuture<CommandOutput> remux(File inputFile,
@@ -33,14 +35,7 @@ public class RemuxService {
outputFile.getAbsolutePath()
);
return CompletableFuture.completedFuture(CommandRunner.run(command, line -> setProgress(line, remuxProgress, length)));
}
private void setProgress(String line, ProgressTracker progress, float length) {
Matcher matcher = timePattern.matcher(line);
if (matcher.find()) {
float timeInMs = Float.parseFloat(matcher.group(1)) / 1000000f;
progress.setProgress(timeInMs / length);
}
return CompletableFuture.completedFuture(commandRunner.run(command, line ->
commandRunner.setProgress(line, remuxProgress, length)));
}
}