- Database: Update -> Drop and Create
- Removed PostConstruct from services - Extended Video with MANYTOONE Playlist - Extended Video with ONETOONE creator - Extended Playlist with MANYTOMANY with videos - Created Creator - Extended Creator with OneToMany to videos - VideoController now listens to POST on /fire, expects RequestBody input:true
This commit is contained in:
@@ -6,11 +6,13 @@ import com.example.video_downloader.entity.Playlist;
|
|||||||
import com.example.video_downloader.entity.Video;
|
import com.example.video_downloader.entity.Video;
|
||||||
import com.example.video_downloader.services.PlaylistService;
|
import com.example.video_downloader.services.PlaylistService;
|
||||||
import com.example.video_downloader.services.VideoService;
|
import com.example.video_downloader.services.VideoService;
|
||||||
|
import com.example.video_downloader.services.YTDLPService;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@@ -24,11 +26,19 @@ public class VideoController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private PlaylistService playlistService;
|
private PlaylistService playlistService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private YTDLPService ytdlpService;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
private static class Response {
|
private static class Response {
|
||||||
private Long id;
|
private Long id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
private static class Trigger {
|
||||||
|
private boolean input;
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping(path = "/videos")
|
@PostMapping(path = "/videos")
|
||||||
public Response saveNewVideo(@RequestBody SaveNewVideoRequest request){
|
public Response saveNewVideo(@RequestBody SaveNewVideoRequest request){
|
||||||
|
|
||||||
@@ -56,4 +66,14 @@ public class VideoController {
|
|||||||
return ResponseEntity.ok(videoService.getVideoById(id));
|
return ResponseEntity.ok(videoService.getVideoById(id));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping(path = "/fire")
|
||||||
|
public int getJobDone(@RequestBody Trigger trigger) throws IOException, InterruptedException {
|
||||||
|
int statusCode = 200;
|
||||||
|
if(trigger.input) {
|
||||||
|
ytdlpService.validateVideos();
|
||||||
|
}
|
||||||
|
return statusCode;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import lombok.Data;
|
|||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class SaveNewPlaylistRequest {
|
public class SaveNewPlaylistRequest {
|
||||||
private String playlist_name;
|
private String playlistName;
|
||||||
private String url;
|
private String url;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,5 +5,4 @@ import lombok.Data;
|
|||||||
@Data
|
@Data
|
||||||
public class SaveNewVideoRequest {
|
public class SaveNewVideoRequest {
|
||||||
private String url;
|
private String url;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.example.video_downloader.entity;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Entity
|
||||||
|
public class Creator {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
private String url;
|
||||||
|
|
||||||
|
@OneToMany(mappedBy = "creator")
|
||||||
|
private List<Video> videos;
|
||||||
|
}
|
||||||
@@ -17,12 +17,17 @@ public class Playlist {
|
|||||||
@GeneratedValue(strategy = GenerationType.SEQUENCE)
|
@GeneratedValue(strategy = GenerationType.SEQUENCE)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
private String playlist_name;
|
private String playlistName;
|
||||||
|
|
||||||
private String url;
|
private String url;
|
||||||
private StatusEnum status;
|
private StatusEnum status;
|
||||||
|
|
||||||
@OneToMany(mappedBy = "playlist", cascade = CascadeType.ALL, orphanRemoval = true)
|
@ManyToMany
|
||||||
private List<Video> videos = new ArrayList<>();
|
@JoinTable(
|
||||||
|
name = "video_playlist",
|
||||||
|
joinColumns = @JoinColumn(name = "playlist_id"),
|
||||||
|
inverseJoinColumns = @JoinColumn(name = "video_id")
|
||||||
|
)
|
||||||
|
private List<Video> videos;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,4 +26,10 @@ public class Video {
|
|||||||
@JoinColumn(name = "playlist_id")
|
@JoinColumn(name = "playlist_id")
|
||||||
private Playlist playlist;
|
private Playlist playlist;
|
||||||
|
|
||||||
|
@OneToOne
|
||||||
|
@JoinColumn(name = "creator_id")
|
||||||
|
private Creator creator;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import com.example.video_downloader.entity.Video;
|
|||||||
import com.example.video_downloader.repositories.VideoRepository;
|
import com.example.video_downloader.repositories.VideoRepository;
|
||||||
import jakarta.annotation.PostConstruct;
|
import jakarta.annotation.PostConstruct;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.web.client.HttpClientErrorException;
|
import org.springframework.web.client.HttpClientErrorException;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -13,6 +14,7 @@ import java.nio.file.Path;
|
|||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
public class YTDLPService {
|
public class YTDLPService {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@@ -24,7 +26,6 @@ public class YTDLPService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private ProcessService processService;
|
private ProcessService processService;
|
||||||
|
|
||||||
@PostConstruct
|
|
||||||
public void validateVideos() throws HttpClientErrorException, IOException, InterruptedException {
|
public void validateVideos() throws HttpClientErrorException, IOException, InterruptedException {
|
||||||
List<Video> response = videoRepository.findByStatus(StatusEnum.NEW);
|
List<Video> response = videoRepository.findByStatus(StatusEnum.NEW);
|
||||||
for(Video video : response) {
|
for(Video video : response) {
|
||||||
@@ -34,6 +35,7 @@ public class YTDLPService {
|
|||||||
|
|
||||||
if(Files.exists(filePath) && Files.isRegularFile(filePath)) {
|
if(Files.exists(filePath) && Files.isRegularFile(filePath)) {
|
||||||
System.out.println("Apparently it exists mate.");
|
System.out.println("Apparently it exists mate.");
|
||||||
|
video.setFullPath(String.valueOf(filePath));
|
||||||
video.setStatus(StatusEnum.SAVED);
|
video.setStatus(StatusEnum.SAVED);
|
||||||
} else {
|
} else {
|
||||||
System.out.println("Nah it does not exist mate.");
|
System.out.println("Nah it does not exist mate.");
|
||||||
|
|||||||
@@ -2,4 +2,4 @@ spring.application.name=video_downloader
|
|||||||
spring.datasource.url = jdbc:postgresql://localhost:5432/videos
|
spring.datasource.url = jdbc:postgresql://localhost:5432/videos
|
||||||
spring.datasource.username = postgres
|
spring.datasource.username = postgres
|
||||||
spring.datasource.password = 5995
|
spring.datasource.password = 5995
|
||||||
spring.jpa.hibernate.ddl-auto = update
|
spring.jpa.hibernate.ddl-auto = create-drop
|
||||||
Reference in New Issue
Block a user