-
Notifications
You must be signed in to change notification settings - Fork 5
/
ytdl.go
33 lines (29 loc) · 641 Bytes
/
ytdl.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package main
import (
"context"
"errors"
"github.com/wader/goutubedl"
"io"
"time"
)
type ytdl struct{
res *goutubedl.Result
}
func (y *ytdl) Info(url string) (Info, error) {
r, err := goutubedl.New(context.TODO(), url, goutubedl.Options{})
if err != nil {
return Info{}, err
}
y.res = &r
return Info{
ext: r.Info.Ext,
id: r.Info.ID,
duration: time.Duration(int64(r.Info.Duration)) * time.Second,
}, nil
}
func (y *ytdl) Download(url string) (io.ReadCloser, error) {
if y.res == nil {
return nil, errors.New("call Info() first to get download details")
}
return y.res.Download(context.TODO(),"best")
}