playlist_service #2

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

View File

@@ -7,6 +7,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
public class VideoDownloaderApplication {
public static void main(String[] args) {
SpringApplication.run(VideoDownloaderApplication.class, args);
}
}

View File

@@ -1,9 +1,13 @@
package com.example.video_downloader.repositories;
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.List;
@Repository
public interface VideoRepository extends JpaRepository<Video, Long> {
List<Video> findUrlByStatus(StatusEnum status);
}

View File

@@ -1,5 +1,7 @@
package com.example.video_downloader.services;
import com.example.video_downloader.entity.StatusEnum;
import com.example.video_downloader.entity.Video;
import com.example.video_downloader.repositories.VideoRepository;
import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
@@ -7,6 +9,7 @@ import org.springframework.stereotype.Service;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List;
@Service
public class ProcessService {
@@ -14,9 +17,28 @@ public class ProcessService {
@Autowired
private VideoRepository videoRepository;
@PostConstruct
public void validateVideos() throws IOException, InterruptedException {
List<Video> response = videoRepository.findUrlByStatus(StatusEnum.NEW);
for(Video video : response) {
if(video.getStatus().equals(StatusEnum.NEW)){
downloadVideo(video.getUrl());
video.setStatus(StatusEnum.SAVED);
Outdated
Review

Hozz letre egy YtDlpService-t a VideoService mintajara es oda keruljon at a validateVideos() methodus.

Es nevezd at downloadNewVideos-ra

Hozz letre egy YtDlpService-t a VideoService mintajara es oda keruljon at a validateVideos() methodus. Es nevezd at downloadNewVideos-ra
videoRepository.save(video);
} else {
return;
}
Outdated
Review

Az adatbazisbol mar csak azokat a videokat akarjuk lekerdezni ahol a status new szoval itt folosleges megegyszer ellenorizni.

Amennyiben olyan videokat is vissza ad amiben a status nem new, ott akkor a lekerdezesd kell javitani nem pedig ujra ellenorizni.

Valszeg findByStatus(StatusEnum.NEW) az mukodik, a findUrlByStatus ugy hangzik mint ha a tablabol csak az URL oszlopot akarnad lekerdezni, de az egesz videot kered vissza. Szoval itt felre vezeto a methodus elnevezese es nem is biztos hogy azt csinalja amit kene.

Az adatbazisbol mar csak azokat a videokat akarjuk lekerdezni ahol a status new szoval itt folosleges megegyszer ellenorizni. Amennyiben olyan videokat is vissza ad amiben a status nem new, ott akkor a lekerdezesd kell javitani nem pedig ujra ellenorizni. Valszeg findByStatus(StatusEnum.NEW) az mukodik, a findUrlByStatus ugy hangzik mint ha a tablabol csak az URL oszlopot akarnad lekerdezni, de az egesz videot kered vissza. Szoval itt felre vezeto a methodus elnevezese es nem is biztos hogy azt csinalja amit kene.
}
}
//@PostConstruct
public void init() throws InterruptedException, IOException {
execute("yt-dlp", "youtube:player_client=android", "");
public void downloadVideo(String url) throws InterruptedException, IOException {
try {
execute("yt-dlp", "youtube:player_client=android", url);
} catch (Exception e) {
System.out.println("Something went awry.");
}
}
public void execute(String... command) throws InterruptedException, IOException {