forked from nkeonkeo/MediaUnlockTest
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathGooglePlayStore.go
44 lines (38 loc) · 954 Bytes
/
GooglePlayStore.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
package mediaunlocktest
import (
//"fmt"
"io"
"net/http"
"regexp"
"strings"
)
func extractGooglePlayStoreRegion(responseBody string) string {
re := regexp.MustCompile(`"zQmIje"\s*:\s*"([^"]+)"`)
match := re.FindStringSubmatch(responseBody)
if len(match) > 1 {
return match[1]
}
return ""
}
func GooglePlayStore(c http.Client) Result {
resp, err := GET(c, "https://play.google.com/store/games")
if err != nil {
return Result{Status: StatusNetworkErr, Err: err}
}
defer resp.Body.Close()
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
return Result{Status: StatusNetworkErr, Err: err}
}
bodyString := string(bodyBytes)
if resp.StatusCode == 200 {
region := extractGooglePlayStoreRegion(bodyString)
if region != "" {
if region == "CN" {
return Result{Status: StatusNo, Region: "cn"}
}
return Result{Status: StatusOK, Region: strings.ToLower(region)}
}
}
return Result{Status: StatusUnexpected}
}