feat: only use '-f 22' on yt links

This commit is contained in:
HeshamTB 2023-09-14 19:35:10 +03:00
parent 8fd3811a72
commit 2dee4917d0

25
yt.go
View File

@ -4,13 +4,32 @@ import (
"net/http" "net/http"
"net/url" "net/url"
"os/exec" "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) { func getYoutubeDownloadURL(link string) (string, error) {
var dlLink string 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() result, err := cmd.Output()
if err != nil { if err != nil {
@ -49,3 +68,7 @@ func isValidURL(data string) bool {
return true return true
} }
func isProbablyYT(link string) bool {
return strings.Contains(link, "youtube")
}