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
|
||||
public class SaveNewPlaylistRequest {
|
||||
private String playlist_name;
|
||||
private String url;
|
||||
|
||||
}
|
||||
|
||||
@@ -4,16 +4,25 @@ import jakarta.persistence.*;
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@ToString
|
||||
@Entity
|
||||
@Table(name = "playlists")
|
||||
|
||||
public class Playlist {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE)
|
||||
private Long id;
|
||||
|
||||
private String playlist_name;
|
||||
|
||||
private String url;
|
||||
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 String fullPath;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "playlist_id")
|
||||
private Playlist playlist;
|
||||
|
||||
}
|
||||
|
||||
@@ -9,5 +9,5 @@ import java.util.List;
|
||||
|
||||
@Repository
|
||||
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.repositories.PlaylistRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class PlaylistService {
|
||||
|
||||
@Autowired
|
||||
@@ -17,6 +19,7 @@ public class PlaylistService {
|
||||
Playlist playlist = new Playlist();
|
||||
|
||||
playlist.setStatus(StatusEnum.NEW);
|
||||
playlist.setPlaylistName(request.getPlaylistName());
|
||||
playlist.setUrl(request.getUrl());
|
||||
playlistRepository.save(playlist);
|
||||
return playlist;
|
||||
|
||||
@@ -13,8 +13,6 @@ public class ProcessService {
|
||||
builder.redirectError(ProcessBuilder.Redirect.INHERIT);
|
||||
Process process = builder.start();
|
||||
int exitCode = process.waitFor();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -18,12 +18,15 @@ public class YTDLPService {
|
||||
@Autowired
|
||||
private VideoRepository videoRepository;
|
||||
|
||||
@Autowired
|
||||
private PlaylistService playlistService;
|
||||
|
||||
@Autowired
|
||||
private ProcessService processService;
|
||||
|
||||
@PostConstruct
|
||||
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) {
|
||||
if(video.getStatus().equals(StatusEnum.NEW)){
|
||||
downloadVideo(video.getUrl(), video.getId());
|
||||
|
||||
Reference in New Issue
Block a user