Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
e31eb9c1f1 | ||
![]() |
f64fa71b1e | ||
![]() |
181a3c402f | ||
![]() |
4c4e4061f5 | ||
![]() |
2526adcab0 | ||
![]() |
f2ea85bae9 | ||
![]() |
c07d55565d | ||
![]() |
71a8d9fab7 | ||
![]() |
7233fdc707 | ||
![]() |
0d119094df | ||
![]() |
1f804e1037 | ||
![]() |
77d9ca4ba8 | ||
![]() |
8f3c74c100 | ||
![]() |
29c27bbfd9 |
47
README.md
47
README.md
@@ -1,30 +1,39 @@
|
|||||||
# Unlock Music 音乐解锁
|
# Unlock Music 音乐解锁
|
||||||
- Unlock encrypted music file in browser.
|
- Unlock encrypted music file in browser.
|
||||||
- 在浏览器中解锁加密的音乐文件。
|
- 在浏览器中解锁加密的音乐文件。
|
||||||
- unlock-music项目是以学习和技术研究的初衷创建的。
|
- unlock-music项目是以学习和技术研究的初衷创建的,修改、再分发时请遵循[License](https://github.com/ix64/unlock-music/blob/master/LICENSE)
|
||||||
- 由于存在可能的法律风险以及滥用风险,不再提供Demo服务。
|
- 由于存在可能的法律风险以及滥用风险,不再提供Demo服务;Unlock Music的CLI版本正在开发中。
|
||||||
|
- [其他测试版工具](https://github.com/ix64/unlock-music/wiki/%E5%85%B6%E4%BB%96%E9%9F%B3%E4%B9%90%E6%A0%BC%E5%BC%8F%E5%B7%A5%E5%85%B7)
|
||||||
|
|
||||||
[](https://ci.ixarea.com/ix64/unlock-music)
|
[](https://ci.ixarea.com/ix64/unlock-music)
|
||||||
|
|
||||||
# Features
|
# 特性
|
||||||
- [x] Unlock in browser 在浏览器中解锁
|
## 支持的格式
|
||||||
- [x] QQMusic Format QQ音乐格式 (.qmc0/.qmc2/.qmc3/.qmcflac/.qmcogg/.tkm)
|
- [x] QQ音乐 (.qmc0/.qmc2/.qmc3/.qmcflac/.qmcogg/[.tkm](https://github.com/ix64/unlock-music/issues/9))
|
||||||
- [x] MooMusic Format Moo音乐格式 ([.bkcmp3/.bkcflac](https://github.com/ix64/unlock-music/issues/11))
|
- [x] Moo音乐格式 ([.bkcmp3/.bkcflac](https://github.com/ix64/unlock-music/issues/11))
|
||||||
- [x] QQMusic Tm Format QQ音乐Tm格式 (.tm0/.tm2/.tm3/.tm6)
|
- [x] QQ音乐Tm格式 (.tm0/.tm2/.tm3/.tm6)
|
||||||
- [x] QQMusic New Format QQ音乐新格式 (Experimental 实验性支持)
|
- [x] QQ音乐新格式 (实验性支持)
|
||||||
- [x] .mflac
|
- [x] .mflac
|
||||||
- [x] .mgg
|
- [x] [.mgg](https://github.com/ix64/unlock-music/issues/3)
|
||||||
- [x] Netease Format 网易云音乐格式 (.ncm)
|
- [x] 网易云音乐格式 (.ncm)
|
||||||
- [x] Drag and Drop 拖放文件
|
- [x] 补全ncm的ID3信息
|
||||||
- [x] Play instantly 在线播放
|
- [x] 虾米音乐格式 (.xm) (测试阶段)
|
||||||
- [x] Batch unlocking 批量解锁
|
- [x] 酷我音乐格式 (.kwm) (测试阶段)
|
||||||
- [x] Progressive Web App 渐进式Web应用
|
- [ ] 酷狗音乐格式 (.kgm) ([Alpha测试](https://github.com/ix64/unlock-music/wiki/%E5%85%B6%E4%BB%96%E9%9F%B3%E4%B9%90%E6%A0%BC%E5%BC%8F%E5%B7%A5%E5%85%B7#%E9%85%B7%E7%8B%97%E9%9F%B3%E4%B9%90-kgmvpr%E8%A7%A3%E9%94%81%E5%B7%A5%E5%85%B7))
|
||||||
- [x] Complete ID3 for ncm 补全ncm的ID3信息
|
|
||||||
- [x] Multi-threads 多线程
|
## 其他特性
|
||||||
|
- [x] 在浏览器中解锁
|
||||||
|
- [x] 拖放文件
|
||||||
|
- [x] 在线播放
|
||||||
|
- [x] 批量解锁
|
||||||
|
- [x] 渐进式Web应用
|
||||||
|
- [x] 多线程
|
||||||
|
|
||||||
|
|
||||||
# 使用方法
|
# 使用方法
|
||||||
## 下载已构建版本
|
## 使用已构建版本
|
||||||
- 已构建的版本发布在 [GitHub Release](https://github.com/ix64/unlock-music/releases/latest), 下载解压缩后即可部署或本地使用
|
- 从[GitHub Release](https://github.com/ix64/unlock-music/releases/latest)下载已构建的版本
|
||||||
|
- 解压缩后即可部署或本地使用(**请勿直接运行源代码**)
|
||||||
|
|
||||||
## 自行构建
|
## 自行构建
|
||||||
- 环境要求
|
- 环境要求
|
||||||
|
1155
package-lock.json
generated
1155
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "unlock-music",
|
"name": "unlock-music",
|
||||||
"version": "1.4.1",
|
"version": "1.5.0",
|
||||||
"updateInfo": "支持.qmc2;qq音乐显示封面图片;界面优化;修复GBK编码ID3信息",
|
"updateInfo": "支持酷我.kwm;支持虾米.xm",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"description": "Unlock encrypted music file in browser.",
|
"description": "Unlock encrypted music file in browser.",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
@@ -22,7 +22,7 @@
|
|||||||
<div id="loader"></div>
|
<div id="loader"></div>
|
||||||
<noscript>
|
<noscript>
|
||||||
<img alt=""
|
<img alt=""
|
||||||
src="https://stats.ixarea.com/ixarea-stats/report?idsite=2&rec=1&action_name=音乐解锁+-+By+IXarea"
|
src="https://stats.ixarea.com/ixarea-stats/report?rec=1&action_name=音乐解锁-NoJS&idsite=2"
|
||||||
style="border:0"/>
|
style="border:0"/>
|
||||||
</noscript>
|
</noscript>
|
||||||
<div hidden id="loader-tips-outdated">
|
<div hidden id="loader-tips-outdated">
|
||||||
@@ -53,12 +53,12 @@
|
|||||||
var m;
|
var m;
|
||||||
if (!ua) return true;
|
if (!ua) return true;
|
||||||
if (/MSIE |Trident\//.exec(ua)) return true; // no IE
|
if (/MSIE |Trident\//.exec(ua)) return true; // no IE
|
||||||
m = /Edge\/([\d.]+)/.exec(ua); // Edge >= 16
|
m = /Edge\/([\d.]+)/.exec(ua); // Edge >= 17
|
||||||
if (m && Number(m[1]) < 16) return true;
|
if (m && Number(m[1]) < 17) return true;
|
||||||
m = /Chrome\/([\d.]+)/.exec(ua); // Chrome >= 50
|
m = /Chrome\/([\d.]+)/.exec(ua); // Chrome >= 58
|
||||||
if (m && Number(m[1]) < 50) return true;
|
if (m && Number(m[1]) < 58) return true;
|
||||||
m = /Firefox\/([\d.]+)/.exec(ua); // Firefox >= 38
|
m = /Firefox\/([\d.]+)/.exec(ua); // Firefox >= 45
|
||||||
return m && Number(m[1]) < 38;
|
return m && Number(m[1]) < 45;
|
||||||
})();
|
})();
|
||||||
if (detected) {
|
if (detected) {
|
||||||
document.getElementById('loader-tips-outdated').hidden = false;
|
document.getElementById('loader-tips-outdated').hidden = false;
|
||||||
|
@@ -41,8 +41,8 @@
|
|||||||
<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>
|
||||||
目前支持网易云音乐(ncm)、QQ音乐(qmc, mflac, mgg, tkm)以及
|
目前支持网易云音乐(ncm), QQ音乐(qmc, mflac, mgg), 虾米音乐(xm), 酷我音乐(.kwm)
|
||||||
<a href="https://github.com/ix64/unlock-music/blob/master/README.md" target="_blank">其他格式</a>。
|
<a href="https://github.com/ix64/unlock-music/blob/master/README.md" target="_blank">更多</a>。
|
||||||
</el-row>
|
</el-row>
|
||||||
<el-row>
|
<el-row>
|
||||||
<span>Copyright © 2019-</span><span v-text="(new Date()).getFullYear()"></span> MengYX
|
<span>Copyright © 2019-</span><span v-text="(new Date()).getFullYear()"></span> MengYX
|
||||||
@@ -92,12 +92,13 @@
|
|||||||
try {
|
try {
|
||||||
const resp = await fetch("https://stats.ixarea.com/collect/music/app-version", {
|
const resp = await fetch("https://stats.ixarea.com/collect/music/app-version", {
|
||||||
method: "POST", headers: {"Content-Type": "application/json"},
|
method: "POST", headers: {"Content-Type": "application/json"},
|
||||||
body: JSON.stringify({Version: this.version})
|
body: JSON.stringify({"Version": this.version})
|
||||||
});
|
});
|
||||||
updateInfo = await resp.json();
|
updateInfo = await resp.json();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
}
|
}
|
||||||
if (!!updateInfo && !!updateInfo.Found) {
|
if ((!!updateInfo && process.env.NODE_ENV === 'production') && (!!updateInfo.HttpsFound ||
|
||||||
|
(!!updateInfo.Found && window.location.protocol !== "https:"))) {
|
||||||
this.$notify.warning({
|
this.$notify.warning({
|
||||||
title: '发现更新',
|
title: '发现更新',
|
||||||
message: '发现新版本 v' + updateInfo.Version +
|
message: '发现新版本 v' + updateInfo.Version +
|
||||||
|
@@ -1,4 +1,6 @@
|
|||||||
const NcmDecrypt = require("./ncm");
|
const NcmDecrypt = require("./ncm");
|
||||||
|
const KwmDecrypt = require("./kwm");
|
||||||
|
const XmDecrypt = require("./xm");
|
||||||
const QmcDecrypt = require("./qmc");
|
const QmcDecrypt = require("./qmc");
|
||||||
const RawDecrypt = require("./raw");
|
const RawDecrypt = require("./raw");
|
||||||
const TmDecrypt = require("./tm");
|
const TmDecrypt = require("./tm");
|
||||||
@@ -11,9 +13,16 @@ export async function CommonDecrypt(file) {
|
|||||||
case "ncm":// Netease Mp3/Flac
|
case "ncm":// Netease Mp3/Flac
|
||||||
rt_data = await NcmDecrypt.Decrypt(file.raw, raw_filename, raw_ext);
|
rt_data = await NcmDecrypt.Decrypt(file.raw, raw_filename, raw_ext);
|
||||||
break;
|
break;
|
||||||
case "mp3":// Raw Mp3
|
case "kwm":// Kuwo Mp3/Flac
|
||||||
case "flac"://Raw Flac
|
rt_data = await KwmDecrypt.Decrypt(file.raw, raw_filename, raw_ext);
|
||||||
case "m4a":// Raw M4a
|
break
|
||||||
|
case "xm": // Xiami Wav/M4a/Mp3/Flac
|
||||||
|
case "wav":// Xiami/Raw Wav
|
||||||
|
case "mp3":// Xiami/Raw Mp3
|
||||||
|
case "flac":// Xiami/Raw Flac
|
||||||
|
case "m4a":// Xiami/Raw M4a
|
||||||
|
rt_data = await XmDecrypt.Decrypt(file.raw, raw_filename, raw_ext);
|
||||||
|
break;
|
||||||
case "ogg":// Raw Ogg
|
case "ogg":// Raw Ogg
|
||||||
rt_data = await RawDecrypt.Decrypt(file.raw, raw_filename, raw_ext);
|
rt_data = await RawDecrypt.Decrypt(file.raw, raw_filename, raw_ext);
|
||||||
break;
|
break;
|
||||||
|
84
src/decrypt/kwm.js
Normal file
84
src/decrypt/kwm.js
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
import {
|
||||||
|
AudioMimeType,
|
||||||
|
DetectAudioExt,
|
||||||
|
GetArrayBuffer,
|
||||||
|
GetFileInfo,
|
||||||
|
GetMetaCoverURL,
|
||||||
|
IsBytesEqual
|
||||||
|
} from "./util";
|
||||||
|
|
||||||
|
const musicMetadata = require("music-metadata-browser");
|
||||||
|
const MagicHeader = [
|
||||||
|
0x79, 0x65, 0x65, 0x6C, 0x69, 0x6F, 0x6E, 0x2D,
|
||||||
|
0x6B, 0x75, 0x77, 0x6F, 0x2D, 0x74, 0x6D, 0x65,
|
||||||
|
]
|
||||||
|
const PreDefinedKey = "MoOtOiTvINGwd2E6n0E1i7L5t2IoOoNk"
|
||||||
|
|
||||||
|
export async function Decrypt(file, raw_filename, raw_ext) {
|
||||||
|
const oriData = new Uint8Array(await GetArrayBuffer(file));
|
||||||
|
if (!IsBytesEqual(MagicHeader, oriData.slice(0, 0x10)))
|
||||||
|
return {status: false, message: "Not a valid kwm file!"}
|
||||||
|
|
||||||
|
let fileKey = oriData.slice(0x18, 0x20)
|
||||||
|
let mask = createMaskFromKey(fileKey)
|
||||||
|
|
||||||
|
function Uint8ArrayToString(fileData) {
|
||||||
|
var dataString = "";
|
||||||
|
for (var i = 0; i < fileData.length; i++) {
|
||||||
|
dataString += String.fromCharCode(fileData[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return dataString
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
let audioData = oriData.slice(0x400);
|
||||||
|
let lenAudioData = audioData.length;
|
||||||
|
for (let cur = 0; cur < lenAudioData; ++cur)
|
||||||
|
audioData[cur] ^= mask[cur % 0x20];
|
||||||
|
|
||||||
|
|
||||||
|
const ext = DetectAudioExt(audioData, "mp3");
|
||||||
|
const mime = AudioMimeType[ext];
|
||||||
|
let musicBlob = new Blob([audioData], {type: mime});
|
||||||
|
|
||||||
|
const musicMeta = await musicMetadata.parseBlob(musicBlob);
|
||||||
|
const info = GetFileInfo(musicMeta.common.artist, musicMeta.common.title, raw_filename);
|
||||||
|
|
||||||
|
const imgUrl = GetMetaCoverURL(musicMeta);
|
||||||
|
|
||||||
|
return {
|
||||||
|
status: true,
|
||||||
|
title: info.title,
|
||||||
|
artist: info.artist,
|
||||||
|
ext: ext,
|
||||||
|
album: musicMeta.common.album,
|
||||||
|
picture: imgUrl,
|
||||||
|
file: URL.createObjectURL(musicBlob),
|
||||||
|
mime: mime
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function createMaskFromKey(keyBytes) {
|
||||||
|
let keyView = new DataView(keyBytes.buffer)
|
||||||
|
let keyStr = keyView.getBigUint64(0, true).toString()
|
||||||
|
let keyStrTrim = trimKey(keyStr)
|
||||||
|
let key = new Uint8Array(32)
|
||||||
|
for (let i = 0; i < 32; i++) {
|
||||||
|
key[i] = PreDefinedKey[i].charCodeAt() ^ keyStrTrim[i].charCodeAt()
|
||||||
|
}
|
||||||
|
return key
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function trimKey(keyRaw) {
|
||||||
|
let lenRaw = keyRaw.length;
|
||||||
|
let out = keyRaw;
|
||||||
|
if (lenRaw > 32) {
|
||||||
|
out = keyRaw.slice(0, 32)
|
||||||
|
} else if (lenRaw < 32) {
|
||||||
|
out = keyRaw.padEnd(32, keyRaw)
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
@@ -19,7 +19,8 @@ export async function Decrypt(file, raw_filename, raw_ext) {
|
|||||||
let audioOffset = musicMetaObj.offset + dataView.getUint32(musicMetaObj.offset + 5, true) + 13;
|
let audioOffset = musicMetaObj.offset + dataView.getUint32(musicMetaObj.offset + 5, true) + 13;
|
||||||
let audioData = new Uint8Array(fileBuffer, audioOffset);
|
let audioData = new Uint8Array(fileBuffer, audioOffset);
|
||||||
|
|
||||||
for (let cur = 0; cur < audioData.length; ++cur) audioData[cur] ^= keyBox[cur & 0xff];
|
let lenAudioData = audioData.length;
|
||||||
|
for (let cur = 0; cur < lenAudioData; ++cur) audioData[cur] ^= keyBox[cur & 0xff];
|
||||||
|
|
||||||
|
|
||||||
if (musicMeta.album === undefined) musicMeta.album = "";
|
if (musicMeta.album === undefined) musicMeta.album = "";
|
||||||
|
@@ -50,7 +50,6 @@ export async function Decrypt(file, raw_filename, raw_ext) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//todo: Use artists list to replace artist
|
|
||||||
const info = GetFileInfo(musicMeta.common.artist, musicMeta.common.title, raw_filename);
|
const info = GetFileInfo(musicMeta.common.artist, musicMeta.common.title, raw_filename);
|
||||||
if (handler.detect) reportKeyUsage(keyData, seed.Matrix128,
|
if (handler.detect) reportKeyUsage(keyData, seed.Matrix128,
|
||||||
info.artist, info.title, musicMeta.common.album, raw_filename, raw_ext);
|
info.artist, info.title, musicMeta.common.album, raw_filename, raw_ext);
|
||||||
@@ -105,18 +104,15 @@ async function queryAlbumCoverImage(artist, title, album) {
|
|||||||
jsonpData = await RequestJsonp(song_query_url, "callback");
|
jsonpData = await RequestJsonp(song_query_url, "callback");
|
||||||
queriedSong = jsonpData["data"]["song"]["list"][0];
|
queriedSong = jsonpData["data"]["song"]["list"][0];
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
|
||||||
}
|
}
|
||||||
console.log(queriedSong);
|
|
||||||
let imgUrl = "";
|
let imgUrl = "";
|
||||||
if (undefined !== queriedSong && undefined !== queriedSong["album"]) {
|
if (!!queriedSong && !!queriedSong["album"]) {
|
||||||
if (queriedSong["album"]["pmid"] !== undefined) {
|
if (queriedSong["album"]["pmid"] !== undefined) {
|
||||||
imgUrl = "https://y.gtimg.cn/music/photo_new/T002M000" + queriedSong["album"]["pmid"] + ".jpg"
|
imgUrl = "https://y.gtimg.cn/music/photo_new/T002M000" + queriedSong["album"]["pmid"] + ".jpg"
|
||||||
} else if (queriedSong["album"]["id"] !== undefined) {
|
} else if (queriedSong["album"]["id"] !== undefined) {
|
||||||
imgUrl = "https://imgcache.qq.com/music/photo/album/" +
|
imgUrl = "https://imgcache.qq.com/music/photo/album/" +
|
||||||
queriedSong["album"]["id"] % 100 +
|
queriedSong["album"]["id"] % 100 + "/albumpic_" + queriedSong["album"]["id"] + "_0.jpg"
|
||||||
"/albumpic_" + queriedSong["album"]["id"] + "_0.jpg"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return imgUrl;
|
return imgUrl;
|
||||||
}
|
}
|
||||||
|
@@ -3,11 +3,18 @@ export const FLAC_HEADER = [0x66, 0x4C, 0x61, 0x43];
|
|||||||
export const MP3_HEADER = [0x49, 0x44, 0x33];
|
export const MP3_HEADER = [0x49, 0x44, 0x33];
|
||||||
export const OGG_HEADER = [0x4F, 0x67, 0x67, 0x53];
|
export const OGG_HEADER = [0x4F, 0x67, 0x67, 0x53];
|
||||||
export const M4A_HEADER = [0x66, 0x74, 0x79, 0x70];
|
export const M4A_HEADER = [0x66, 0x74, 0x79, 0x70];
|
||||||
|
export const WMA_HEADER = [
|
||||||
|
0x30, 0x26, 0xB2, 0x75, 0x8E, 0x66, 0xCF, 0x11,
|
||||||
|
0xA6, 0xD9, 0x00, 0xAA, 0x00, 0x62, 0xCE, 0x6C,
|
||||||
|
]
|
||||||
|
export const WAV_HEADER = [0x52, 0x49, 0x46, 0x46]
|
||||||
export const AudioMimeType = {
|
export const AudioMimeType = {
|
||||||
mp3: "audio/mpeg",
|
mp3: "audio/mpeg",
|
||||||
flac: "audio/flac",
|
flac: "audio/flac",
|
||||||
m4a: "audio/mp4",
|
m4a: "audio/mp4",
|
||||||
ogg: "audio/ogg"
|
ogg: "audio/ogg",
|
||||||
|
wma: "audio/x-ms-wma",
|
||||||
|
wav: "audio/x-wav"
|
||||||
};
|
};
|
||||||
|
|
||||||
// Also a new draft API: blob.arrayBuffer()
|
// Also a new draft API: blob.arrayBuffer()
|
||||||
@@ -21,9 +28,9 @@ export async function GetArrayBuffer(blobObject) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function GetFileInfo(artist, title, filenameNoExt) {
|
export function GetFileInfo(artist, title, filenameNoExt, separator = "-") {
|
||||||
let newArtist = "", newTitle = "";
|
let newArtist = "", newTitle = "";
|
||||||
let filenameArray = filenameNoExt.split("-");
|
let filenameArray = filenameNoExt.split(separator);
|
||||||
if (filenameArray.length > 1) {
|
if (filenameArray.length > 1) {
|
||||||
newArtist = filenameArray[0].trim();
|
newArtist = filenameArray[0].trim();
|
||||||
newTitle = filenameArray[1].trim();
|
newTitle = filenameArray[1].trim();
|
||||||
@@ -63,6 +70,8 @@ export function DetectAudioExt(data, fallbackExt) {
|
|||||||
if (IsBytesEqual(FLAC_HEADER, data.slice(0, FLAC_HEADER.length))) return "flac";
|
if (IsBytesEqual(FLAC_HEADER, data.slice(0, FLAC_HEADER.length))) return "flac";
|
||||||
if (IsBytesEqual(OGG_HEADER, data.slice(0, OGG_HEADER.length))) return "ogg";
|
if (IsBytesEqual(OGG_HEADER, data.slice(0, OGG_HEADER.length))) return "ogg";
|
||||||
if (IsBytesEqual(M4A_HEADER, data.slice(4, 4 + M4A_HEADER.length))) return "m4a";
|
if (IsBytesEqual(M4A_HEADER, data.slice(4, 4 + M4A_HEADER.length))) return "m4a";
|
||||||
|
if (IsBytesEqual(WMA_HEADER, data.slice(0, WMA_HEADER.length))) return "wma";
|
||||||
|
if (IsBytesEqual(WAV_HEADER, data.slice(0, WAV_HEADER.length))) return "wav";
|
||||||
return fallbackExt;
|
return fallbackExt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
72
src/decrypt/xm.js
Normal file
72
src/decrypt/xm.js
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
import {
|
||||||
|
AudioMimeType,
|
||||||
|
DetectAudioExt,
|
||||||
|
GetArrayBuffer,
|
||||||
|
GetFileInfo,
|
||||||
|
GetMetaCoverURL,
|
||||||
|
IsBytesEqual
|
||||||
|
} from "./util";
|
||||||
|
|
||||||
|
import {Decrypt as RawDecrypt} from "./raw";
|
||||||
|
|
||||||
|
const musicMetadata = require("music-metadata-browser");
|
||||||
|
const MagicHeader = [0x69, 0x66, 0x6D, 0x74]
|
||||||
|
const MagicHeader2 = [0xfe, 0xfe, 0xfe, 0xfe]
|
||||||
|
const FileTypeMap = {
|
||||||
|
" WAV": ".wav",
|
||||||
|
"FLAC": ".flac",
|
||||||
|
" MP3": ".mp3",
|
||||||
|
" A4M": ".m4a",
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function Decrypt(file, raw_filename, raw_ext) {
|
||||||
|
const oriData = new Uint8Array(await GetArrayBuffer(file));
|
||||||
|
if (!IsBytesEqual(MagicHeader, oriData.slice(0, 4)) ||
|
||||||
|
!IsBytesEqual(MagicHeader2, oriData.slice(8, 12))) {
|
||||||
|
if (raw_ext === "xm") {
|
||||||
|
return {status: false, message: "Not a valid xm file!"}
|
||||||
|
} else {
|
||||||
|
return await RawDecrypt(file, raw_filename, raw_ext, true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let typeText = (new TextDecoder()).decode(oriData.slice(4, 8))
|
||||||
|
if (!FileTypeMap.hasOwnProperty(typeText)) {
|
||||||
|
return {status: false, message: "New Xiami file category!"}
|
||||||
|
}
|
||||||
|
|
||||||
|
let key = oriData[0xf]
|
||||||
|
let dataOffset = oriData[0xc] | oriData[0xd] << 8
|
||||||
|
let audioData = oriData.slice(0x10);
|
||||||
|
let lenAudioData = audioData.length;
|
||||||
|
for (let cur = dataOffset; cur < lenAudioData; ++cur)
|
||||||
|
audioData[cur] = (audioData[cur] - key) ^ 0xff;
|
||||||
|
|
||||||
|
const ext = DetectAudioExt(audioData, "mp3");
|
||||||
|
const mime = AudioMimeType[ext];
|
||||||
|
let musicBlob = new Blob([audioData], {type: mime});
|
||||||
|
|
||||||
|
const musicMeta = await musicMetadata.parseBlob(musicBlob);
|
||||||
|
if (ext === "wav") {
|
||||||
|
//todo:未知的编码方式
|
||||||
|
musicMeta.common.album = "";
|
||||||
|
musicMeta.common.artist = "";
|
||||||
|
musicMeta.common.title = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
const info = GetFileInfo(musicMeta.common.artist, musicMeta.common.title, raw_filename, "_");
|
||||||
|
|
||||||
|
const imgUrl = GetMetaCoverURL(musicMeta);
|
||||||
|
|
||||||
|
return {
|
||||||
|
status: true,
|
||||||
|
title: info.title,
|
||||||
|
artist: info.artist,
|
||||||
|
ext: ext,
|
||||||
|
album: musicMeta.common.album,
|
||||||
|
picture: imgUrl,
|
||||||
|
file: URL.createObjectURL(musicBlob),
|
||||||
|
mime: mime
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@@ -5,10 +5,7 @@ import {register} from 'register-service-worker'
|
|||||||
if (process.env.NODE_ENV === 'production') {
|
if (process.env.NODE_ENV === 'production') {
|
||||||
register(`${process.env.BASE_URL}service-worker.js`, {
|
register(`${process.env.BASE_URL}service-worker.js`, {
|
||||||
ready() {
|
ready() {
|
||||||
console.log(
|
console.log('App is being served from cache by a service worker.')
|
||||||
'App is being served from cache by a service worker.\n' +
|
|
||||||
'For more details, visit https://goo.gl/AFskqB'
|
|
||||||
)
|
|
||||||
},
|
},
|
||||||
registered() {
|
registered() {
|
||||||
console.log('Service worker has been registered.')
|
console.log('Service worker has been registered.')
|
||||||
|
Reference in New Issue
Block a user