-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsohu.go
55 lines (40 loc) · 939 Bytes
/
sohu.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
package main
import (
"regexp"
"errors"
"fmt"
"os"
)
func parseSohu(url string, opts... interface{}) (err error, m3u8url,body string, desc string) {
var re *regexp.Regexp
var ma []string
body, err = curl(url, opts...)
if err != nil {
err = errors.New(fmt.Sprintf("curl index failed: %v", err))
return
}
re, err = regexp.Compile(`<title>([^<]+)</title>`)
ma = re.FindStringSubmatch(body)
if len(ma) >= 2 {
desc = gbk2utf(ma[1])
}
re, err = regexp.Compile(`var vid="([^"]+)"`)
ma = re.FindStringSubmatch(body)
if len(ma) != 2 {
err = errors.New(fmt.Sprintf("sohu: cannot find vid: ma = %v", ma))
return
}
vid := ma[1]
m3u8url = "http://hot.vrs.sohu.com/ipad"+vid+".m3u8"
body, err = curl(m3u8url, opts...)
if err != nil {
err = errors.New(fmt.Sprintf("fetch m3u8 failed: %v", err))
return
}
if false {
f, _ := os.Create("/tmp/m3u8")
fmt.Fprintf(f, "%v", body)
f.Close()
}
return
}