From f13d3343826902352268c5370eabd62fd346c2d5 Mon Sep 17 00:00:00 2001 From: Arkaprabha Chakraborty Date: Fri, 9 Aug 2024 10:19:30 +0530 Subject: [PATCH] Refactor: change Python3 virtual environment path --- backend/Dockerfile | 8 ++++---- backend/main.go | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/backend/Dockerfile b/backend/Dockerfile index 471c269..726d649 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -26,14 +26,14 @@ RUN apk add --no-cache \ ffmpeg # Create a virtual environment for Python -RUN python3 -m venv /venv +RUN python3 -m venv venv # Activate the virtual environment and install yt-dlp -RUN /venv/bin/pip install --upgrade pip && \ - /venv/bin/pip install yt-dlp +RUN ./venv/bin/pip install --upgrade pip && \ + ./venv/bin/pip install yt-dlp # Ensure ffmpeg is in the PATH -ENV PATH="/usr/bin:/venv/bin:${PATH}" +ENV PATH="/usr/bin:${PATH}" # Expose port 8080 to the outside world EXPOSE 8080 diff --git a/backend/main.go b/backend/main.go index 4e6424c..e6a1c68 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", "--cookies", "cookies.txt", "--list-formats", url) + cmd := exec.Command("./venv/bin/python3", "-m", "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", "--cookies", "cookies.txt", "-f", videoFormat, "-o", videoPath, req.URL) + cmdVideo := exec.Command("./venv/bin/python3", "-m", "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", "--cookies", "cookies.txt", "-f", audioFormat, "-o", audioPath, req.URL) + cmdAudio := exec.Command("./venv/bin/python3", "-m", "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)) }