Added new endpoints to launch the sequence with. Reverted back to using Lists at Video and Playlist typologies. Removed downloadVideo use for the time being. Instead, we have process video to add details to the database.
This commit is contained in:
@@ -59,9 +59,11 @@ public class VideoController {
|
||||
|
||||
@PostMapping(path = "/fire")
|
||||
public int getJobDone(@RequestBody Trigger trigger) throws IOException, InterruptedException {
|
||||
|
||||
int statusCode = 200;
|
||||
if(trigger.input) {
|
||||
ytdlpService.processPlaylist();
|
||||
System.out.println("Hello!");
|
||||
ytdlpService.validateVideos();
|
||||
}
|
||||
return statusCode;
|
||||
|
||||
@@ -17,6 +17,7 @@ public class Video {
|
||||
private Long id;
|
||||
|
||||
private String url;
|
||||
private String name;
|
||||
private String ytdl;
|
||||
private String ytMetaData;
|
||||
|
||||
@@ -38,5 +39,6 @@ public class Video {
|
||||
private Creator creator;
|
||||
|
||||
|
||||
|
||||
public void setCreator(String part) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import com.example.video_downloader.entity.StatusEnum;
|
||||
import com.example.video_downloader.entity.Video;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
|
||||
@@ -2,9 +2,6 @@ package com.example.video_downloader.services;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Service
|
||||
|
||||
@@ -8,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.security.InvalidParameterException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
|
||||
@@ -10,9 +10,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.HttpClientErrorException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@@ -52,21 +50,27 @@ public class YTDLPService {
|
||||
List<Video> response = videoRepository.findByStatus(StatusEnum.NEW);
|
||||
|
||||
for(Video video : response) {
|
||||
downloadVideo(video.getUrl(), video.getId());
|
||||
Path filePath = Paths.get("downloads/" + video.getId() + ".webm");
|
||||
if(Files.exists(filePath) && Files.isRegularFile(filePath)) {
|
||||
System.out.println("Apparently it exists mate.");
|
||||
video.setFullPath(String.valueOf(filePath));
|
||||
video.setStatus(StatusEnum.SAVED);
|
||||
} else {
|
||||
System.out.println("Download failed.");
|
||||
video.setStatus(StatusEnum.FAILED);
|
||||
}
|
||||
String data = processVideo(video.getUrl());
|
||||
String[] parts = data.trim().split(", ");
|
||||
video.setName(parts[0]);
|
||||
video.setCreator(parts[1]);
|
||||
videoRepository.save(video);
|
||||
|
||||
}
|
||||
}
|
||||
// Path filePath = Paths.get("downloads/" + video.getId() + ".webm");
|
||||
// if(Files.exists(filePath) && Files.isRegularFile(filePath)) {
|
||||
// System.out.println("Apparently it exists mate.");
|
||||
// video.setFullPath(String.valueOf(filePath));
|
||||
// video.setStatus(StatusEnum.SAVED);
|
||||
// } else {
|
||||
// System.out.println("Download failed.");
|
||||
// video.setStatus(StatusEnum.FAILED);
|
||||
// }
|
||||
|
||||
public String processVideo(String url) throws HttpClientErrorException, InterruptedException, IOException {
|
||||
String result = processService.execute("yt-dlp", "--skip-download", "--print", "%(title)s, %(uploader)s, %(upload_date)s, %(duration_string)s", url);
|
||||
return result;
|
||||
}
|
||||
public void downloadVideo(String url, Long id) throws HttpClientErrorException, InterruptedException, IOException {
|
||||
String outputPath = "downloads/" + id + ".%(ext)s";
|
||||
String result = processService.execute("yt-dlp", "--print", "%(title)s, %(uploader)s, %(upload_date)s, %(duration_string)s", outputPath, url);
|
||||
|
||||
Reference in New Issue
Block a user