YTSFlix_Go/youtube/youtube.go

33 lines
585 B
Go
Raw Normal View History

2018-11-04 14:58:15 +00:00
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)
}