Added Playlist One to Many and Video Many to One relation to the DB.
This commit is contained in:
@@ -4,5 +4,7 @@ import lombok.Data;
|
|||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class SaveNewPlaylistRequest {
|
public class SaveNewPlaylistRequest {
|
||||||
|
private String playlist_name;
|
||||||
private String url;
|
private String url;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,16 +4,25 @@ import jakarta.persistence.*;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@ToString
|
@ToString
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "playlists")
|
@Table(name = "playlists")
|
||||||
|
|
||||||
public class Playlist {
|
public class Playlist {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.SEQUENCE)
|
@GeneratedValue(strategy = GenerationType.SEQUENCE)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
|
private String playlist_name;
|
||||||
|
|
||||||
private String url;
|
private String url;
|
||||||
private StatusEnum status;
|
private StatusEnum status;
|
||||||
|
|
||||||
|
@OneToMany(mappedBy = "playlist", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||||
|
private List<Video> videos = new ArrayList<>();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,4 +21,9 @@ public class Video {
|
|||||||
private StatusEnum status;
|
private StatusEnum status;
|
||||||
|
|
||||||
private String fullPath;
|
private String fullPath;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "playlist_id")
|
||||||
|
private Playlist playlist;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,5 +9,5 @@ import java.util.List;
|
|||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface VideoRepository extends JpaRepository<Video, Long> {
|
public interface VideoRepository extends JpaRepository<Video, Long> {
|
||||||
List<Video> findUrlByStatus(StatusEnum status);
|
List<Video> findByStatus(StatusEnum status);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,9 +5,11 @@ import com.example.video_downloader.entity.Playlist;
|
|||||||
import com.example.video_downloader.entity.StatusEnum;
|
import com.example.video_downloader.entity.StatusEnum;
|
||||||
import com.example.video_downloader.repositories.PlaylistRepository;
|
import com.example.video_downloader.repositories.PlaylistRepository;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
public class PlaylistService {
|
public class PlaylistService {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@@ -17,6 +19,7 @@ public class PlaylistService {
|
|||||||
Playlist playlist = new Playlist();
|
Playlist playlist = new Playlist();
|
||||||
|
|
||||||
playlist.setStatus(StatusEnum.NEW);
|
playlist.setStatus(StatusEnum.NEW);
|
||||||
|
playlist.setPlaylistName(request.getPlaylistName());
|
||||||
playlist.setUrl(request.getUrl());
|
playlist.setUrl(request.getUrl());
|
||||||
playlistRepository.save(playlist);
|
playlistRepository.save(playlist);
|
||||||
return playlist;
|
return playlist;
|
||||||
|
|||||||
@@ -13,8 +13,6 @@ public class ProcessService {
|
|||||||
builder.redirectError(ProcessBuilder.Redirect.INHERIT);
|
builder.redirectError(ProcessBuilder.Redirect.INHERIT);
|
||||||
Process process = builder.start();
|
Process process = builder.start();
|
||||||
int exitCode = process.waitFor();
|
int exitCode = process.waitFor();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -18,12 +18,15 @@ public class YTDLPService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private VideoRepository videoRepository;
|
private VideoRepository videoRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private PlaylistService playlistService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ProcessService processService;
|
private ProcessService processService;
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void validateVideos() throws HttpClientErrorException, IOException, InterruptedException {
|
public void validateVideos() throws HttpClientErrorException, IOException, InterruptedException {
|
||||||
List<Video> response = videoRepository.findUrlByStatus(StatusEnum.NEW);
|
List<Video> response = videoRepository.findByStatus(StatusEnum.NEW);
|
||||||
for(Video video : response) {
|
for(Video video : response) {
|
||||||
if(video.getStatus().equals(StatusEnum.NEW)){
|
if(video.getStatus().equals(StatusEnum.NEW)){
|
||||||
downloadVideo(video.getUrl(), video.getId());
|
downloadVideo(video.getUrl(), video.getId());
|
||||||
|
|||||||
Reference in New Issue
Block a user