-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathyouku.go
49 lines (36 loc) · 917 Bytes
/
youku.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 (
"regexp"
"errors"
"fmt"
"time"
)
func parseYouku(url string, opts... interface{}) (err error, m3u8url,body string, desc string) {
var ma []string
var re *regexp.Regexp
body, err = curl(url, opts...)
if err != nil {
err = errors.New(fmt.Sprintf("curl index failed: %v", err))
return
}
re, err = regexp.Compile(`<meta name="title" content="([^"]+)">`)
ma = re.FindStringSubmatch(body)
if len(ma) >= 2 {
desc = ma[1]
}
re, err = regexp.Compile(`videoId = '([^']+)'`)
ma = re.FindStringSubmatch(body)
if len(ma) != 2 {
err = errors.New("cannot find videoId")
return
}
vid := ma[1]
tms := fmt.Sprintf("%d", time.Now().Unix())
m3u8url = "http://www.youku.com/player/getM3U8/vid/" + vid + "/type/hd2/ts/" + tms + "/v.m3u8"
body, err = curl(m3u8url, opts...)
if err != nil {
err = errors.New(fmt.Sprintf("curl m3u8 failed: %v", err))
return
}
return
}