-
Notifications
You must be signed in to change notification settings - Fork 9
/
player.go
87 lines (75 loc) · 1.96 KB
/
player.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
package gulli
import (
"html"
"io/ioutil"
"regexp"
"strings"
"github.com/simulot/aspiratv/providers"
)
const gullyPlayer = "http://replay.gulli.fr/jwplayer/embed/" // + VOD ID
var reTitle = regexp.MustCompile(`^(.*)\s\-\sSaison\s(\d+),\sEpisode\s(\d+)\s:\s(.*)$`)
var reVars = regexp.MustCompile(
`(?m)(?P<sources>sources:)` +
`|(?:file:\s*(?U:"(?P<file>[^"]*)"))` +
`|(?:mediaid:\s*(?U:"(?P<mediaid>[^"]*)"))` +
`|(?:playlist_title:\s*(?U:"(?P<playlist_title>[^"]*)"))` +
`|(?:image:\s*(?U:"(?P<image>[^"]*)"))`)
func (p *Gulli) getPlayer(ShowUrl, ID string, destination string) ([]*providers.Show, error) {
r, err := p.getter.Get(gullyPlayer + ID)
if err != nil {
return nil, err
}
b, err := ioutil.ReadAll(r)
if err != nil {
return nil, err
}
BaseShowURL := ShowUrl
i := strings.LastIndex(ShowUrl, "/")
if i >= 0 {
BaseShowURL = ShowUrl[:i+1]
}
match := reVars.FindAllStringSubmatch(string(b), -1)
shows := []*providers.Show{}
var show *providers.Show
parts := reVars.SubexpNames()
for _, m := range match {
for i, s := range m {
if i > 0 && len(s) > 0 {
switch parts[i] {
case "sources":
if show != nil {
if !p.seenShows[show.ID] {
shows = append(shows, show)
}
p.seenShows[show.ID] = true
}
show = &providers.Show{}
case "file":
if strings.HasSuffix(strings.ToLower(s), ".m3u8") {
show.StreamURL = s
}
case "image":
show.ThumbnailURL = s
case "playlist_title":
t := reTitle.FindAllStringSubmatch(s, -1)
if len(t) > 0 && len(t[0]) == 5 {
show.Show = html.UnescapeString(t[0][1])
show.Season = t[0][2]
show.Episode = t[0][3]
show.Title = html.UnescapeString(t[0][4])
}
case "mediaid":
show.ID = s
show.ShowURL = BaseShowURL + show.ID
show.Provider = p.Name()
show.Destination = destination
}
}
}
}
if show != nil {
shows = append(shows, show)
p.seenShows[show.ID] = true
}
return shows, err
}