@@ -5,14 +5,24 @@ import (
55 "simple-golang-crawler/engine"
66 "simple-golang-crawler/fetcher"
77 "simple-golang-crawler/model"
8-
8+ "simple-golang-crawler/tool"
9+ "math"
910 "github.com/tidwall/gjson"
1011)
1112
1213var _getAidUrlTemp = "https://api.bilibili.com/x/space/arc/search?mid=%d&ps=30&tid=0&pn=%d&keyword=&order=pubdate&jsonp=jsonp"
13- var _getCidUrlTemp = "https://api.bilibili.com/x/player/pagelist?aid=%d"
14+ var _getCidUrlTemp = "https://api.bilibili.com/x/web-interface/view?aid=%d"
15+ //var _getCidUrlTemp = "https://api.bilibili.com/x/player/pagelist?aid=%d"
16+
17+ var table string = "fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF"
18+ var s = [6 ]int {11 , 10 , 3 , 8 , 4 , 6 }
19+ var xor = 177451812
20+ var add = 8728348608
21+ var tr map [string ]int
22+
1423
1524func UpSpaceParseFun (contents []byte , url string ) engine.ParseResult {
25+
1626 var retParseResult engine.ParseResult
1727 value := gjson .GetManyBytes (contents , "data.list.vlist" , "data.page" )
1828
@@ -25,22 +35,26 @@ func UpSpaceParseFun(contents []byte, url string) engine.ParseResult {
2535}
2636
2737func getAidDetailReqList (pageInfo gjson.Result ) ([]* engine.Request , int64 ) {
38+
2839 var retRequests []* engine.Request
2940 var upid int64
3041 for _ , i := range pageInfo .Array () {
3142 aid := i .Get ("aid" ).Int ()
3243 upid = i .Get ("mid" ).Int ()
3344 title := i .Get ("title" ).String ()
45+ title = tool .TitleEdit (title ) // remove special characters
3446 reqUrl := fmt .Sprintf (_getCidUrlTemp , aid )
3547 videoAid := model .NewVideoAidInfo (aid , title )
36- reqParseFunction := GenGetAidChildrenParseFun (videoAid )
48+ reqParseFunction := GenGetAidChildrenParseFun (videoAid ) //子视频
3749 req := engine .NewRequest (reqUrl , reqParseFunction , fetcher .DefaultFetcher )
3850 retRequests = append (retRequests , req )
3951 }
4052 return retRequests , upid
4153}
4254
55+ // 访问up主的时候 需要翻页
4356func getNewBilibiliUpSpaceReqList (pageInfo gjson.Result , upid int64 ) []* engine.Request {
57+
4458 var retRequests []* engine.Request
4559
4660 count := pageInfo .Get ("count" ).Int ()
@@ -51,7 +65,7 @@ func getNewBilibiliUpSpaceReqList(pageInfo gjson.Result, upid int64) []*engine.R
5165 extraPage = 1
5266 }
5367 totalPage := count / ps + extraPage
54- for i := int64 (1 ); i < totalPage ; i ++ {
68+ for i := int64 (1 ); i <= totalPage ; i ++ {
5569 if i == pn {
5670 continue
5771 }
@@ -63,6 +77,20 @@ func getNewBilibiliUpSpaceReqList(pageInfo gjson.Result, upid int64) []*engine.R
6377}
6478
6579func GetRequestByUpId (upid int64 ) * engine.Request {
80+
6681 reqUrl := fmt .Sprintf (_getAidUrlTemp , upid , 1 )
6782 return engine .NewRequest (reqUrl , UpSpaceParseFun , fetcher .DefaultFetcher )
6883}
84+
85+ // source code: https://blog.csdn.net/dotastar00/article/details/108805779
86+ func Bv2av (x string ) int64 {
87+ tr = make (map [string ]int )
88+ for i := 0 ; i < 58 ; i ++ {
89+ tr [string (table [i ])] = i
90+ }
91+ r := 0
92+ for i := 0 ; i < 6 ; i ++ {
93+ r += tr [string (x [s [i ]])] * int (math .Pow (float64 (58 ), float64 (i )))
94+ }
95+ return int64 ((r - add ) ^ xor )
96+ }
0 commit comments