mirror of
https://github.com/arkorty/DownLink.git
synced 2026-03-18 00:57:15 +00:00
Fix: no need to combine video and audio after downloading
This commit is contained in:
@@ -88,26 +88,13 @@ func downloadVideo(c echo.Context) error {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
uid := uuid.New().String()
|
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))
|
outputPath := filepath.Join(tmpDir, fmt.Sprintf("output_%s.mp4", uid))
|
||||||
|
|
||||||
// Download video
|
// Download video and audio combined
|
||||||
cmdVideo := exec.Command("./venv/bin/python3", "-m", "yt_dlp", "--cookies", "cookies.txt", "-f", videoFormat, "-o", videoPath, req.URL)
|
combinedFormat := fmt.Sprintf("%s+%s", videoFormat, audioFormat)
|
||||||
if err := cmdVideo.Run(); err != nil {
|
cmdDownload := exec.Command("./venv/bin/python3", "-m", "yt_dlp", "--cookies", "cookies.txt", "-f", combinedFormat, "-o", outputPath, req.URL)
|
||||||
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to download video: %v", err))
|
if err := cmdDownload.Run(); err != nil {
|
||||||
}
|
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to download video and audio: %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))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Serve the file with appropriate headers
|
// Serve the file with appropriate headers
|
||||||
|
|||||||
Reference in New Issue
Block a user