-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b890ba4
commit 708b8e2
Showing
4 changed files
with
80 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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,11 @@ | ||
import fetcher from '../../src/utils/mediafetch/biliVideoSimilar'; | ||
|
||
test('biliVideoSimilar', async () => { | ||
const content = await fetcher.regexFetch({ | ||
reExtracted: fetcher.regexSearchMatch.exec( | ||
'bilibili.com/video/similarvideo/BV1cf421Z7oQ' | ||
)!, | ||
}); | ||
// console.log(content); | ||
expect(content?.songList[0]?.id).not.toBeNull(); | ||
}); |
This file contains 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 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 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,53 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
|
||
import { logger } from '../Logger'; | ||
import { regexFetchProps } from './generic'; | ||
import bfetch from '@utils/BiliFetch'; | ||
import { SOURCE, BiliMusicTid } from '@enums/MediaFetch'; | ||
import SongTS from '@objects/Song'; | ||
import { fetchBVID } from './bilivideo'; | ||
|
||
/** | ||
* https://api.bilibili.com/x/web-interface/archive/related?bvid=BV1xx411c7m9 | ||
*/ | ||
const API = | ||
'https://api.bilibili.com/x/web-interface/archive/related?bvid={sid}'; | ||
|
||
const fetchBiliVideoSimilarList = async (bvid: string) => { | ||
logger.info('calling fetchBiliVideoSimilarList'); | ||
const res = await bfetch(API.replace('{sid}', bvid)); | ||
const json = await res.json(); | ||
return (await fetchBVID(bvid)).concat( | ||
json.data | ||
// limit similar videos to music only. | ||
.filter((v: any) => BiliMusicTid.includes(v.tid)) | ||
.map((data: any) => | ||
SongTS({ | ||
cid: data.cid, | ||
bvid: data.bvid, | ||
name: data.title, | ||
nameRaw: data.title, | ||
singer: data.owner.name, | ||
singerId: data.owner.mid, | ||
cover: data.pic, | ||
lyric: '', | ||
page: 1, | ||
duration: data.duration, | ||
album: data.title, | ||
source: SOURCE.bilivideo, | ||
}) | ||
) | ||
); | ||
}; | ||
|
||
const regexFetch = async ({ | ||
reExtracted, | ||
}: regexFetchProps): Promise<NoxNetwork.NoxRegexFetch> => ({ | ||
songList: await fetchBiliVideoSimilarList(reExtracted[1]!), | ||
}); | ||
|
||
export default { | ||
// https://www.bilibili.com/audio/similarsongs/3680653 | ||
regexSearchMatch: /bilibili\.com\/video\/similarvideo\/(BV[^/?]+)/, | ||
regexFetch, | ||
}; |