YTSFlix_Go/youtube/youtube.go
2018-11-04 15:58:15 +01:00

33 lines
585 B
Go

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