2021-12-21 22:34:36 +00:00
|
|
|
import jooxFactory from '@unlock-music/joox-crypto';
|
|
|
|
|
2021-12-19 23:03:46 +00:00
|
|
|
import { DecryptResult } from './entity';
|
|
|
|
import { AudioMimeType, GetArrayBuffer, SniffAudioExt } from './utils';
|
|
|
|
|
|
|
|
import { MergeUint8Array } from '@/utils/MergeUint8Array';
|
2021-12-20 22:19:44 +00:00
|
|
|
import { storage } from '@/utils/storage';
|
2021-12-21 22:34:36 +00:00
|
|
|
import { extractQQMusicMeta } from '@/utils/qm_meta';
|
2021-12-19 23:03:46 +00:00
|
|
|
|
|
|
|
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];
|
2021-12-21 22:34:36 +00:00
|
|
|
|
|
|
|
const { album, artist, imgUrl, blob, title } = await extractQQMusicMeta(
|
|
|
|
new Blob([musicDecoded], { type: mime }),
|
|
|
|
raw_filename,
|
|
|
|
ext,
|
|
|
|
);
|
2021-12-19 23:03:46 +00:00
|
|
|
|
|
|
|
return {
|
2021-12-21 22:34:36 +00:00
|
|
|
title: title,
|
|
|
|
artist: artist,
|
2021-12-19 23:03:46 +00:00
|
|
|
ext: ext,
|
2021-12-21 22:34:36 +00:00
|
|
|
album: album,
|
|
|
|
picture: imgUrl,
|
|
|
|
file: URL.createObjectURL(blob),
|
|
|
|
blob: blob,
|
|
|
|
mime: mime,
|
2021-12-19 23:03:46 +00:00
|
|
|
};
|
|
|
|
}
|