yzqzss
f7a50c6101
All checks were successful
Gitea Go Release Actions / Release Go Binary (arm, linux) (push) Successful in 1m0s
Gitea Go Release Actions / Release Go Binary (amd64, linux) (push) Successful in 1m7s
Gitea Go Release Actions / Release Go Binary (arm64, linux) (push) Successful in 48s
Gitea Go Release Actions / Release Go Binary (arm64, darwin) (push) Successful in 53s
Gitea Go Release Actions / Release Go Binary (amd64, windows) (push) Successful in 2m22s
Gitea Go Release Actions / Release Go Binary (amd64, darwin) (push) Successful in 28s
77 lines
1.9 KiB
Go
77 lines
1.9 KiB
Go
package acfun_api
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"log"
|
|
"net/http"
|
|
"net/url"
|
|
"os"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/tidwall/gjson"
|
|
)
|
|
|
|
var Logger = log.New(os.Stdout, "[acfun_api] ", log.Ldate|log.Ltime|log.Lmsgprefix)
|
|
|
|
// var json = jsoniter.ConfigCompatibleWithStandardLibrary
|
|
|
|
func GetDanmaku(client *http.Client, resource_id string) ([]string, error) {
|
|
danmakus := []string{}
|
|
pcursor := "1"
|
|
for {
|
|
|
|
data := url.Values{
|
|
"resourceId": {resource_id},
|
|
"resourceType": {"9"},
|
|
"enableAdvanced": {"true"},
|
|
"pcursor": {pcursor},
|
|
"count": {"200"},
|
|
"sortType": {"1"},
|
|
"asc": {"false"},
|
|
}
|
|
dataEncoded := data.Encode()
|
|
|
|
req, err := http.NewRequest("POST", "https://www.acfun.cn/rest/pc-direct/new-danmaku/list", strings.NewReader(dataEncoded))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
req.Header.Set("Accept", "application/json, text/plain, */*")
|
|
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36 Viewer/99.9.8782.87")
|
|
|
|
response, err := client.Do(req)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if response.StatusCode != 200 {
|
|
panic("StatusCode != 200")
|
|
}
|
|
|
|
body, err := io.ReadAll(response.Body)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
result := gjson.GetBytes(body, "result").Int()
|
|
if result != 0 {
|
|
// panic(gjson.GetBytes(body, "error_msg").String())
|
|
return nil, fmt.Errorf("result != 0: %s", gjson.GetBytes(body, "error_msg").String())
|
|
}
|
|
pcursor = gjson.GetBytes(body, "pcursor").String()
|
|
|
|
for _, danmaku := range gjson.GetBytes(body, "danmakus").Array() {
|
|
danmakus = append(danmakus, danmaku.Raw)
|
|
}
|
|
|
|
Logger.Println(resource_id, "pcursor", pcursor, len(danmakus), "danmakus")
|
|
if pcursor == "no_more" {
|
|
break
|
|
}
|
|
time.Sleep(1 * time.Second)
|
|
}
|
|
return danmakus, nil
|
|
}
|