From 51d23d28695be99719972a2b21189fe0756962b0 Mon Sep 17 00:00:00 2001 From: buddingworld <109396464+buddingworld@users.noreply.github.com> Date: Sat, 12 Oct 2024 13:49:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=B4=E6=97=B6=E4=BF=AE=E5=A4=8DB=E7=AB=99E?= =?UTF-8?q?P=E8=A7=86=E9=A2=91=E6=97=A0=E6=B3=95=E4=B8=8B=E8=BD=BD=20(#138?= =?UTF-8?q?9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update bilibili.go * Update types.go * Update bilibili.go --- extractors/bilibili/bilibili.go | 40 ++++++++++++++------------------- extractors/bilibili/types.go | 27 +++++++++++++--------- 2 files changed, 34 insertions(+), 33 deletions(-) diff --git a/extractors/bilibili/bilibili.go b/extractors/bilibili/bilibili.go index 26c790ea8..313197dac 100644 --- a/extractors/bilibili/bilibili.go +++ b/extractors/bilibili/bilibili.go @@ -96,32 +96,26 @@ type bilibiliOptions struct { func extractBangumi(url, html string, extractOption extractors.Options) ([]*extractors.Data, error) { dataString := utils.MatchOneOf(html, `(.*?)`)[1] - epArrayString := utils.MatchOneOf(dataString, `"episodes"\s*:\s*(.+?)\s*,\s*"user_status"`)[1] + epArrayString := utils.MatchOneOf(dataString, `"episode_info"\s*:\s*(.+?)\s*,\s*"season_info"`)[1] fullVideoIdString := utils.MatchOneOf(dataString, `"videoId"\s*:\s*"(ep|ss)(\d+)"`) epSsString := fullVideoIdString[1] // "ep" or "ss" videoIdString := fullVideoIdString[2] - var epArray []json.RawMessage + var epArray EpVideoInfo err := json.Unmarshal([]byte(epArrayString), &epArray) if err != nil { return nil, errors.WithStack(err) } var data bangumiData - for _, jsonByte := range epArray { - var epInfo bangumiEpData - err := json.Unmarshal(jsonByte, &epInfo) - if err != nil { - return nil, errors.WithStack(err) - } - videoId, err := strconv.ParseInt(videoIdString, 10, 0) - if err != nil { - return nil, errors.WithStack(err) - } - if epInfo.ID == int(videoId) || (epSsString == "ss" && epInfo.TitleFormat == "第1话") { - data.EpInfo = epInfo - } - data.EpList = append(data.EpList, epInfo) + + videoId, err := strconv.ParseInt(videoIdString, 10, 0) + if err != nil { + return nil, errors.WithStack(err) + } + if epArray.EpID == int(videoId) || (epSsString == "ss" && epArray.Title == "第1话") { + data.EpInfo = epArray } + data.EpList = append(data.EpList, epArray) sort.Slice(data.EpList, func(i, j int) bool { return data.EpList[i].EpID < data.EpList[j].EpID @@ -130,14 +124,14 @@ func extractBangumi(url, html string, extractOption extractors.Options) ([]*extr if !extractOption.Playlist { aid := data.EpInfo.Aid cid := data.EpInfo.Cid - bvid := data.EpInfo.BVid - titleFormat := data.EpInfo.TitleFormat + bvid := data.EpInfo.Bvid + titleFormat := data.EpInfo.Title longTitle := data.EpInfo.LongTitle if aid <= 0 || cid <= 0 || bvid == "" { aid = data.EpList[0].Aid cid = data.EpList[0].Cid - bvid = data.EpList[0].BVid - titleFormat = data.EpList[0].TitleFormat + bvid = data.EpList[0].Bvid + titleFormat = data.EpList[0].Title longTitle = data.EpList[0].LongTitle } options := bilibiliOptions{ @@ -165,7 +159,7 @@ func extractBangumi(url, html string, extractOption extractors.Options) ([]*extr wgp.Add() id := u.EpID if id == 0 { - id = u.ID + id = u.EpID } // html content can't be reused here options := bilibiliOptions{ @@ -173,9 +167,9 @@ func extractBangumi(url, html string, extractOption extractors.Options) ([]*extr bangumi: true, aid: u.Aid, cid: u.Cid, - bvid: u.BVid, + bvid: u.Bvid, - subtitle: fmt.Sprintf("%s %s", u.TitleFormat, u.LongTitle), + subtitle: fmt.Sprintf("%s %s", u.Title, u.LongTitle), } go func(index int, options bilibiliOptions, extractedData []*extractors.Data) { defer wgp.Done() diff --git a/extractors/bilibili/types.go b/extractors/bilibili/types.go index 844b1a05e..f1021ee66 100644 --- a/extractors/bilibili/types.go +++ b/extractors/bilibili/types.go @@ -12,19 +12,26 @@ type token struct { Data tokenData `json:"data"` } -type bangumiEpData struct { - Aid int `json:"aid"` - Cid int `json:"cid"` - BVid string `json:"bvid"` - ID int `json:"id"` - EpID int `json:"ep_id"` - TitleFormat string `json:"titleFormat"` - LongTitle string `json:"long_title"` +type Interaction struct { + Interaction bool `json:"interaction"` +} + +type EpVideoInfo struct { + Aid int `json:"aid"` + Bvid string `json:"bvid"` + Cid int `json:"cid"` + DeliveryBusinessFragmentVideo bool `json:"delivery_business_fragment_video"` + DeliveryFragmentVideo bool `json:"delivery_fragment_video"` + EpID int `json:"ep_id"` + EpStatus int `json:"ep_status"` + Interaction Interaction `json:"interaction"` + LongTitle string `json:"long_title"` + Title string `json:"title"` } type bangumiData struct { - EpInfo bangumiEpData `json:"epInfo"` - EpList []bangumiEpData `json:"epList"` + EpInfo EpVideoInfo `json:"epInfo"` + EpList []EpVideoInfo `json:"epList"` } type videoPagesData struct {