-
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.
Merge pull request #390 from lovegaoshi/dev
feat: biliFavColle
- Loading branch information
Showing
3 changed files
with
73 additions
and
0 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,10 @@ | ||
import fetcher from '../../src/utils/mediafetch/biliFavColle'; | ||
test('FavColle', async () => { | ||
const content = await fetcher.regexFetch({ | ||
reExtracted: fetcher.regexSearchMatch.exec( | ||
'https://space.bilibili.com/529249/favlist?fid=1061551&ftype=collect&ctype=21' | ||
)!, | ||
}); | ||
// 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/** | ||
* refactor: | ||
* bilisearch workflow: | ||
* reExtractSearch matches regex patterns and use the corresponding fetch functions; | ||
* fetch function takes extracted and calls a dataProcess.js fetch function; | ||
* dataprocess fetch function fetches VIDEOINFO using data.js fetch function, then parses into SONGS | ||
* data.js fetch function fetches VIDEOINFO. | ||
* steps to refactor: | ||
* each site needs a fetch to parse regex extracted, a videoinfo fetcher and a song fetcher. | ||
*/ | ||
import { logger } from '../Logger'; | ||
import { regexFetchProps } from './generic'; | ||
import { biliShazamOnSonglist } from './bilishazam'; | ||
import { fetchBiliPaginatedAPI } from './paginatedbili'; | ||
|
||
const URL_BILICOLLE_INFO = | ||
'https://api.bilibili.com/x/space/fav/season/list?season_id={sid}&pn={pn}&ps=100'; | ||
|
||
const fetchBiliColleList = async ( | ||
sid: string, | ||
progressEmitter: (val: number) => void = () => undefined, | ||
favList: string[] = [] | ||
) => { | ||
logger.info('calling fetchBiliColleList'); | ||
|
||
return await fetchBiliPaginatedAPI({ | ||
url: URL_BILICOLLE_INFO.replace('{sid}', sid), | ||
getMediaCount: (data: any) => data.info.media_count, | ||
getPageSize: () => 100, | ||
getItems: (js: any) => js.data.medias, | ||
progressEmitter, | ||
favList, | ||
}); | ||
}; | ||
|
||
const regexFetch = async ({ | ||
reExtracted, | ||
progressEmitter = () => undefined, | ||
favList, | ||
useBiliTag, | ||
}: regexFetchProps): Promise<NoxNetwork.NoxRegexFetch> => ({ | ||
songList: await biliShazamOnSonglist( | ||
await fetchBiliColleList(reExtracted[1]!, progressEmitter, favList), | ||
false, | ||
progressEmitter, | ||
useBiliTag || false | ||
), | ||
}); | ||
|
||
const resolveURL = () => undefined; | ||
|
||
export default { | ||
regexSearchMatch: /.*bilibili\.com\/\d+\/favlist\?fid=(\d+)&ftype=collect/, | ||
regexFetch, | ||
regexResolveURLMatch: /^null-/, | ||
resolveURL, | ||
}; |