Add Partial Support For .mflac

This commit is contained in:
MengYX 2019-11-23 18:09:33 +08:00
parent 95de3e8cc5
commit 591c1a5312
No known key found for this signature in database
GPG Key ID: E63F9C7303E8F604
4 changed files with 131 additions and 5 deletions

View File

@ -7,8 +7,11 @@
## Features ## Features
- [x] Unlock in browser 在浏览器中解锁 - [x] Unlock in browser 在浏览器中解锁
- [x] QQMusic File QQ音乐文件 (.qmc0/.qmc3/.qmcflac/.qmcogg) - [x] QQMusic File QQ音乐格式 (.qmc0/.qmc3/.qmcflac/.qmcogg)
- [x] Netease File 网易云音乐文件 (.ncm) - [ ] QQMusic New Format QQ音乐新格式
- [x] .mflac (Partial 部分支持)
- [ ] .mgg
- [x] Netease Format 网易云音乐格式 (.ncm)
- [x] Drag and Drop 拖放文件 - [x] Drag and Drop 拖放文件
- [x] Play instantly 在线播放 - [x] Play instantly 在线播放
- [x] Batch unlocking 批量解锁 - [x] Batch unlocking 批量解锁

View File

@ -10,7 +10,7 @@
</script> </script>
<script async src="https://stats.ixarea.com/ixarea-stats.js"></script> <script async src="https://stats.ixarea.com/ixarea-stats.js"></script>
<title>音乐解锁 - By IXarea</title> <title>音乐解锁 - By IXarea</title>
<meta content="音乐,解锁,ncm,qmc,qmc0,qmc3,qmcflac,qq音乐,网易云音乐,加密" name="keywords"/> <meta content="音乐,解锁,ncm,qmc,qmc0,qmc3,qmcflac,qmcogg,mflac,qq音乐,网易云音乐,加密" name="keywords"/>
<meta content="音乐解锁 - 在任何设备上解锁已购的加密音乐!" name="description"/> <meta content="音乐解锁 - 在任何设备上解锁已购的加密音乐!" name="description"/>
<style> <style>
#loader { #loader {

View File

@ -6,7 +6,7 @@
:auto-upload="false" :auto-upload="false"
:on-change="handleFile" :on-change="handleFile"
:show-file-list="false" :show-file-list="false"
accept=".ncm,.qmc0,.qmc3,.qmcflac,.qmcogg" accept=".ncm,.qmc0,.qmc3,.qmcflac,.qmcogg,.mflac"
action="" action=""
drag drag
multiple> multiple>
@ -69,7 +69,7 @@
<el-footer id="app-footer"> <el-footer id="app-footer">
<el-row> <el-row>
音乐解锁移除已购音乐的加密保护 音乐解锁移除已购音乐的加密保护
目前支持网易云音乐(ncm)和QQ音乐(qmc0, qmc3, qmcflac, qmcogg) 目前支持网易云音乐(ncm)和QQ音乐(qmc0, qmc3, qmcflac, qmcogg, mflac)
<a href="https://github.com/ix64/unlock-music/wiki/使用提示" target="_blank">使用提示</a> <a href="https://github.com/ix64/unlock-music/wiki/使用提示" target="_blank">使用提示</a>
</el-row> </el-row>
<el-row> <el-row>
@ -90,6 +90,7 @@
const NcmDecrypt = require("./plugins/ncm"); const NcmDecrypt = require("./plugins/ncm");
const QmcDecrypt = require("./plugins/qmc"); const QmcDecrypt = require("./plugins/qmc");
const RawDecrypt = require("./plugins/raw"); const RawDecrypt = require("./plugins/raw");
const MFlacDecrypt = require("./plugins/mflac");
export default { export default {
name: 'app', name: 'app',
components: {}, components: {},
@ -135,7 +136,11 @@
case "qmcogg": case "qmcogg":
data = await QmcDecrypt.Decrypt(file.raw); data = await QmcDecrypt.Decrypt(file.raw);
break; break;
case "mflac":
data = await MFlacDecrypt.Decrypt(file.raw);
break;
default: default:
console.log("Not Supported File!");
break; break;
} }
if (null != data) { if (null != data) {

118
src/plugins/mflac.js Normal file
View File

@ -0,0 +1,118 @@
const musicMetadata = require("music-metadata-browser");
export {Decrypt}
async function Decrypt(file) {
// 获取扩展名
let filename_ext = file.name.substring(file.name.lastIndexOf(".") + 1, file.name.length).toLowerCase();
if (filename_ext !== "mflac") return;
// 读取文件
const fileBuffer = await new Promise(resolve => {
const reader = new FileReader();
reader.onload = (e) => {
resolve(e.target.result);
};
reader.readAsArrayBuffer(file);
});
const audioData = new Uint8Array(fileBuffer.slice(0, -0x170));
const audioDataLen = audioData.length;
// 转换数据
const seed = new Mask();
if (!seed.DetectMask(audioData)) return;
for (let cur = 0; cur < audioDataLen; ++cur) {
audioData[cur] ^= seed.NextMask();
}
// 导出
const musicData = new Blob([audioData], {type: "audio/flac"});
const musicUrl = URL.createObjectURL(musicData);
console.log(musicUrl);
// 读取Meta
let tag = await musicMetadata.parseBlob(musicData);
// 处理无标题歌手
let filename_array = file.name.substring(0, file.name.lastIndexOf(".")).split("-");
let title = tag.common.title;
let artist = tag.common.artist;
if (filename_array.length > 1) {
if (artist === undefined) artist = filename_array[0].trim();
if (title === undefined) title = filename_array[1].trim();
} else if (filename_array.length === 1) {
if (title === undefined) title = filename_array[0].trim();
}
const filename = artist + " - " + title + ".flac";
// 处理无封面
let pic_url = "";
if (tag.common.picture !== undefined && tag.common.picture.length >= 1) {
const picture = tag.common.picture[0];
const blobPic = new Blob([picture.data], {type: picture.format});
pic_url = URL.createObjectURL(blobPic);
}
// 返回*/
return {
filename: filename,
title: title,
artist: artist,
album: tag.common.album,
picture: pic_url,
file: musicUrl,
mime: "audio/flac"
}
}
class Mask {
FLAC_HEADER = [0x66, 0x4C, 0x61, 0x43, 0x00];
constructor() {
this.index = -1;
this.mask_index = -1;
this.mask = Array(128).fill(0x00);
}
DetectMask(data) {
let search_len = data.length - 256, mask;
for (let block_idx = 0; block_idx < search_len; block_idx += 128) {
let flag = true;
mask = data.slice(block_idx, block_idx + 128);
let next_mask = data.slice(block_idx + 128, block_idx + 256);
for (let idx = 0; idx < 128; idx++) {
if (mask[idx] !== next_mask[idx]) {
flag = false;
break;
}
}
if (!flag) continue;
for (let test_idx = 0; test_idx < this.FLAC_HEADER.length; test_idx++) {
let p = data[test_idx] ^ mask[test_idx];
if (p !== this.FLAC_HEADER[test_idx]) {
flag = false;
debugger;
break;
}
}
if (!flag) continue;
this.mask = mask;
console.log(mask);
return true;
}
return false;
}
NextMask() {
this.index++;
this.mask_index++;
if (this.index === 0x8000 || (this.index > 0x8000 && (this.index + 1) % 0x8000 === 0)) {
this.index++;
this.mask_index++;
}
if (this.mask_index >= 128) {
this.mask_index -= 128;
}
return this.mask[this.mask_index]
}
}