-
Notifications
You must be signed in to change notification settings - Fork 8
/
player.go
131 lines (121 loc) · 3.24 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package gulli
import (
"context"
"html"
"io/ioutil"
"regexp"
"strconv"
"strings"
"github.com/simulot/aspiratv/matcher"
"github.com/simulot/aspiratv/media"
"github.com/simulot/aspiratv/metadata/nfo"
"github.com/simulot/aspiratv/net/myhttp/httptest"
)
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, mr *matcher.MatchRequest, ID string) ([]*media.Media, error) {
ctx, done := context.WithTimeout(ctx, p.deadline)
defer done()
p.config.Log.Debug().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.config.Log.IsDebug() {
r = httptest.DumpReaderToFile(p.config.Log, r, "gulli-player-")
}
defer r.Close()
b, err := ioutil.ReadAll(r)
if err != nil {
return nil, err
}
match := reVars.FindAllStringSubmatch(string(b), -1)
shows := []*media.Media{}
var info *nfo.MediaInfo
parts := reVars.SubexpNames()
for _, m := range match {
for i, s := range m {
if i > 0 && len(s) > 0 {
switch parts[i] {
case "sources":
if info != nil {
if !p.seenShows[info.UniqueID[0].ID] {
shows = append(shows, &media.Media{
ID: info.UniqueID[0].ID,
Match: mr,
Metadata: &nfo.EpisodeDetails{
MediaInfo: *info,
},
})
}
p.seenShows[info.UniqueID[0].ID] = true
}
info = &nfo.MediaInfo{}
case "file":
if strings.HasSuffix(strings.ToLower(s), ".m3u8") {
info.MediaURL = s
}
case "image":
info.Thumb = []nfo.Thumb{
{
Aspect: "thumb",
URL: 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":
info.Showtitle = html.UnescapeString(s2)
case "saison":
info.Season, _ = strconv.Atoi(s2)
case "episode":
info.Episode, _ = strconv.Atoi(s2)
case "title":
info.Title = html.UnescapeString(s2)
}
}
}
case "mediaid":
info.UniqueID = []nfo.ID{
{
ID: s,
Type: "GULLITV",
},
}
info.Tag = []string{"Gulli"}
info.Genre = []string{"dessins animés", "enfants"}
case "description":
info.Plot = html.UnescapeString(s)
}
}
}
}
if info != nil && len(info.UniqueID) > 0 {
if !p.seenShows[info.UniqueID[0].ID] {
info.MediaType = nfo.TypeSeries
if info.Episode == 0 && info.Season == 0 {
info.MediaType = nfo.TypeMovie
}
shows = append(shows, &media.Media{
ID: info.UniqueID[0].ID,
Match: mr,
Metadata: &nfo.EpisodeDetails{
MediaInfo: *info,
},
})
}
p.seenShows[info.UniqueID[0].ID] = true
}
return shows, err
}