-
Notifications
You must be signed in to change notification settings - Fork 6.8k
B站适配+一些小问题 / bili adapters and minor fixes #2540
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
HittyGubby
wants to merge
6
commits into
lyswhut:dev
Choose a base branch
from
HittyGubby:dev
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8dd4d74
bili api semi-integrated revised
HittyGubby 62445a7
bili api semi-integrated revised
HittyGubby c35bff9
Merge branch 'dev' of https://github.com/HittyGubby/lx-music-desktop …
lyswhut 3ee78e0
修复歌单、排行榜数据加载
lyswhut 426990f
bili referer injection
HittyGubby 29d9ab7
Merge branch 'dev' of https://github.com/HittyGubby/lx-music-desktop …
HittyGubby File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| import { httpFetch } from '../../request' | ||
| import { dateFormat2 } from '../../index' | ||
|
|
||
| export default { | ||
| async getComment(mInfo, page = 1, limit = 20) { | ||
| const bvid = mInfo.songmid | ||
| const url = `https://api.bilibili.com/x/v2/reply?type=1&oid=${bvid}&sort=2&ps=${limit}&pn=${page}` | ||
| const { body, statusCode } = await httpFetch(url, { | ||
| headers: { | ||
| 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.34 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.34', | ||
| Referer: `https://www.bilibili.com/video/${bvid}/`, | ||
| }, | ||
| }).promise | ||
|
|
||
| if (statusCode !== 200 || body.code !== 0) throw new Error('获取评论失败') | ||
|
|
||
| return { | ||
| source: 'bili', | ||
| comments: this.filterComment(body.data.replies), | ||
| total: body.data.page.count, | ||
| page, | ||
| limit, | ||
| maxPage: body.data.page.num, | ||
| }// seems that sorting by time requires state validation but why, this consumes more server resource? | ||
| }, // you know what, this actually returns the exact same as getHotComment, but consider this scenario | ||
| // user turns on comment and see pitch blank or simply the same content, then they not even notice | ||
| // even if they notice, they may just think "lucky me, what are the odds of that", and move on | ||
|
|
||
| async getHotComment(mInfo, page = 1, limit = 20) { | ||
| const bvid = mInfo.songmid | ||
| const url = `https://api.bilibili.com/x/v2/reply?type=1&oid=${bvid}&sort=1&ps=${limit}&pn=${page}` | ||
| const { body, statusCode } = await httpFetch(url, { | ||
| headers: { | ||
| 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.34 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.34', | ||
| Referer: `https://www.bilibili.com/video/${bvid}/`, | ||
| }, | ||
| }).promise | ||
|
|
||
| if (statusCode !== 200 || body.code !== 0) throw new Error('获取热门评论失败') | ||
|
|
||
| return { | ||
| source: 'bili', | ||
| comments: this.filterComment(body.data.replies), | ||
| total: body.data.page.count, | ||
| page, | ||
| limit, | ||
| maxPage: body.data.page.num, | ||
| } | ||
| }, | ||
|
|
||
| filterComment(rawList) { | ||
| if (!rawList) return [] | ||
|
|
||
| return rawList.map(item => { | ||
| return { | ||
| id: item.rpid, | ||
| rootId: item.rpid, | ||
| text: item.content.message.replace(/\\n/g, '\n'), | ||
| time: item.ctime * 1000, | ||
| timeStr: dateFormat2(item.ctime * 1000), | ||
| userName: item.member.uname, | ||
| avatar: '//wsrv.nl/?url=' + item.member.avatar + '&il', | ||
| userId: item.member.mid, | ||
| likedCount: item.like, | ||
| reply: item.replies ? item.replies.map(reply => ({ | ||
| id: reply.rpid, | ||
| text: reply.content.message.replace(/\\n/g, '\n'), | ||
| time: reply.ctime * 1000, | ||
| timeStr: dateFormat2(reply.ctime * 1000), | ||
| userName: reply.member.uname, | ||
| avatar: '//wsrv.nl/?url=' + reply.member.avatar + '&il', | ||
| userId: reply.member.mid, | ||
| likedCount: reply.like, | ||
| })) : [], | ||
| } | ||
| }) | ||
| }, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import { httpFetch } from '../../request' | ||
|
|
||
| export default { | ||
| _requestObj: null, | ||
|
|
||
| async getList(retryNum = 0) { | ||
| if (this._requestObj) this._requestObj.cancelHttp() | ||
| if (retryNum > 2) return Promise.reject(new Error('try max num')) | ||
|
|
||
| const _requestObj = httpFetch('https://s.search.bilibili.com/main/hotword', { | ||
| headers: { | ||
| 'User-Agent': 'Mozilla/5.0', | ||
| Referer: 'https://www.bilibili.com/', | ||
| }, | ||
| }) | ||
|
|
||
| const { body, statusCode } = await _requestObj.promise | ||
| if (statusCode != 200 || body.code !== 0) throw new Error('获取热搜词失败') | ||
|
|
||
| return { | ||
| source: 'bili', | ||
| list: this.filterList(body.list), | ||
| } | ||
| }, | ||
|
|
||
| filterList(rawList) { | ||
| return rawList.map(item => item.keyword).slice(0, 20) | ||
| }, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import songList from './songList' | ||
| import musicSearch from './musicSearch' | ||
| import { apis } from '../api-source' | ||
| import hotSearch from './hotSearch' | ||
| import comment from './comment' | ||
|
|
||
| const bili = { | ||
| songList, | ||
| musicSearch, | ||
| hotSearch, | ||
| comment, | ||
|
|
||
| getMusicUrl(songInfo, type) { | ||
| return apis('bili').getMusicUrl(songInfo, type) | ||
| }, | ||
| getLyric(songInfo) { | ||
| throw new Error('Bilibili暂无歌词接口') | ||
| }, | ||
| getPic(songInfo) { | ||
| return apis('bili').getPic(songInfo) | ||
| }, | ||
| getMusicDetailPageUrl(songInfo) { | ||
| return `https://www.bilibili.com/video/${songInfo.songmid}` | ||
| }, | ||
| } | ||
|
|
||
| export default bili |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import { httpFetch } from '../../request' | ||
| import { sizeFormate } from '../../index' | ||
|
|
||
| export default { | ||
| limit: 30, | ||
| total: 0, | ||
| page: 0, | ||
| allPage: 1, | ||
| successCode: 0, | ||
|
|
||
| async musicSearch(str, page, limit, retryNum = 0) { | ||
| if (retryNum > 2) throw new Error('搜索失败') | ||
|
|
||
| const searchRequest = httpFetch(`https://api.bilibili.com/x/web-interface/search/type?search_type=video&keyword=${encodeURIComponent(str)}&page=${page}&page_size=${limit}`, { | ||
| headers: { | ||
| 'User-Agent': 'Mozilla/5.0', | ||
| Referer: 'https://www.bilibili.com/', | ||
| Cookie: 'SESSDATA=xxx', | ||
| }, | ||
| }) | ||
|
|
||
| return searchRequest.promise.then(({ body }) => { | ||
| console.log(body) | ||
| if (body.code !== this.successCode) return this.musicSearch(str, page, limit, ++retryNum) | ||
| return body | ||
| }) | ||
| }, | ||
|
|
||
| handleResult(rawList) { | ||
| const list = [] | ||
| if (!rawList) return list | ||
| rawList.forEach(video => { | ||
| if (!video.bvid) return | ||
| const parts = video.duration.split(':') | ||
| const minutes = String(parts[0]).padStart(2, '0') | ||
| const seconds = String(parts[1]).padStart(2, '0') | ||
| const paddedDuration = `${minutes}:${seconds}` | ||
| list.push({ | ||
| singer: video.author, | ||
| name: video.title.replace(/<[^>]+>/g, ''), | ||
| albumName: video.typename, | ||
| albumId: video.tid, | ||
| source: 'bili', | ||
| interval: paddedDuration, | ||
| songId: video.bvid, | ||
| songmid: video.bvid, | ||
| img: '//wsrv.nl/?url=' + video.pic + '&il', | ||
| types: [{ type: 'video', size: sizeFormate(video.play), url: `https://www.bilibili.com/video/${video.bvid}` }], | ||
| _types: { video: { size: sizeFormate(video.play) } }, | ||
| typeUrl: {}, | ||
| }) | ||
| }) | ||
| return list | ||
| }, | ||
|
|
||
| async search(str, page = 1, limit) { | ||
| if (limit == null) limit = this.limit | ||
|
|
||
| const body = await this.musicSearch(str, page, limit) | ||
| if (!body.data.result || body.data.result.length === 0) { | ||
| return Promise.reject(new Error('EMPTY_RESULT')) | ||
| } | ||
| const list = this.handleResult(body.data.result) | ||
|
|
||
| this.total = body.data.numResults | ||
| this.page = page | ||
| this.allPage = Math.ceil(this.total / limit) | ||
|
|
||
| return { | ||
| list, | ||
| allPage: this.allPage, | ||
| limit, | ||
| total: this.total, | ||
| source: 'bili', | ||
| } | ||
| }, | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.