Skip downloading existing videos

This commit is contained in:
2024-11-05 15:58:52 +01:00
parent 52fdcc64ef
commit d8c4c343f4

View File

@@ -46,7 +46,6 @@ func DownloadR(url string) error {
OutputDir: OUTPUT_DIR, OutputDir: OUTPUT_DIR,
Client: client, Client: client,
} }
videoTitle := video.Title videoTitle := video.Title
videoAuthor := video.Author videoAuthor := video.Author
videoTitle = strings.ReplaceAll(videoTitle, " ", "-") videoTitle = strings.ReplaceAll(videoTitle, " ", "-")
@@ -56,11 +55,20 @@ func DownloadR(url string) error {
videoAuthor = strings.ReplaceAll(videoAuthor, "&", "and") videoAuthor = strings.ReplaceAll(videoAuthor, "&", "and")
videoAuthor = strings.ReplaceAll(videoAuthor, "?", "") videoAuthor = strings.ReplaceAll(videoAuthor, "?", "")
videoFileRoot := filepath.Join(OUTPUT_DIR, videoAuthor) videoFileRoot := filepath.Join(OUTPUT_DIR, videoAuthor)
err = os.MkdirAll(videoFileRoot, 0755) err = os.MkdirAll(videoFileRoot, 0755)
if err != nil { if err != nil {
return fmt.Errorf("failed creating directory %s with %+v", videoFileRoot, err) return fmt.Errorf("failed creating directory %s with %+v", videoFileRoot, err)
} }
fullVideoPath := filepath.Join(OUTPUT_DIR, videoAuthor, videoTitle+".mp4")
_, err = os.Open(fullVideoPath)
if err == nil {
log.Printf("File %s already exists, skipping download", fullVideoPath)
return nil
}
videoFile := filepath.Join(videoAuthor, videoTitle+".mp4") videoFile := filepath.Join(videoAuthor, videoTitle+".mp4")
err = downloader.DownloadComposite(context.Background(), videoFile, video, "hd", "mp4", "") err = downloader.DownloadComposite(context.Background(), videoFile, video, "hd", "mp4", "")
if err != nil { if err != nil {
@@ -73,3 +81,4 @@ func DownloadR(url string) error {
ongoingDownloadsMutex.Unlock() ongoingDownloadsMutex.Unlock()
return nil return nil
} }