-
Notifications
You must be signed in to change notification settings - Fork 51
/
starz.go
42 lines (40 loc) · 1.14 KB
/
starz.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
package mediaunlocktest
import (
"encoding/json"
"io"
"net/http"
)
func Starz(c http.Client) Result {
resp, err := GET(c, "https://www.starz.com/sapi/header/v1/starz/us/09b397fc9eb64d5080687fc8a218775b", H{"Referer", "https://www.starz.com/us/en/"})
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}
}
authorization := string(b)
resp2, err := GET(c, "https://auth.starz.com/api/v4/User/geolocation", H{"AuthTokenAuthorization", authorization})
if err != nil {
return Result{Status: StatusNetworkErr, Err: err}
}
defer resp2.Body.Close()
b2, err := io.ReadAll(resp2.Body)
if err != nil {
return Result{Status: StatusNetworkErr, Err: err}
}
var res struct {
IsAllowedAccess bool
IsAllowedCountry bool
IsKnownProxy bool
Country string
}
if err := json.Unmarshal(b2, &res); err != nil {
return Result{Status: StatusErr, Err: err}
}
if res.IsAllowedAccess && res.IsAllowedCountry && !res.IsKnownProxy {
return Result{Status: StatusOK}
}
return Result{Status: StatusNo}
}