2023-09-11 23:09:24 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"net/url"
|
|
|
|
"os/exec"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func getYoutubeDownloadURL(link string) (string, error) {
|
|
|
|
|
|
|
|
var dlLink string
|
|
|
|
cmd := exec.Command("yt-dlp", "--get-url", "-f 22", link)
|
|
|
|
result, err := cmd.Output()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
dlLink = string(result)
|
|
|
|
|
|
|
|
return dlLink, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func isValidURL(data string) bool {
|
|
|
|
|
|
|
|
_, err := url.ParseRequestURI(data)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-09-13 12:43:44 +02:00
|
|
|
httpClient := &http.Client{
|
|
|
|
CheckRedirect: func(req *http.Request, via []*http.Request) error {
|
|
|
|
return http.ErrUseLastResponse
|
|
|
|
},
|
|
|
|
}
|
2023-09-11 23:09:24 +02:00
|
|
|
resp, err := httpClient.Get(data)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
if resp.StatusCode != 200 {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|