forked from iawia002/lux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
streamtape.go
88 lines (74 loc) · 1.93 KB
/
streamtape.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
package streamtape
import (
"fmt"
"github.com/pkg/errors"
"github.com/robertkrimen/otto"
"github.com/wanyuqin/lux/extractors"
"github.com/wanyuqin/lux/request"
"github.com/wanyuqin/lux/utils"
)
func init() {
e := New()
extractors.Register("streamtape", e)
extractors.Register("streamta", e) // streamta.pe
}
type extractor struct{}
// New returns a StreamTape extractor
func New() extractors.Extractor {
return &extractor{}
}
// Extract is the main function to extract the data.
func (e *extractor) Extract(url string, _ extractors.Options) ([]*extractors.Data, error) {
html, err := request.Get(url, url, nil)
if err != nil {
return nil, errors.WithStack(err)
}
scripts := utils.MatchOneOf(html, `document.getElementById\('norobotlink'\).innerHTML = (.+?);`)
if len(scripts) < 2 {
return nil, errors.WithStack(extractors.ErrURLParseFailed)
}
vm := otto.New()
_, err = vm.Run(fmt.Sprintf("var __VM__OUTPUT = %s", scripts[1]))
if err != nil {
return nil, errors.WithStack(err)
}
value, err := vm.Get("__VM__OUTPUT")
if err != nil {
return nil, errors.WithStack(err)
}
u, err := value.ToString() // //streamtape.com/get_video?id=xx&expires=xx&ip=xx&token=xx
if err != nil {
return nil, errors.WithStack(err)
}
u = fmt.Sprintf("https:%s&stream=1", u)
// get title
var title = "StreamTape Video"
titleMatch := utils.MatchOneOf(html,
`\<meta name="og:title" content="(.*)"\>`)
if len(titleMatch) >= 2 {
title = titleMatch[1]
}
size, err := request.Size(u, url)
if err != nil {
return nil, errors.WithStack(err)
}
urlData := &extractors.Part{
URL: u,
Size: size,
Ext: "mp4",
}
streams := make(map[string]*extractors.Stream)
streams["default"] = &extractors.Stream{
Parts: []*extractors.Part{urlData},
Size: size,
}
return []*extractors.Data{
{
URL: u,
Site: "StreamTape streamtape.com",
Title: title,
Type: extractors.DataTypeVideo,
Streams: streams,
},
}, nil
}