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 22 additions and 13 deletions
Showing only changes of commit b63d70078a - Show all commits

View File

@@ -67,6 +67,12 @@
<artifactId>spring-boot-starter-webmvc-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>26.1.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>

View File

@@ -8,6 +8,7 @@ import com.example.video_downloader.services.PlaylistService;
import com.example.video_downloader.services.VideoService;
import com.example.video_downloader.services.YTDLPService;
import lombok.Data;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@@ -58,13 +59,13 @@ public class VideoController {
}
@PostMapping(path = "/fire")
public int getJobDone(@RequestBody Trigger trigger) throws IOException, InterruptedException {
public int getJobDone(@RequestBody @NotNull Trigger trigger) throws IOException, InterruptedException {
int statusCode = 200;
if(trigger.input) {
ytdlpService.processPlaylist();
System.out.println("Hello!");
ytdlpService.validateVideos();
System.out.println("Hello!");
}
return statusCode;

View File

@@ -4,7 +4,6 @@ import jakarta.persistence.*;
import lombok.Data;
import lombok.ToString;
import java.util.ArrayList;
import java.util.List;
@Data

View File

@@ -5,6 +5,7 @@ import lombok.Data;
import lombok.ToString;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Data
@@ -18,8 +19,8 @@ public class Video {
private String url;
private String name;
private String ytdl;
private String ytMetaData;
private String uploadDate;
private String duration;
@Enumerated(EnumType.STRING)
private StatusEnum status;

View File

@@ -10,8 +10,8 @@ import org.springframework.stereotype.Service;
import org.springframework.web.client.HttpClientErrorException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Date;
@Service
public class YTDLPService {
@@ -31,9 +31,9 @@ public class YTDLPService {
public void processPlaylist() throws IOException, InterruptedException {
List<Playlist> playlists = playlistRepository.findByStatus(StatusEnum.NEW);
System.out.println("Am I slow?");
for(Playlist playlist : playlists) {
String urls = processService.execute("yt-dlp", "--flat-playlist", "--print", "webpage_url", playlist.getUrl());
String urls = processService.execute("yt-dlp", "--force-ipv4", "--flat-playlist", "--print", "webpage_url", playlist.getUrl());
for(String url : urls.split("\\n")){
Video video = new Video();
video.setUrl(url);
@@ -52,8 +52,10 @@ public class YTDLPService {
for(Video video : response) {
String data = processVideo(video.getUrl());
String[] parts = data.trim().split(", ");
video.setName(parts[0]);
video.setCreator(parts[1]);
video.setName(parts[0]);
video.setCreator(parts[1]);
video.setUploadDate(parts[2]);
video.setDuration(parts[3]);
videoRepository.save(video);
}
}
@@ -68,12 +70,12 @@ public class YTDLPService {
// }
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);
String result = processService.execute("yt-dlp", "--force-ipv4", "--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);
String result = processService.execute("yt-dlp", "--force-ipv4", "--print", "%(title)s, %(uploader)s, %(upload_date)s, %(duration_string)s", outputPath, url);
System.out.println(result);
}

View File

@@ -1,5 +1,5 @@
spring.application.name=video_downloader
spring.datasource.url = jdbc:postgresql://localhost:5432/videos
spring.datasource.url = jdbc:postgresql://127.0.0.1:5432/videos
spring.datasource.username = postgres
spring.datasource.password = 5995
spring.jpa.hibernate.ddl-auto = create-drop