Skip to content

Commit

Permalink
fix(bilibili): search api needs the cookie (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
foamzou authored Sep 6, 2022
1 parent 2a1c461 commit ba119f7
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 8 deletions.
2 changes: 1 addition & 1 deletion LATEST_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.7
0.2.8
29 changes: 27 additions & 2 deletions processor/bilibili/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,39 @@ import (
)

const APISearch = "https://api.bilibili.com/x/web-interface/search/all/v2?page=1&page_size=10&platform=pc&single_column=0&keyword=%s&preload=true"
const APIFinger = "https://api.bilibili.com/x/frontend/finger/spi"
const SearchPageUrl = "https://search.bilibili.com/all"

func (c *Core) SearchSong() ([]*meta.SearchSongItem, error) {
cookie, err := utils.GetCookie(SearchPageUrl, map[string]string{
"User-Agent": consts.UAMac,
"Referer": "https://search.bilibili.com/",
}, false)
if err != nil {
return nil, err
}

fingerJsonStr, err := utils.HttpGet(APIFinger, map[string]string{
"User-Agent": consts.UAMac,
"Referer": "https://search.bilibili.com/all",
"Cookie": cookie,
})
if err != nil {
return nil, err
}
var fingerInfo FingerInfo
err = json.Unmarshal([]byte(fingerJsonStr), &fingerInfo)
if err != nil {
return nil, err
}
cookie = fmt.Sprintf("buvid3=%s; buvid4=%s; %s", fingerInfo.Data.B3, fingerInfo.Data.B4, cookie)

var searchSongItems []*meta.SearchSongItem
api := fmt.Sprintf(APISearch, url.QueryEscape(c.Opts.Search.Keyword))

jsonStr, err := utils.HttpGet(api, map[string]string{
"User-Agent": consts.UAMac,
"Referer": "https://search.bilibili.com/",
"Referer": "https://search.bilibili.com/all",
"Cookie": cookie,
})
if err != nil {
return nil, err
Expand Down
9 changes: 9 additions & 0 deletions processor/bilibili/search_entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,12 @@ type SearchSongResponse struct {
} `json:"result"`
} `json:"data"`
}

type FingerInfo struct {
Code int `json:"code"`
Data struct {
B3 string `json:"b_3"`
B4 string `json:"b_4"`
} `json:"data"`
Message string `json:"message"`
}
7 changes: 4 additions & 3 deletions processor/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package processor

import (
"fmt"
"os"
"path"
"strings"

"github.com/foamzou/audio-get/consts"
"github.com/foamzou/audio-get/ffmpeg"
"github.com/foamzou/audio-get/logger"
"github.com/foamzou/audio-get/meta"
"github.com/foamzou/audio-get/utils"
"os"
"path"
"strings"
)

func (p *Processor) download(mediaMeta *meta.MediaMeta) error {
Expand Down
4 changes: 2 additions & 2 deletions version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
)

const (
BuildCode = 12
BuildName = "0.2.7"
BuildCode = 13
BuildName = "0.2.8"
Repo = "https://github.com/foamzou/media-get"
)

Expand Down

0 comments on commit ba119f7

Please sign in to comment.