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")
|
@PostMapping(path = "/fire")
|
||||||
public int getJobDone(@RequestBody Trigger trigger) throws IOException, InterruptedException {
|
public int getJobDone(@RequestBody Trigger trigger) throws IOException, InterruptedException {
|
||||||
|
|
||||||
int statusCode = 200;
|
int statusCode = 200;
|
||||||
if(trigger.input) {
|
if(trigger.input) {
|
||||||
ytdlpService.processPlaylist();
|
ytdlpService.processPlaylist();
|
||||||
|
System.out.println("Hello!");
|
||||||
ytdlpService.validateVideos();
|
ytdlpService.validateVideos();
|
||||||
}
|
}
|
||||||
return statusCode;
|
return statusCode;
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ public class Video {
|
|||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
private String url;
|
private String url;
|
||||||
|
private String name;
|
||||||
private String ytdl;
|
private String ytdl;
|
||||||
private String ytMetaData;
|
private String ytMetaData;
|
||||||
|
|
||||||
@@ -38,5 +39,6 @@ public class Video {
|
|||||||
private Creator creator;
|
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 com.example.video_downloader.entity.Video;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
|
|||||||
@@ -2,9 +2,6 @@ package com.example.video_downloader.services;
|
|||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.security.InvalidParameterException;
|
import java.security.InvalidParameterException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
|||||||
@@ -10,9 +10,7 @@ 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;
|
||||||
import java.nio.file.Files;
|
import java.util.ArrayList;
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@@ -52,21 +50,27 @@ public class YTDLPService {
|
|||||||
List<Video> response = videoRepository.findByStatus(StatusEnum.NEW);
|
List<Video> response = videoRepository.findByStatus(StatusEnum.NEW);
|
||||||
|
|
||||||
for(Video video : response) {
|
for(Video video : response) {
|
||||||
downloadVideo(video.getUrl(), video.getId());
|
String data = processVideo(video.getUrl());
|
||||||
Path filePath = Paths.get("downloads/" + video.getId() + ".webm");
|
String[] parts = data.trim().split(", ");
|
||||||
if(Files.exists(filePath) && Files.isRegularFile(filePath)) {
|
video.setName(parts[0]);
|
||||||
System.out.println("Apparently it exists mate.");
|
video.setCreator(parts[1]);
|
||||||
video.setFullPath(String.valueOf(filePath));
|
|
||||||
video.setStatus(StatusEnum.SAVED);
|
|
||||||
} else {
|
|
||||||
System.out.println("Download failed.");
|
|
||||||
video.setStatus(StatusEnum.FAILED);
|
|
||||||
}
|
|
||||||
videoRepository.save(video);
|
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 {
|
public void downloadVideo(String url, Long id) throws HttpClientErrorException, InterruptedException, IOException {
|
||||||
String outputPath = "downloads/" + id + ".%(ext)s";
|
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);
|
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