Fix: no need to combine video and audio after downloading

This commit is contained in:
Arkaprabha Chakraborty
2024-08-10 20:41:38 +05:30
parent 395fbce5b3
commit 4e595fd179

View File

@@ -88,26 +88,13 @@ func downloadVideo(c echo.Context) error {
}()
uid := uuid.New().String()
videoPath := filepath.Join(tmpDir, fmt.Sprintf("video_%s.mp4", uid))
audioPath := filepath.Join(tmpDir, fmt.Sprintf("audio_%s.m4a", uid))
outputPath := filepath.Join(tmpDir, fmt.Sprintf("output_%s.mp4", uid))
// Download video
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("./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))
}
// Combine video and audio using ffmpeg
cmdMerge := exec.Command("ffmpeg", "-i", videoPath, "-i", audioPath, "-c", "copy", outputPath)
if err := cmdMerge.Run(); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to merge video and audio: %v", err))
// Download video and audio combined
combinedFormat := fmt.Sprintf("%s+%s", videoFormat, audioFormat)
cmdDownload := exec.Command("./venv/bin/python3", "-m", "yt_dlp", "--cookies", "cookies.txt", "-f", combinedFormat, "-o", outputPath, req.URL)
if err := cmdDownload.Run(); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to download video and audio: %v", err))
}
// Serve the file with appropriate headers