Added video downloading from database url.
Added findByStatus, any entry with NEW status in the db will have their url returned. Currently to add entries to the database POSTMAN or other apps need to be used.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//@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