From f6086cdf53b61df5eefdfadd96cc86d199d9fea9 Mon Sep 17 00:00:00 2001 From: ThisBirchWood Date: Thu, 15 May 2025 10:44:07 +0200 Subject: [PATCH] ADD input and output downloaders --- bruno/VoD-System/Download Input.bru | 11 ++++++++++ bruno/VoD-System/Download Output.bru | 11 ++++++++++ bruno/VoD-System/Download.bru | 11 ---------- .../controllers/DownloadController.java | 22 ++++++++++++++++--- .../services/CompressionService.java | 22 +++++++++---------- 5 files changed, 52 insertions(+), 25 deletions(-) create mode 100644 bruno/VoD-System/Download Input.bru create mode 100644 bruno/VoD-System/Download Output.bru delete mode 100644 bruno/VoD-System/Download.bru diff --git a/bruno/VoD-System/Download Input.bru b/bruno/VoD-System/Download Input.bru new file mode 100644 index 0000000..fdf2b5b --- /dev/null +++ b/bruno/VoD-System/Download Input.bru @@ -0,0 +1,11 @@ +meta { + name: Download Input + type: http + seq: 7 +} + +get { + url: {{base_url}}/download/input/{{video_uuid}} + body: none + auth: inherit +} diff --git a/bruno/VoD-System/Download Output.bru b/bruno/VoD-System/Download Output.bru new file mode 100644 index 0000000..f6ff94e --- /dev/null +++ b/bruno/VoD-System/Download Output.bru @@ -0,0 +1,11 @@ +meta { + name: Download Output + type: http + seq: 6 +} + +get { + url: {{base_url}}/download/output/{{video_uuid}} + body: none + auth: inherit +} diff --git a/bruno/VoD-System/Download.bru b/bruno/VoD-System/Download.bru deleted file mode 100644 index 5664723..0000000 --- a/bruno/VoD-System/Download.bru +++ /dev/null @@ -1,11 +0,0 @@ -meta { - name: Download - type: http - seq: 6 -} - -get { - url: {{base_url}}/download/{{video_uuid}} - body: none - auth: inherit -} diff --git a/src/main/java/com/ddf/vodsystem/controllers/DownloadController.java b/src/main/java/com/ddf/vodsystem/controllers/DownloadController.java index 5d815ac..6dd6be4 100644 --- a/src/main/java/com/ddf/vodsystem/controllers/DownloadController.java +++ b/src/main/java/com/ddf/vodsystem/controllers/DownloadController.java @@ -8,9 +8,11 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController +@RequestMapping("/download") public class DownloadController { private final DownloadService downloadService; @@ -19,9 +21,23 @@ public class DownloadController { this.downloadService = downloadService; } - @GetMapping("/download/{filename}") - public ResponseEntity downloadFile(@PathVariable String filename) { - Resource resource = downloadService.downloadOutput(filename); + @GetMapping("/output/{uuid}") + public ResponseEntity downloadFile(@PathVariable String uuid) { + 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 downloadInput(@PathVariable String uuid) { + Resource resource = downloadService.downloadInput(uuid); if (resource == null || !resource.exists()) { return ResponseEntity.notFound().build(); diff --git a/src/main/java/com/ddf/vodsystem/services/CompressionService.java b/src/main/java/com/ddf/vodsystem/services/CompressionService.java index ad9663e..725fef9 100644 --- a/src/main/java/com/ddf/vodsystem/services/CompressionService.java +++ b/src/main/java/com/ddf/vodsystem/services/CompressionService.java @@ -50,20 +50,20 @@ public class CompressionService { private void buildBitrate(ArrayList command, Float length, Float fileSize) { float bitrate = ((fileSize * 8) / length) * BITRATE_MULTIPLIER; - float audio_bitrate = bitrate * AUDIO_RATIO; - float video_bitrate; + float audioBitrate = bitrate * AUDIO_RATIO; + float videoBitrate; - if (audio_bitrate > MAX_AUDIO_BITRATE) { - audio_bitrate = MAX_AUDIO_BITRATE; - video_bitrate = bitrate - MAX_AUDIO_BITRATE; + if (audioBitrate > MAX_AUDIO_BITRATE) { + audioBitrate = MAX_AUDIO_BITRATE; + videoBitrate = bitrate - MAX_AUDIO_BITRATE; } else { - video_bitrate = bitrate * (1 - AUDIO_RATIO); + videoBitrate = bitrate * (1 - AUDIO_RATIO); } command.add("-b:v"); - command.add(video_bitrate + "k"); + command.add(videoBitrate + "k"); command.add("-b:a"); - command.add(audio_bitrate + "k"); + command.add(audioBitrate + "k"); } private void buildInputs(ArrayList command, File inputFile, Float startPoint, Float endPoint) { @@ -78,9 +78,9 @@ public class CompressionService { command.add(inputFile.getAbsolutePath()); if (endPoint != null) { - Float length = endPoint - startPoint; + float length = endPoint - startPoint; command.add("-t"); - command.add(length.toString()); + command.add(Float.toString(length)); } } @@ -102,7 +102,7 @@ public class CompressionService { // Output file command.add(outputFile.getAbsolutePath()); - logger.info("Running command: {}", String.join(" ", command)); + logger.info("Running command: {}", command); return new ProcessBuilder(command); }