-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse.go
47 lines (42 loc) · 950 Bytes
/
parse.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
package main
import (
"bufio"
"bytes"
"regexp"
"strings"
"github.com/PuerkitoBio/goquery"
"github.com/pkg/errors"
"github.com/tidwall/gjson"
)
var initUriRe = regexp.MustCompile(`#EXT-X-MAP:URI="(.+)"`)
func ParseM3u8URL(doc *goquery.Document) (string, error) {
node := doc.Find("[data-movie-playlist]").First()
v, ok := node.Attr("data-movie-playlist")
if !ok {
return "", errors.Errorf("metadata not found")
}
v = gjson.Get(v, "2.0.source.url").String()
if v == "" {
return "", errors.Errorf("source url not found")
}
return v, nil
}
func ParseSegPath(b []byte) []string {
s := []string{}
scaner := bufio.NewScanner(bytes.NewBuffer(b))
for scaner.Scan() {
line := scaner.Text()
if line == "" {
continue
}
switch {
case strings.HasPrefix(line, "#EXT-X-MAP"):
line = initUriRe.FindStringSubmatch(line)[1]
case !strings.HasPrefix(line, "#"):
default:
continue
}
s = append(s, line)
}
return s
}