web/src/decrypt/qmc.js

47 lines
1.3 KiB
JavaScript
Raw Normal View History

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");
import * as mask from "./qmcmask"
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
//todo: use header to detect media type
export async function Decrypt(file, raw_filename, raw_ext) {
// 获取扩展名
2020-01-27 04:50:24 +00:00
if (!(raw_ext in OriginalExtMap)) {
return {status: false, message: "File type is incorrect!"}
}
2020-02-06 08:18:40 +00:00
const new_ext = OriginalExtMap[raw_ext];
2020-01-21 11:03:41 +00:00
const mime = util.AudioMimeType[new_ext];
// 读取文件
2020-01-21 11:03:41 +00:00
const fileBuffer = await util.GetArrayBuffer(file);
const audioData = new Uint8Array(fileBuffer);
// 转换数据
const seed = mask.QmcMaskGetDefault();
const dec = seed.Decrypt(audioData);
// 导出
const musicData = new Blob([dec], {type: mime});
// 读取Meta
2020-02-06 08:18:40 +00:00
const tag = await musicMetadata.parseBlob(musicData);
const info = util.GetFileInfo(tag.common.artist, tag.common.title, raw_filename);
// 返回
return {
2020-01-21 11:03:41 +00:00
status: true,
title: info.title,
artist: info.artist,
2020-02-04 10:24:53 +00:00
ext: new_ext,
album: tag.common.album,
2020-02-06 08:18:40 +00:00
picture: util.GetCoverURL(tag),
file: URL.createObjectURL(musicData),
mime: mime
}
}