playlist_service #2

Merged
zoli merged 13 commits from playlist_service into main 2026-03-11 18:25:42 +01:00
6 changed files with 25 additions and 19 deletions
Showing only changes of commit f83d21d8f6 - Show all commits

View File

@@ -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;

View File

@@ -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) {
}
}

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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);