Skip to content
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

feat: biliFavColle #390

Merged
merged 2 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
};
Loading