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") +} +