91 lines
2.0 KiB
Go
91 lines
2.0 KiB
Go
package internal
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"io"
|
|
"log"
|
|
"net/http"
|
|
)
|
|
|
|
type SongMessage struct {
|
|
Video_stat VideoStat `json:"video_stat"`
|
|
Video_info VideoInfo `json:"video_info"`
|
|
Video_id VideoID `json:"video_id"`
|
|
Video_increase VideoIncrease `json:"video_increase"`
|
|
Vrank_info VrankInfo `json:"vrank_info"`
|
|
}
|
|
|
|
type VideoStat struct {
|
|
View int `json:"view"`
|
|
Like int `json:"like"`
|
|
Coin int `json:"coin"`
|
|
Favorite int `json:"favorite"`
|
|
Reply int `json:"reply"`
|
|
Share int `json:"share"`
|
|
Danmaku int `json:"danmaku"`
|
|
}
|
|
|
|
type VideoInfo struct {
|
|
Uploader_mid string `json:"uploader_mid"`
|
|
Uploader_name string `json:"uploader_name"`
|
|
Title string `json:"title"`
|
|
Pic string `json:"pic"`
|
|
Pages int `json:"pages"`
|
|
Timestamp int64 `json:"timestamp"`
|
|
}
|
|
|
|
type VideoID struct {
|
|
Avid string `json:"avid"`
|
|
Bvid string `json:"bvid"`
|
|
Tid int `json:"tid"`
|
|
}
|
|
|
|
type VideoIncrease struct {
|
|
View int `json:"view"`
|
|
Like int `json:"like"`
|
|
Coin int `json:"coin"`
|
|
Favorite int `json:"favorite"`
|
|
Reply int `json:"reply"`
|
|
Share int `json:"share"`
|
|
Danmaku int `json:"danmaku"`
|
|
}
|
|
|
|
type VrankInfo struct {
|
|
Vrank_score float64 `json:"vrank_score"`
|
|
Rank string `json:"rank"`
|
|
Rank_code int `json:"rank_code"`
|
|
Progress_percentage float64 `json:"progress_percentage"`
|
|
}
|
|
|
|
func Monitor(bvid string) (SongData *SongMessage, error error) {
|
|
|
|
url := fmt.Sprintf("https://api.mmeiblog.cn/NineVocalRank/vocaloid_rank/v1/video/%s", bvid)
|
|
method := "GET"
|
|
client := &http.Client{}
|
|
req, err := http.NewRequest(method, url, nil)
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
return
|
|
}
|
|
res, err := client.Do(req)
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
return
|
|
}
|
|
defer res.Body.Close()
|
|
body, err := io.ReadAll(res.Body)
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
return
|
|
}
|
|
|
|
var Data SongMessage
|
|
err = json.Unmarshal(body, &Data)
|
|
if err != nil {
|
|
log.Printf("解析JSON失败: %v\n", err)
|
|
return nil, err
|
|
}
|
|
return &Data, nil
|
|
}
|