package youtube import ( "github.com/rylio/ytdl" "os" ) func Get(url string) (string, error) { v, err := ytdl.GetVideoInfo(url) if err != nil { return "", err } u, err := v.GetDownloadURL(v.Formats.Best(ytdl.FormatResolutionKey)[0]) if err != nil { return "", err } return u.String(), nil } func Download(url string, file string) error { v, err := ytdl.GetVideoInfo(url) if err != nil { return err } format := v.Formats.Best(ytdl.FormatResolutionKey)[0] f, err := os.Create(file) if err != nil { return err } defer f.Close() return v.Download(format, f) }