mirror of
https://git.unlock-music.dev/um/web.git
synced 2025-01-19 09:00:22 +00:00
a69ed4f3ce
(cherry picked from commit 2e946e6e30e02085018e868b7857acb62a1a0b08)
43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
import jooxFactory from '@unlock-music/joox-crypto';
|
|
|
|
import { DecryptResult } from './entity';
|
|
import { AudioMimeType, GetArrayBuffer, SniffAudioExt } from './utils';
|
|
|
|
import { MergeUint8Array } from '@/utils/MergeUint8Array';
|
|
import { storage } from '@/utils/storage';
|
|
import { extractQQMusicMeta } from '@/utils/qm_meta';
|
|
|
|
export async function Decrypt(file: Blob, raw_filename: string, raw_ext: string): Promise<DecryptResult> {
|
|
const uuid = await storage.loadJooxUUID('');
|
|
if (!uuid || uuid.length !== 32) {
|
|
throw new Error('请在“解密设定”填写应用 Joox 应用的 UUID。');
|
|
}
|
|
|
|
const fileBuffer = new Uint8Array(await GetArrayBuffer(file));
|
|
const decryptor = jooxFactory(fileBuffer, uuid);
|
|
if (!decryptor) {
|
|
throw new Error('不支持的 joox 加密格式');
|
|
}
|
|
|
|
const musicDecoded = MergeUint8Array(decryptor.decryptFile(fileBuffer));
|
|
const ext = SniffAudioExt(musicDecoded);
|
|
const mime = AudioMimeType[ext];
|
|
|
|
const { album, artist, imgUrl, blob, title } = await extractQQMusicMeta(
|
|
new Blob([musicDecoded], { type: mime }),
|
|
raw_filename,
|
|
ext,
|
|
);
|
|
|
|
return {
|
|
title: title,
|
|
artist: artist,
|
|
ext: ext,
|
|
album: album,
|
|
picture: imgUrl,
|
|
file: URL.createObjectURL(blob),
|
|
blob: blob,
|
|
mime: mime,
|
|
};
|
|
}
|