Skip to content

Commit

Permalink
Merge pull request #390 from lovegaoshi/dev
Browse files Browse the repository at this point in the history
feat: biliFavColle
  • Loading branch information
lovegaoshi authored Apr 23, 2024
2 parents 6c4a229 + 48a6955 commit b16cf3b
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
10 changes: 10 additions & 0 deletions __tests__/mediafetch/biliFavColle.test.ts
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();
});
5 changes: 5 additions & 0 deletions src/utils/BiliSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import bilisubliveFetch from './mediafetch/bilisublive';
import localFetch from '@utils/mediafetch/local';
import b23tvFetch from './mediafetch/b23tv';
import headRequestFetch from './mediafetch/headRequest';
import biliFavColleFetch from './mediafetch/biliFavColle';
import { regexFetchProps } from './mediafetch/generic';
import { MUSICFREE, searcher } from './mediafetch/musicfree';
import { getMusicFreePlugin } from '@utils/ChromeStorage';
Expand Down Expand Up @@ -141,6 +142,10 @@ interface ReExtraction<T> {
}

const reExtractions: ReExtraction<NoxNetwork.NoxRegexFetch>[] = [
{
match: biliFavColleFetch.regexSearchMatch,
fetch: biliFavColleFetch.regexFetch,
},
{
match: biliVideoSimilarFetch.regexSearchMatch,
fetch: biliVideoSimilarFetch.regexFetch,
Expand Down
58 changes: 58 additions & 0 deletions src/utils/mediafetch/biliFavColle.ts
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,
};

0 comments on commit b16cf3b

Please sign in to comment.