ADD input and output downloaders

This commit is contained in:
2025-05-15 10:44:07 +02:00
committed by dylandefaoite
parent bce8a5e1d6
commit f6086cdf53
5 changed files with 52 additions and 25 deletions

View File

@@ -0,0 +1,11 @@
meta {
name: Download Input
type: http
seq: 7
}
get {
url: {{base_url}}/download/input/{{video_uuid}}
body: none
auth: inherit
}

View File

@@ -0,0 +1,11 @@
meta {
name: Download Output
type: http
seq: 6
}
get {
url: {{base_url}}/download/output/{{video_uuid}}
body: none
auth: inherit
}

View File

@@ -1,11 +0,0 @@
meta {
name: Download
type: http
seq: 6
}
get {
url: {{base_url}}/download/{{video_uuid}}
body: none
auth: inherit
}

View File

@@ -8,9 +8,11 @@ import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@RestController @RestController
@RequestMapping("/download")
public class DownloadController { public class DownloadController {
private final DownloadService downloadService; private final DownloadService downloadService;
@@ -19,9 +21,23 @@ public class DownloadController {
this.downloadService = downloadService; this.downloadService = downloadService;
} }
@GetMapping("/download/{filename}") @GetMapping("/output/{uuid}")
public ResponseEntity<Resource> downloadFile(@PathVariable String filename) { public ResponseEntity<Resource> downloadFile(@PathVariable String uuid) {
Resource resource = downloadService.downloadOutput(filename); Resource resource = downloadService.downloadOutput(uuid);
if (resource == null || !resource.exists()) {
return ResponseEntity.notFound().build();
}
return ResponseEntity.ok()
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + resource.getFilename() + "\"")
.contentType(MediaType.APPLICATION_OCTET_STREAM)
.body(resource);
}
@GetMapping("/input/{uuid}")
public ResponseEntity<Resource> downloadInput(@PathVariable String uuid) {
Resource resource = downloadService.downloadInput(uuid);
if (resource == null || !resource.exists()) { if (resource == null || !resource.exists()) {
return ResponseEntity.notFound().build(); return ResponseEntity.notFound().build();

View File

@@ -50,20 +50,20 @@ public class CompressionService {
private void buildBitrate(ArrayList<String> command, Float length, Float fileSize) { private void buildBitrate(ArrayList<String> command, Float length, Float fileSize) {
float bitrate = ((fileSize * 8) / length) * BITRATE_MULTIPLIER; float bitrate = ((fileSize * 8) / length) * BITRATE_MULTIPLIER;
float audio_bitrate = bitrate * AUDIO_RATIO; float audioBitrate = bitrate * AUDIO_RATIO;
float video_bitrate; float videoBitrate;
if (audio_bitrate > MAX_AUDIO_BITRATE) { if (audioBitrate > MAX_AUDIO_BITRATE) {
audio_bitrate = MAX_AUDIO_BITRATE; audioBitrate = MAX_AUDIO_BITRATE;
video_bitrate = bitrate - MAX_AUDIO_BITRATE; videoBitrate = bitrate - MAX_AUDIO_BITRATE;
} else { } else {
video_bitrate = bitrate * (1 - AUDIO_RATIO); videoBitrate = bitrate * (1 - AUDIO_RATIO);
} }
command.add("-b:v"); command.add("-b:v");
command.add(video_bitrate + "k"); command.add(videoBitrate + "k");
command.add("-b:a"); command.add("-b:a");
command.add(audio_bitrate + "k"); command.add(audioBitrate + "k");
} }
private void buildInputs(ArrayList<String> command, File inputFile, Float startPoint, Float endPoint) { private void buildInputs(ArrayList<String> command, File inputFile, Float startPoint, Float endPoint) {
@@ -78,9 +78,9 @@ public class CompressionService {
command.add(inputFile.getAbsolutePath()); command.add(inputFile.getAbsolutePath());
if (endPoint != null) { if (endPoint != null) {
Float length = endPoint - startPoint; float length = endPoint - startPoint;
command.add("-t"); command.add("-t");
command.add(length.toString()); command.add(Float.toString(length));
} }
} }
@@ -102,7 +102,7 @@ public class CompressionService {
// Output file // Output file
command.add(outputFile.getAbsolutePath()); command.add(outputFile.getAbsolutePath());
logger.info("Running command: {}", String.join(" ", command)); logger.info("Running command: {}", command);
return new ProcessBuilder(command); return new ProcessBuilder(command);
} }