forked from nkeonkeo/MediaUnlockTest
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathEncoreTVB.go
45 lines (41 loc) · 1.48 KB
/
EncoreTVB.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
package mediaunlocktest
import (
"encoding/json"
"io"
"net/http"
)
func EncoreTVB(c http.Client) Result {
resp, err := GET(c, "https://edge.api.brightcove.com/playback/v1/accounts/5324042807001/videos/6005570109001",
H{"Accept", "application/json;pk=BCpkADawqM2Gpjj8SlY2mj4FgJJMfUpxTNtHWXOItY1PvamzxGstJbsgc-zFOHkCVcKeeOhPUd9MNHEGJoVy1By1Hrlh9rOXArC5M5MTcChJGU6maC8qhQ4Y8W-QYtvi8Nq34bUb9IOvoKBLeNF4D9Avskfe9rtMoEjj6ImXu_i4oIhYS0dx7x1AgHvtAaZFFhq3LBGtR-ZcsSqxNzVg-4PRUI9zcytQkk_YJXndNSfhVdmYmnxkgx1XXisGv1FG5GOmEK4jZ_Ih0riX5icFnHrgniADr4bA2G7TYh4OeGBrYLyFN_BDOvq3nFGrXVWrTLhaYyjxOr4rZqJPKK2ybmMsq466Ke1ZtE-wNQ"},
H{"Origin", "https://www.encoretvb.com"},
)
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 res1 struct {
ErrorSubcode string `json:"error_subcode"`
AccountId string `json:"account_id"`
}
var res2 []struct {
ErrorSubcode string `json:"error_subcode"`
//ClientGeo string `json:"client_geo"`
}
if err := json.Unmarshal(b, &res1); err != nil {
if err := json.Unmarshal(b, &res2); err != nil {
return Result{Status: StatusFailed, Err: err}
}
if res2[0].ErrorSubcode == "CLIENT_GEO" {
return Result{Status: StatusNo}
}
return Result{Status: StatusFailed, Err: err}
}
if res1.AccountId != "0" {
return Result{Status: StatusOK}
}
return Result{Status: StatusUnexpected}
}