From d6fe7825cee81f6531bc477f6bf8cc5c49035e67 Mon Sep 17 00:00:00 2001 From: Arkaprabha Chakraborty Date: Wed, 14 Aug 2024 19:25:16 +0530 Subject: [PATCH] Add support for instagram --- backend/main.go | 16 ++++++++++++++-- frontend/src/components/DownloadForm.js | 11 ++++++----- frontend/src/components/Home.js | 2 ++ 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/backend/main.go b/backend/main.go index 96fd63c..a93e772 100644 --- a/backend/main.go +++ b/backend/main.go @@ -7,6 +7,7 @@ import ( "os" "os/exec" "path/filepath" + "strings" "github.com/labstack/echo" "github.com/labstack/echo/middleware" @@ -44,8 +45,19 @@ func downloadVideo(c echo.Context) error { // Download video and audio combined quality := req.Quality[:len(req.Quality) - 1] - mergedFormat := fmt.Sprintf("bestvideo[height<=%s]+bestaudio/best[height<=%s]", quality, quality) - cmdDownload := exec.Command("./venv/bin/python3", "-m", "yt_dlp", "--cookies", "cookies.txt", "-f", mergedFormat, "--merge-output-format", "mp4", "-o", outputPath, req.URL) + + var mergedFormat string + var cookies string + + if strings.Contains(req.URL, "instagram.com/") { + mergedFormat = fmt.Sprintf("bestvideo[width<=%s]+bestaudio/best", quality) + cookies = "cookies_i.txt" + } else { + mergedFormat = fmt.Sprintf("bestvideo[height<=%s]+bestaudio/best[height<=%s]", quality, quality) + cookies = "cookies_y.txt" + } + + cmdDownload := exec.Command("./venv/bin/python3", "-m", "yt_dlp", "--cookies", cookies, "-f", mergedFormat, "--merge-output-format", "mp4", "-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)) } diff --git a/frontend/src/components/DownloadForm.js b/frontend/src/components/DownloadForm.js index 3ca6f07..e45c75d 100644 --- a/frontend/src/components/DownloadForm.js +++ b/frontend/src/components/DownloadForm.js @@ -13,9 +13,10 @@ const DownloadForm = () => { const [showConfetti, setShowConfetti] = useState(false); const [notification, setNotification] = useState(null); - const isValidYouTubeUrl = (url) => { - const youtubeRegex = /^(https?:\/\/)?(www\.)?(youtube\.com|youtu\.be)\/.+$/; - return youtubeRegex.test(url); + const isValidUrl = (url) => { + const legalDomains = + /^(https?:\/\/)?(www\.)?(youtube\.com|youtu\.be|instagram\.com)\/.+$/; + return legalDomains.test(url); }; const handleDownload = async (e) => { @@ -24,8 +25,8 @@ const DownloadForm = () => { if (!url) { setNotification("Maybe enter an URL first"); return; - } else if (!isValidYouTubeUrl(url)) { - setNotification("Doesn't look like YouTube to me"); + } else if (!isValidUrl(url)) { + setNotification("Doesn't look like a valid URL to me"); return; } diff --git a/frontend/src/components/Home.js b/frontend/src/components/Home.js index dbd762f..579a4ee 100644 --- a/frontend/src/components/Home.js +++ b/frontend/src/components/Home.js @@ -12,6 +12,8 @@ const Home = () => { sequence={[ "From YouTube!", 1200, + "And Instagram", + 1200, "Download Now!", 1200, "HD Quality!",