-
Notifications
You must be signed in to change notification settings - Fork 51
/
VideoMarket.go
92 lines (80 loc) · 2.42 KB
/
VideoMarket.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
package mediaunlocktest
import (
"context"
"encoding/json"
"io"
"net/http"
"strings"
"time"
)
func VideoMarket(c http.Client) Result {
resp, err := PostForm(c, "https://api-p.videomarket.jp/v2/authorize/access_token",
`grant_type=client_credentials&client_id=1eolxdrti3t58m2f2k8yi0kli105743b6f8c8295&client_secret=lco0nndn3l9tcbjdfdwlswmee105743b739cfb5a`,
)
if err != nil {
return Result{Status: StatusNetworkErr, Err: err}
}
defer resp.Body.Close()
b, err := io.ReadAll(resp.Body)
if err != nil {
return Result{Status: StatusNetworkErr, Err: err}
}
// log.Println(string(b))
var res resVideoMarketToken
if err := json.Unmarshal(b, &res); err != nil {
return Result{Status: StatusErr, Err: err}
}
if res.AccessToken == "" {
return Result{Status: StatusNo}
}
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
req, err := http.NewRequestWithContext(ctx, "POST", "https://api-p.videomarket.jp/v2/api/play/keyissue", strings.NewReader(
`fullStoryId=118008001&playChromeCastFlag=false&loginFlag=0`,
))
if err != nil {
return Result{Status: StatusNetworkErr, Err: err}
}
req.Header.Set("User-Agent", UA_Browser)
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.Header.Set("X-Authorization", res.AccessToken)
resp, err = cdo(c, req)
if err != nil {
return Result{Status: StatusNetworkErr, Err: err}
}
defer resp.Body.Close()
b, err = io.ReadAll(resp.Body)
if err != nil {
return Result{Status: StatusNetworkErr, Err: err}
}
var rpk resVideoMarketPlayKey
if err := json.Unmarshal(b, &rpk); err != nil {
return Result{Status: StatusErr, Err: err}
}
req, err = http.NewRequestWithContext(ctx, "GET", "https://api-p.videomarket.jp/v2/api/play/keyauth?playKey="+rpk.PlayKey+"&deviceType=3&bitRate=0&loginFlag=0&connType=", nil)
if err != nil {
return Result{Status: StatusNetworkErr, Err: err}
}
req.Header.Set("User-Agent", UA_Browser)
req.Header.Set("X-Authorization", res.AccessToken)
resp, err = cdo(c, req)
if err != nil {
return Result{Status: StatusNetworkErr, Err: err}
}
defer resp.Body.Close()
switch resp.StatusCode {
case 200:
return Result{Status: StatusOK}
case 408:
return Result{Status: StatusOK}
case 403:
return Result{Status: StatusNo}
}
return Result{Status: StatusUnexpected}
}
type resVideoMarketToken struct {
AccessToken string `json:"access_token"`
}
type resVideoMarketPlayKey struct {
PlayKey string
}