-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
173 lines (145 loc) · 4.12 KB
/
main.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"net/url"
"strconv"
"strings"
"sync"
"time"
)
var (
appealCount int
mutex sync.Mutex
cookie = "YOUR_BILIBILI_JCT_AND_SESSDATA"
)
func Appeal(aid string) {
urlStr := "https://api.bilibili.com/x/web-interface/archive/appeal?jsonp=jsonp&csrf=097af8caab0ffc4e26f6be4b557ab972"
queryParams := url.Values{}
queryParams.Set("aid", aid)
queryParams.Set("attach", "")
queryParams.Set("desc", "标题")
queryParams.Set("tid", "5")
requestBody := bytes.NewBufferString(queryParams.Encode())
//Create POST request
req, err := http.NewRequest("POST", urlStr, requestBody)
if err != nil {
fmt.Println("Error creating request:", err)
return
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36")
req.Header.Set("Cookie", cookie)
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Println("Error making request:", err)
return
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
fmt.Println("Error reading response body:", err)
return
}
fmt.Println("Response Status:", resp.Status)
fmt.Println("Response Body:", string(body))
var data map[string]interface{}
err = json.Unmarshal(body, &data)
if err != nil {
fmt.Println("Error decoding response body:", err)
return
}
if data["code"] == float64(0) {
mutex.Lock()
appealCount++
mutex.Unlock()
}
}
func SearchAndappeal(page int) {
urlStr := "https://api.bilibili.com/x/web-interface/search/type"
queryParams := url.Values{}
queryParams.Set("search_type", "video")
queryParams.Set("keyword", "收米直播 b775")
queryParams.Set("page", strconv.Itoa(page))
fullUrl := fmt.Sprintf("%s?%s", urlStr, queryParams.Encode())
req, err := http.NewRequest("GET", fullUrl, nil)
if err != nil {
fmt.Println("Error creating request:", err)
return
}
// 设置请求头
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36")
req.Header.Set("Cookie", cookie)
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Println("Error making request:", err)
return
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
fmt.Println("Error reading response body:", err)
return
}
//fmt.Println("Response Status:", resp.Status)
//fmt.Println("Response Body:", string(body))
var jsonData map[string]interface{}
err = json.Unmarshal(body, &jsonData)
if err != nil {
fmt.Println("Error parsing JSON:", err)
return
}
data, ok := jsonData["data"].(map[string]interface{})
if !ok {
fmt.Println("'data' not found or is not an object")
return
}
// 寻找'result'字段
results, ok := data["result"].([]interface{})
if !ok {
fmt.Println("'result' not found or is not an array")
return
}
for _, result := range results {
res, ok := result.(map[string]interface{})
if !ok {
fmt.Println("Error: result is not a map")
continue
}
title := res["title"].(string)
//strings.Contains(title, "\uE708")
if strings.Contains(title, "2023已更新") || strings.Contains(title, "网站") || strings.Contains(title, "体育") || strings.Contains(title, "app") {
aidFloat, ok := res["aid"].(float64)
if !ok {
panic("aid is not of type float64")
}
aidString := fmt.Sprintf("%.0f", aidFloat)
Appeal(aidString)
fmt.Printf("Appeal Aid: %s sent, waiting 2 seconds...\n", aidString)
time.Sleep(2 * time.Second)
}
// }
//}
}
}
func main() {
var wg sync.WaitGroup
ch := make(chan struct{}, 10) // 创建一个具有10个缓冲区的通道
for i := 1; i < 50; i++ {
wg.Add(1)
ch <- struct{}{} // 向通道发送一个值,以便让另一个goroutine可以开始执行
go func(i int) {
defer wg.Done()
SearchAndappeal(i)
<-ch // 当goroutine完成时,从通道中接收一个值
}(i)
}
wg.Wait()
print("Video appealed: ", appealCount)
}