From 2dee4917d0b998e6d1a553d5edda8a04e5911537 Mon Sep 17 00:00:00 2001 From: HeshamTB Date: Thu, 14 Sep 2023 19:35:10 +0300 Subject: [PATCH] feat: only use '-f 22' on yt links --- yt.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/yt.go b/yt.go index b48f430..8cf1ee7 100644 --- a/yt.go +++ b/yt.go @@ -4,13 +4,32 @@ import ( "net/http" "net/url" "os/exec" + "strings" ) +// yt-dlp flags and options for all links +var ytdlpParams []string = []string{ + "--no-playlist", +} + +// yt-dlp flags and options only for youtube links +var ytlinkParams []string = []string{ + "--get-url", + "-f 22", +} + func getYoutubeDownloadURL(link string) (string, error) { var dlLink string - cmd := exec.Command("yt-dlp", "--get-url", "-f 22", link) + params := make([]string, 0) + params = append(params, ytdlpParams...) + + if isProbablyYT(link) { + params = append(params, ytlinkParams...) + } + + cmd := exec.Command("yt-dlp", link) result, err := cmd.Output() if err != nil { @@ -49,3 +68,7 @@ func isValidURL(data string) bool { return true } +func isProbablyYT(link string) bool { + return strings.Contains(link, "youtube") +} +