playlist_service #2
@@ -7,6 +7,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
public class VideoDownloaderApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(VideoDownloaderApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
|
||||
videoRepository.save(video);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
zoli
commented
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 {
|
||||
|
||||
Reference in New Issue
Block a user
Hozz letre egy YtDlpService-t a VideoService mintajara es oda keruljon at a validateVideos() methodus.
Es nevezd at downloadNewVideos-ra