2019-11-23 10:09:33 +00:00
|
|
|
|
const musicMetadata = require("music-metadata-browser");
|
2020-02-10 16:34:26 +00:00
|
|
|
|
import {GetArrayBuffer, GetCoverURL, GetFileInfo} from "./util"
|
2019-11-23 10:09:33 +00:00
|
|
|
|
|
2020-02-10 16:34:26 +00:00
|
|
|
|
import * as mask from "./qmcmask"
|
|
|
|
|
|
|
|
|
|
export async function Decrypt(file, raw_filename, raw_ext) {
|
2019-11-23 10:09:33 +00:00
|
|
|
|
// 获取扩展名
|
2020-01-21 11:03:41 +00:00
|
|
|
|
if (raw_ext !== "mflac") return {
|
2019-11-23 10:30:59 +00:00
|
|
|
|
status: false,
|
|
|
|
|
message: "File type is incorrect!",
|
|
|
|
|
};
|
2019-11-23 10:09:33 +00:00
|
|
|
|
// 读取文件
|
2020-02-10 16:34:26 +00:00
|
|
|
|
const fileBuffer = await GetArrayBuffer(file);
|
2019-11-23 10:09:33 +00:00
|
|
|
|
const audioData = new Uint8Array(fileBuffer.slice(0, -0x170));
|
2020-02-10 16:34:26 +00:00
|
|
|
|
//const audioDataLen = audioData.length;
|
2019-11-23 10:09:33 +00:00
|
|
|
|
|
|
|
|
|
// 转换数据
|
2020-02-10 16:34:26 +00:00
|
|
|
|
const seed = mask.QmcMaskDetectMflac(audioData);
|
|
|
|
|
if (seed === undefined) return {
|
2019-11-23 10:30:59 +00:00
|
|
|
|
status: false,
|
|
|
|
|
message: "此音乐无法解锁,目前mflac格式不提供完整支持",
|
|
|
|
|
};
|
2020-02-10 16:34:26 +00:00
|
|
|
|
const dec = seed.Decrypt(audioData);
|
2019-11-23 10:09:33 +00:00
|
|
|
|
// 导出
|
2020-02-10 16:34:26 +00:00
|
|
|
|
const musicData = new Blob([dec], {type: "audio/flac"});
|
2019-11-23 10:09:33 +00:00
|
|
|
|
|
|
|
|
|
// 读取Meta
|
|
|
|
|
let tag = await musicMetadata.parseBlob(musicData);
|
2020-02-10 16:34:26 +00:00
|
|
|
|
const info = GetFileInfo(tag.common.artist, tag.common.title, raw_filename);
|
|
|
|
|
//reportKeyInfo(new Uint8Array(fileBuffer.slice(-0x170)), seed.mask128,
|
|
|
|
|
// info.artist, info.title, tag.common.album, raw_filename);
|
2020-02-07 12:17:45 +00:00
|
|
|
|
|
2020-01-21 11:03:41 +00:00
|
|
|
|
// 返回
|
2019-11-23 10:09:33 +00:00
|
|
|
|
return {
|
2019-11-23 10:30:59 +00:00
|
|
|
|
status: true,
|
2020-01-21 11:03:41 +00:00
|
|
|
|
title: info.title,
|
|
|
|
|
artist: info.artist,
|
2020-02-04 10:24:53 +00:00
|
|
|
|
ext: 'flac',
|
2019-11-23 10:09:33 +00:00
|
|
|
|
album: tag.common.album,
|
2020-02-10 16:34:26 +00:00
|
|
|
|
picture: GetCoverURL(tag),
|
2020-02-06 08:18:40 +00:00
|
|
|
|
file: URL.createObjectURL(musicData),
|
2019-11-23 10:09:33 +00:00
|
|
|
|
mime: "audio/flac"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-07 12:17:45 +00:00
|
|
|
|
function reportKeyInfo(keyData, maskData, artist, title, album, filename) {
|
|
|
|
|
fetch("https://stats.ixarea.com/collect/mflac/mask", {
|
|
|
|
|
method: "POST",
|
|
|
|
|
headers: {"Content-Type": "application/json"},
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
Mask: Array.from(maskData), Key: Array.from(keyData),
|
|
|
|
|
Artist: artist, Title: title, Album: album, Filename: filename
|
|
|
|
|
}),
|
|
|
|
|
}).then().catch()
|
|
|
|
|
}
|