-
Notifications
You must be signed in to change notification settings - Fork 9
/
player.go
108 lines (96 loc) · 2.47 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package gulli
import (
"context"
"html"
"io/ioutil"
"log"
"regexp"
"strings"
"time"
"github.com/simulot/aspiratv/net/myhttp/httptest"
"github.com/simulot/aspiratv/providers"
)
const gullyPlayer = "http://replay.gulli.fr/jwplayer/embed/" // + VOD ID
var reTitle = regexp.MustCompile(`^(?P<show>.*)\s-\sS(?P<saison>\d+)\sép.\s(?P<episode>\d+)\s+:\s(?P<title>.*)$`)
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>[^"]*)"))` +
`|(?:description:\s*(?U:"(?P<description>[^"]*)"))`)
func (p *Gulli) getPlayer(ctx context.Context, ID string) ([]*providers.Show, error) {
ctx, done := context.WithTimeout(ctx, 30*time.Second)
defer done()
if p.debug {
log.Printf("[%s] Player URL: %q", p.Name(), gullyPlayer+ID)
}
r, err := p.getter.Get(ctx, gullyPlayer+ID)
if err != nil {
return nil, err
}
if p.debug {
r = httptest.DumpReaderToFile(r, "gulli-player-")
}
defer r.Close()
b, err := ioutil.ReadAll(r)
if err != nil {
return nil, err
}
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 {
p2 := reTitle.SubexpNames()
for j, s2 := range t[0] {
switch p2[j] {
case "show":
show.Show = html.UnescapeString(s2)
case "saison":
show.Season = s2
case "episode":
show.Episode = s2
case "title":
show.Title = html.UnescapeString(s2)
}
}
}
case "mediaid":
show.ID = s
show.Provider = p.Name()
show.Channel = "Gulli"
case "description":
show.Pitch = html.UnescapeString(s)
}
}
}
}
if show != nil {
if _, ok := p.seenShows[show.ID]; !ok {
shows = append(shows, show)
p.seenShows[show.ID] = true
}
}
return shows, err
}