76 lines
1.8 KiB
Go
76 lines
1.8 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"regexp"
|
|
"strconv"
|
|
)
|
|
|
|
// EPData 视频信息
|
|
type EPData struct {
|
|
Aid int64 `json:"aid"`
|
|
Badge string `json:"badge"`
|
|
BadgeType int64 `json:"badge_type"`
|
|
Cid int64 `json:"cid"`
|
|
Cover string `json:"cover"`
|
|
From string `json:"from"`
|
|
ID int64 `json:"id"`
|
|
LongTitle string `json:"long_title"`
|
|
ShareURL string `json:"share_url"`
|
|
Stat struct {
|
|
Danmakus int64 `json:"danmakus"`
|
|
Play int64 `json:"play"`
|
|
} `json:"stat"`
|
|
Status int64 `json:"status"`
|
|
Title string `json:"title"`
|
|
Vid string `json:"vid"`
|
|
}
|
|
|
|
// SectionResponse 获取section数据的返回
|
|
type SectionResponse struct {
|
|
Code int64 `json:"code"`
|
|
Message string `json:"message"`
|
|
Result struct {
|
|
MainSection struct {
|
|
Episodes []EPData `json:"episodes"`
|
|
ID int64 `json:"id"`
|
|
Title string `json:"title"`
|
|
Type int64 `json:"type"`
|
|
} `json:"main_section"`
|
|
Section []interface{} `json:"section"`
|
|
} `json:"result"`
|
|
}
|
|
|
|
// GetEPData 根据videoNo从bilibili获取av数据
|
|
func (provider *episodeDataProvider) GetEPData(epNo int64) (epdatas []EPData, err error) {
|
|
htmlByte, err := provider.dataSource.GetEPData(epNo)
|
|
if err != nil {
|
|
return
|
|
}
|
|
// the regex rule is: \"ssId\":\d+
|
|
re, err := regexp.Compile("\\\"ssId\\\":(\\d+)")
|
|
if err != nil {
|
|
return
|
|
}
|
|
ssidResult := re.Find(htmlByte)
|
|
if len(ssidResult) == 0 {
|
|
return epdatas, errors.New("ssid not found")
|
|
}
|
|
ssid := string(ssidResult)[7:]
|
|
ssNo, err := strconv.ParseInt(ssid, 10, 64)
|
|
if err != nil {
|
|
return
|
|
}
|
|
ssByte, err := provider.dataSource.GetSSData(ssNo)
|
|
if err != nil {
|
|
return
|
|
}
|
|
var resp SectionResponse
|
|
err = json.Unmarshal(ssByte, &resp)
|
|
if err != nil {
|
|
return
|
|
}
|
|
return resp.Result.MainSection.Episodes, err
|
|
}
|