forked from nkeonkeo/MediaUnlockTest
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathBahamutAnime.go
70 lines (68 loc) · 1.89 KB
/
BahamutAnime.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
package mediaunlocktest
import (
"encoding/json"
"io"
"strings"
"net/http"
"net/http/cookiejar"
)
func BahamutAnime(c http.Client) Result {
c.Jar, _ = cookiejar.New(nil)
resp, err := GET(c, "https://ani.gamer.com.tw/ajax/getdeviceid.php")
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 res struct {
AnimeSn int
Deviceid string
}
if err := json.Unmarshal(b, &res); err != nil {
if err.Error() == "invalid character '<' looking for beginning of value" {
return Result{Status: StatusNo}
}
return Result{Status: StatusErr, Err: err}
}
resp, err = GET(c, "https://ani.gamer.com.tw/ajax/token.php?adID=89422&sn=14667&device="+res.Deviceid)
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}
}
if err := json.Unmarshal(b, &res); err != nil {
return Result{Status: StatusErr, Err: err}
}
if res.AnimeSn != 0 {
resp, err = GET(c, "https://ani.gamer.com.tw/cdn-cgi/trace")
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}
}
bodyString := string(b)
index := strings.Index(bodyString, "loc=")
if index == -1 {
return Result{Status: StatusUnexpected}
}
bodyString = bodyString[index+4:]
index = strings.Index(bodyString, "\n")
if index == -1 {
return Result{Status: StatusUnexpected}
}
loc := bodyString[:index]
if len(loc) == 2 {
return Result{Status: StatusOK, Region: strings.ToLower(loc)}
}
}
return Result{Status: StatusUnexpected}
}