-
Notifications
You must be signed in to change notification settings - Fork 22
/
headRequest.ts
40 lines (37 loc) · 1.02 KB
/
headRequest.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
import bfetch from '@utils/BiliFetch';
import SongTS from '@objects/Song';
import { Source } from '@enums/MediaFetch';
const headFetch = async (url: string): Promise<NoxMedia.Song | undefined> => {
if (!url.startsWith('https://')) return;
try {
const res = await bfetch(url, { method: 'HEAD' });
if (res.headers.get('content-type')?.startsWith('audio')) {
const urlObj = new URL(url);
const fn = urlObj.pathname.substring(
urlObj.pathname.lastIndexOf('/') + 1
);
return SongTS({
cid: `${Source.rawhttp}-${url}`,
bvid: url,
name: fn,
nameRaw: fn,
singer: urlObj.hostname,
singerId: urlObj.hostname,
cover: '',
lyric: '',
page: 1,
duration: 0,
album: fn,
source: Source.rawhttp,
});
}
} catch (e) {
console.warn(e);
}
};
const resolveURL = async (song: NoxMedia.Song) => ({ url: song.bvid });
export default {
regexFetch: headFetch,
regexResolveURLMatch: /^rawhttp-/,
resolveURL,
};