Compare commits

2 Commits

7 changed files with 65 additions and 14 deletions

1
.gitignore vendored
View File

@@ -31,3 +31,4 @@ build/
### VS Code ###
.vscode/
After this video, you will speak with confidence \[3yMHLJbXfFc].webm

8
Dockerfile Normal file
View File

@@ -0,0 +1,8 @@
FROM eclipse-temurin:21-jdk
WORKDIR /app
COPY yt-dlp /app
COPY target/video_downloader-0.0.1-SNAPSHOT.jar /app
CMD ["java", "-jar", "/app/video_downloader-0.0.1-SNAPSHOT.jar"]

View File

@@ -2,11 +2,16 @@ package com.example.video_downloader.controllers;
import com.example.video_downloader.dto.SaveNewVideoRequest;
import com.example.video_downloader.entity.Video;
import com.example.video_downloader.repositories.VideoRepository;
import com.example.video_downloader.services.VideoService;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ResponseStatusException;
import java.util.List;
import java.util.Optional;
@RestController
@RequestMapping(path="/video")
@@ -31,4 +36,15 @@ public class VideoController {
return response;
}
@GetMapping(path = "/all")
public ResponseEntity<List<Video>> getAllVideos(){
return ResponseEntity.ok(videoService.getVideos());
}
@GetMapping(path = "/{id}")
public ResponseEntity<Video> getVideoById(@PathVariable Long id){
return ResponseEntity.ok(videoService.getVideoById(id));
}
}

View File

@@ -0,0 +1,26 @@
package com.example.video_downloader.services;
import jakarta.annotation.PostConstruct;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
@Service
public class ProcessService {
@PostConstruct
public void init() throws InterruptedException, IOException {
execute("yt-dlp", "");
}
public void execute(String... command) throws InterruptedException, IOException {
ProcessBuilder builder = new ProcessBuilder(command);
builder.redirectOutput(ProcessBuilder.Redirect.INHERIT);
builder.redirectError(ProcessBuilder.Redirect.INHERIT);
Process process = builder.start();
process.waitFor();
}
}

View File

@@ -7,6 +7,9 @@ import com.example.video_downloader.repositories.VideoRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional;
@Service
public class VideoService {
@@ -22,4 +25,14 @@ public class VideoService {
return video;
}
public List<Video> getVideos(){
return videoRepository.findAll();
}
public Video getVideoById(Long id){
return videoRepository.findById(id)
.orElseThrow(() -> new RuntimeException("Video not found with id: " + id));
}
}

View File

@@ -1,13 +0,0 @@
package com.example.video_downloader;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class VideoDownloaderApplicationTests {
@Test
void contextLoads() {
}
}

BIN
yt-dlp Normal file

Binary file not shown.