2019-09-07 17:50:04 +00:00
|
|
|
const musicMetadata = require("music-metadata-browser");
|
2020-01-21 11:03:41 +00:00
|
|
|
const util = require("./util");
|
2019-07-05 07:05:11 +00:00
|
|
|
export {Decrypt}
|
|
|
|
const SEED_MAP = [
|
|
|
|
[0x4a, 0xd6, 0xca, 0x90, 0x67, 0xf7, 0x52],
|
|
|
|
[0x5e, 0x95, 0x23, 0x9f, 0x13, 0x11, 0x7e],
|
|
|
|
[0x47, 0x74, 0x3d, 0x90, 0xaa, 0x3f, 0x51],
|
|
|
|
[0xc6, 0x09, 0xd5, 0x9f, 0xfa, 0x66, 0xf9],
|
|
|
|
[0xf3, 0xd6, 0xa1, 0x90, 0xa0, 0xf7, 0xf0],
|
|
|
|
[0x1d, 0x95, 0xde, 0x9f, 0x84, 0x11, 0xf4],
|
|
|
|
[0x0e, 0x74, 0xbb, 0x90, 0xbc, 0x3f, 0x92],
|
|
|
|
[0x00, 0x09, 0x5b, 0x9f, 0x62, 0x66, 0xa1]];
|
|
|
|
|
2020-01-27 04:50:24 +00:00
|
|
|
const OriginalExtMap = {
|
|
|
|
"qmc0": "mp3",
|
|
|
|
"qmc3": "mp3",
|
|
|
|
"qmcogg": "ogg",
|
|
|
|
"qmcflac": "flac",
|
|
|
|
"bkcmp3": "mp3",
|
2020-01-27 09:36:20 +00:00
|
|
|
"bkcflac": "flac",
|
|
|
|
"tkm": "m4a"
|
2020-01-27 04:50:24 +00:00
|
|
|
};
|
2020-01-21 11:03:41 +00:00
|
|
|
|
|
|
|
async function Decrypt(file, raw_filename, raw_ext) {
|
2019-07-05 07:05:11 +00:00
|
|
|
// 获取扩展名
|
2020-01-27 04:50:24 +00:00
|
|
|
if (!(raw_ext in OriginalExtMap)) {
|
|
|
|
return {status: false, message: "File type is incorrect!"}
|
2019-07-05 07:05:11 +00:00
|
|
|
}
|
2020-01-27 04:50:24 +00:00
|
|
|
let new_ext = OriginalExtMap[raw_ext]
|
2020-01-21 11:03:41 +00:00
|
|
|
const mime = util.AudioMimeType[new_ext];
|
2019-07-05 07:05:11 +00:00
|
|
|
// 读取文件
|
2020-01-21 11:03:41 +00:00
|
|
|
const fileBuffer = await util.GetArrayBuffer(file);
|
2019-07-05 07:05:11 +00:00
|
|
|
const audioData = new Uint8Array(fileBuffer);
|
|
|
|
// 转换数据
|
|
|
|
const seed = new Mask();
|
2020-01-21 11:03:41 +00:00
|
|
|
for (let cur = 0; cur < audioData.length; ++cur) {
|
2019-07-05 07:05:11 +00:00
|
|
|
audioData[cur] ^= seed.NextMask();
|
|
|
|
}
|
|
|
|
// 导出
|
2020-01-21 11:03:41 +00:00
|
|
|
const musicData = new Blob([audioData], {type: mime});
|
2019-07-05 07:05:11 +00:00
|
|
|
const musicUrl = URL.createObjectURL(musicData);
|
|
|
|
// 读取Meta
|
2019-09-08 05:40:32 +00:00
|
|
|
let tag = await musicMetadata.parseBlob(musicData);
|
2020-01-27 08:43:40 +00:00
|
|
|
const info = util.GetFileInfo(tag.common.artist, tag.common.title, raw_filename, new_ext);
|
2020-01-21 11:03:41 +00:00
|
|
|
let picUrl = util.GetCoverURL(tag);
|
2019-07-05 07:05:11 +00:00
|
|
|
|
|
|
|
// 返回
|
|
|
|
return {
|
2020-01-21 11:03:41 +00:00
|
|
|
status: true,
|
|
|
|
filename: info.filename,
|
|
|
|
title: info.title,
|
|
|
|
artist: info.artist,
|
2020-02-04 10:24:53 +00:00
|
|
|
ext: new_ext,
|
2019-09-08 05:40:32 +00:00
|
|
|
album: tag.common.album,
|
2020-01-21 11:03:41 +00:00
|
|
|
picture: picUrl,
|
2019-09-14 12:43:57 +00:00
|
|
|
file: musicUrl,
|
2019-07-05 07:05:11 +00:00
|
|
|
mime: mime
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Mask {
|
|
|
|
constructor() {
|
|
|
|
this.x = -1;
|
|
|
|
this.y = 8;
|
|
|
|
this.dx = 1;
|
|
|
|
this.index = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
NextMask() {
|
|
|
|
let ret;
|
|
|
|
this.index++;
|
|
|
|
if (this.x < 0) {
|
|
|
|
this.dx = 1;
|
|
|
|
this.y = (8 - this.y) % 8;
|
|
|
|
ret = 0xc3
|
|
|
|
} else if (this.x > 6) {
|
|
|
|
this.dx = -1;
|
|
|
|
this.y = 7 - this.y;
|
|
|
|
ret = 0xd8
|
|
|
|
} else {
|
|
|
|
ret = SEED_MAP[this.y][this.x]
|
|
|
|
}
|
|
|
|
this.x += this.dx;
|
|
|
|
if (this.index === 0x8000 || (this.index > 0x8000 && (this.index + 1) % 0x8000 === 0)) {
|
|
|
|
return this.NextMask()
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|