-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
59 lines (54 loc) · 1 KB
/
client.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package gotube
import (
"io/ioutil"
"log"
"net/http"
)
type Client struct {
*http.Client
}
func NewClient() *Client {
tp := &http.Transport{
Proxy: http.ProxyFromEnvironment,
}
// jar, err := cookiejar.New(nil)
// if err != nil {
// log.Fatal(err)
// return nil
// }
return &Client{&http.Client{
Transport: tp,
// Jar: jar,
}}
}
//get video's raw info
func (c *Client) GetRawInfo(url string) (*VideoRawInfo, error) {
resp, err := c.Get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
b, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
log.Println("read finished")
return GenerateVideoInfo(b)
}
//get info for common format
func (c *Client) GetInfo(url string) (*VideoInfo, error) {
resp, err := c.Get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
b, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
v, err := GenerateVideoInfo(b)
if err != nil {
return nil, err
}
return v.toVideoInfo(), nil
}