-
Notifications
You must be signed in to change notification settings - Fork 6
/
pluto.go
101 lines (89 loc) · 2.06 KB
/
pluto.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package pluto
import (
"encoding/json"
"errors"
"net/http"
"net/url"
"strings"
)
func (v Video) Clip() (*EpisodeClip, error) {
req, err := http.NewRequest("GET", "http://api.pluto.tv", nil)
if err != nil {
return nil, err
}
req.URL.Path = func() string {
var b strings.Builder
b.WriteString("/v2/episodes/")
if v.ID != "" {
b.WriteString(v.ID)
} else {
b.WriteString(v.Episode)
}
b.WriteString("/clips.json")
return b.String()
}()
res, err := http.DefaultClient.Do(req)
if err != nil {
return nil, err
}
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
return nil, errors.New(res.Status)
}
var clips []EpisodeClip
err = json.NewDecoder(res.Body).Decode(&clips)
if err != nil {
return nil, err
}
return &clips[0], nil
}
type Poster struct{}
func (Poster) RequestUrl() (string, bool) {
return "https://service-concierge.clusters.pluto.tv/v1/wv/alt", true
}
func (Poster) RequestHeader() (http.Header, error) {
return http.Header{}, nil
}
func (Poster) WrapRequest(b []byte) ([]byte, error) {
return b, nil
}
func (Poster) UnwrapResponse(b []byte) ([]byte, error) {
return b, nil
}
type EpisodeClip struct {
Sources []Source
}
func (e EpisodeClip) DASH() (*Source, bool) {
for _, s := range e.Sources {
if s.Type == "DASH" {
return &s, true
}
}
return nil, false
}
type Source struct {
File string
Type string
}
var Base = []string{
// these return `403 OK` with compressed content
"http://siloh-fs.plutotv.net",
"http://siloh-ns1.plutotv.net",
"https://siloh-fs.plutotv.net",
"https://siloh-ns1.plutotv.net",
// returns `200 OK` with plain content
"http://silo-hybrik.pluto.tv.s3.amazonaws.com",
}
func (s Source) Parse(base string) (*url.URL, error) {
a, err := url.Parse(base)
if err != nil {
return nil, err
}
b, err := url.Parse(s.File)
if err != nil {
return nil, err
}
b.Scheme = a.Scheme
b.Host = a.Host
return b, nil
}