From 21b60e90d2f4a0232fab26174594de6d497c3804 Mon Sep 17 00:00:00 2001 From: Arkaprabha Chakraborty Date: Fri, 9 Aug 2024 02:02:09 +0530 Subject: [PATCH] Load cookies via yt-dlp for YouTube access --- backend/main.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/main.go b/backend/main.go index bfd33ff..4e6424c 100644 --- a/backend/main.go +++ b/backend/main.go @@ -24,7 +24,7 @@ type VideoDownloadRequest struct { func getBestFormats(url string, targetResolution string) (string, string, error) { log.Printf("Getting best formats for URL: %s, target resolution: %s", url, targetResolution) - cmd := exec.Command("yt-dlp", "--list-formats", url) + cmd := exec.Command("yt-dlp", "--cookies", "cookies.txt", "--list-formats", url) output, err := cmd.CombinedOutput() if err != nil { return "", "", fmt.Errorf("failed to list formats: %v\nOutput: %s", err, string(output)) @@ -93,13 +93,13 @@ func downloadVideo(c echo.Context) error { outputPath := filepath.Join(tmpDir, fmt.Sprintf("output_%s.mp4", uid)) // Download video - cmdVideo := exec.Command("yt-dlp", "-f", videoFormat, "-o", videoPath, req.URL) + cmdVideo := exec.Command("yt-dlp", "--cookies", "cookies.txt", "-f", videoFormat, "-o", videoPath, req.URL) if err := cmdVideo.Run(); err != nil { return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to download video: %v", err)) } // Download audio - cmdAudio := exec.Command("yt-dlp", "-f", audioFormat, "-o", audioPath, req.URL) + cmdAudio := exec.Command("yt-dlp", "--cookies", "cookies.txt", "-f", audioFormat, "-o", audioPath, req.URL) if err := cmdAudio.Run(); err != nil { return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to download audio: %v", err)) }