forked from nkeonkeo/MediaUnlockTest
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathNaverTV.go
executable file
·70 lines (59 loc) · 1.74 KB
/
NaverTV.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 (
"crypto/hmac"
"crypto/sha1"
"encoding/base64"
"encoding/json"
"io"
"net/http"
"net/url"
"strconv"
"strings"
"time"
)
func urlEncode(input string) string {
return url.QueryEscape(input)
}
func generateHMACSignature(key, data string) string {
h := hmac.New(sha1.New, []byte(key))
h.Write([]byte(data))
return base64.StdEncoding.EncodeToString(h.Sum(nil))
}
func NaverTV(c http.Client) Result {
timestamp := time.Now().UnixNano() / int64(time.Millisecond)
signature := generateHMACSignature(
"nbxvs5nwNG9QKEWK0ADjYA4JZoujF4gHcIwvoCxFTPAeamq5eemvt5IWAYXxrbYM",
"https://apis.naver.com/now_web2/now_web_api/v1/clips/31030608/play-info"+strconv.FormatInt(timestamp, 10),
)
resp, err := GET(c, "https://apis.naver.com/now_web2/now_web_api/v1/clips/31030608/play-info?msgpad="+strconv.FormatInt(timestamp, 10)+"&md="+urlEncode(signature),
H{"Connection", "keep-alive"},
H{"Accept", "application/json, text/plain, */*"},
H{"Origin", "https://tv.naver.com"},
H{"Referer", "https://tv.naver.com/v/31030608"},
)
if err != nil {
if strings.Contains(err.Error(), "EOF") {
return Result{Status: StatusBanned}
}
return Result{Status: StatusNetworkErr, Err: err}
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
return Result{Status: StatusNetworkErr, Err: err}
}
var res struct {
Playable string `json:"playable"`
}
err = json.Unmarshal(body, &res)
if err != nil {
return Result{Status: StatusErr, Err: err}
}
if res.Playable == "NOT_COUNTRY_AVAILABLE" {
return Result{Status: StatusNo}
}
if resp.StatusCode == 200 {
return Result{Status: StatusOK}
}
return Result{Status: StatusUnexpected}
}