-
Notifications
You must be signed in to change notification settings - Fork 25
/
bilichannel.ts
74 lines (68 loc) · 2.28 KB
/
bilichannel.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
* 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 { fetchAwaitBiliPaginatedAPI } from './paginatedbili';
import { awaitLimiter } from './throttle';
import { getDm } from '../Bilibili/bilidm';
import { biliShazamOnSonglist } from './bilishazam';
const URL_BILICHANNEL_INFO =
'https://api.bilibili.com/x/space/wbi/arc/search?mid={mid}&pn={pn}&jsonp=jsonp&ps=50';
export const fetchBiliChannelList = async (
url: string,
progressEmitter: (val: number) => void = () => undefined,
favList: string[] = []
) => {
logger.info('calling fetchBiliChannelList');
const mid = /.*space.bilibili\.com\/(\d+)\/video.*/.exec(url)![1];
let searchAPI = URL_BILICHANNEL_INFO.replace('{mid}', mid!);
const urlObj = new URL(url);
const URLParams = new URLSearchParams(urlObj.search);
const tidVal = URLParams.get('tid');
if (tidVal) {
searchAPI += `&tid=${tidVal}`;
}
const kwVal = URLParams.get('keyword');
if (kwVal) {
searchAPI += `&keyword=${kwVal}`;
}
return fetchAwaitBiliPaginatedAPI({
url: searchAPI + getDm(),
getMediaCount: data => data.page.count,
getPageSize: data => data.page.ps,
getItems: js => js.data.list.vlist,
progressEmitter,
favList,
limiter: awaitLimiter,
});
};
const regexFetch = async ({
reExtracted,
progressEmitter = () => undefined,
favList,
useBiliTag,
}: regexFetchProps): Promise<NoxNetwork.NoxRegexFetch> => ({
songList: await biliShazamOnSonglist(
await fetchBiliChannelList(reExtracted.input, progressEmitter, favList),
false,
progressEmitter,
useBiliTag || false
),
});
const resolveURL = () => undefined;
const refreshSong = (song: NoxMedia.Song) => song;
export default {
regexSearchMatch: /space.bilibili\.com\/(\d+)\/video/,
regexFetch,
regexResolveURLMatch: /^null-/,
resolveURL,
refreshSong,
};