mirror of
https://git.um-react.app/um/um-react.git
synced 2025-11-28 03:23:02 +00:00
feat(kgm): kgm v5 (aka. kgg) support
This commit is contained in:
23
src/decrypt-worker/worker/kugou_parse_header.ts
Normal file
23
src/decrypt-worker/worker/kugou_parse_header.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import {
|
||||
ParseKugouHeaderPayload, ParseKugouHeaderResponse,
|
||||
|
||||
} from '~/decrypt-worker/types.ts';
|
||||
import { KuGouHeader } from '@unlock-music/crypto';
|
||||
|
||||
export const workerParseKugouHeader = async ({ blobURI }: ParseKugouHeaderPayload): Promise<ParseKugouHeaderResponse> => {
|
||||
const blob = await fetch(blobURI, { headers: { Range: 'bytes=0-1023' } }).then((r) => r.blob());
|
||||
const arrayBuffer = await blob.arrayBuffer();
|
||||
const buffer = new Uint8Array(arrayBuffer.slice(0, 0x400));
|
||||
|
||||
let kwm : KuGouHeader | undefined;
|
||||
|
||||
try {
|
||||
kwm = new KuGouHeader(buffer);
|
||||
const { version, audioHash } = kwm;
|
||||
return { version, audioHash };
|
||||
} catch {
|
||||
return null;
|
||||
} finally {
|
||||
kwm?.free();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user