Compare commits
10 Commits
master
...
v1.9.0-bet
Author | SHA1 | Date |
---|---|---|
Emmm Monster | 7c1f2cfc34 | |
Emmm Monster | aa2f689b13 | |
Emmm Monster | c908158439 | |
Emmm Monster | 9dacf46cc1 | |
Emmm Monster | 51184ea80f | |
Emmm Monster | 9ddad74554 | |
Emmm Monster | 01e33b26a5 | |
Emmm Monster | 7acf497a5f | |
Emmm Monster | b0f3da6d41 | |
Emmm Monster | 8e4ba856ea |
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "unlock-music",
|
||||
"version": "1.8.1",
|
||||
"version": "v1.9.0-beta",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
@ -1722,6 +1722,12 @@
|
|||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"@types/crypto-js": {
|
||||
"version": "4.0.1",
|
||||
"resolved": "http://mirrors.cloud.tencent.com/npm/@types%2fcrypto-js/-/crypto-js-4.0.1.tgz",
|
||||
"integrity": "sha512-6+OPzqhKX/cx5xh+yO8Cqg3u3alrkhoxhE5ZOdSEv0DOzJ13lwJ6laqGU0Kv6+XDMFmlnGId04LtY22PsFLQUw==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/debug": {
|
||||
"version": "4.1.5",
|
||||
"resolved": "https://registry.npmjs.org/@types/debug/-/debug-4.1.5.tgz",
|
||||
|
@ -5814,6 +5820,12 @@
|
|||
"estraverse": "^4.1.1"
|
||||
}
|
||||
},
|
||||
"esm": {
|
||||
"version": "3.2.25",
|
||||
"resolved": "http://mirrors.cloud.tencent.com/npm/esm/-/esm-3.2.25.tgz",
|
||||
"integrity": "sha512-U1suiZ2oDVWv4zPO56S0NcR5QriEahGtdN2OR6FiOG4WJvcjBVFB0qI4+eKoWFH483PKGuLuu6V8Z4T5g63UVA==",
|
||||
"optional": true
|
||||
},
|
||||
"esprima": {
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz",
|
||||
|
@ -7388,9 +7400,9 @@
|
|||
"dev": true
|
||||
},
|
||||
"iconv-lite": {
|
||||
"version": "0.6.2",
|
||||
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.2.tgz",
|
||||
"integrity": "sha512-2y91h5OpQlolefMPmUlivelittSWy0rP+oYVpn6A7GwVHNE8AWzoYOBNmlwks3LobaJxgHCYZAnyNo2GgpNRNQ==",
|
||||
"version": "0.6.3",
|
||||
"resolved": "http://mirrors.cloud.tencent.com/npm/iconv-lite/-/iconv-lite-0.6.3.tgz",
|
||||
"integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==",
|
||||
"requires": {
|
||||
"safer-buffer": ">= 2.1.2 < 3.0.0"
|
||||
}
|
||||
|
@ -7816,6 +7828,11 @@
|
|||
"integrity": "sha1-PkcprB9f3gJc19g6iW2rn09n2w8=",
|
||||
"dev": true
|
||||
},
|
||||
"is-observable": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "http://mirrors.cloud.tencent.com/npm/is-observable/-/is-observable-2.1.0.tgz",
|
||||
"integrity": "sha512-DailKdLb0WU+xX8K5w7VsJhapwHLZ9jjmazqCJq4X12CTgqq73TKnbRcnSLuXYPOoLQgV5IrD7ePiX/h1vnkBw=="
|
||||
},
|
||||
"is-path-cwd": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/is-path-cwd/-/is-path-cwd-2.2.0.tgz",
|
||||
|
@ -9299,6 +9316,11 @@
|
|||
"has": "^1.0.3"
|
||||
}
|
||||
},
|
||||
"observable-fns": {
|
||||
"version": "0.5.1",
|
||||
"resolved": "http://mirrors.cloud.tencent.com/npm/observable-fns/-/observable-fns-0.5.1.tgz",
|
||||
"integrity": "sha512-wf7g4Jpo1Wt2KIqZKLGeiuLOEMqpaOZ5gJn7DmSdqXgTdxRwSdBhWegQQpPteQ2gZvzCKqNNpwb853wcpA0j7A=="
|
||||
},
|
||||
"obuf": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/obuf/-/obuf-1.1.2.tgz",
|
||||
|
@ -12237,6 +12259,56 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"threads": {
|
||||
"version": "1.6.4",
|
||||
"resolved": "http://mirrors.cloud.tencent.com/npm/threads/-/threads-1.6.4.tgz",
|
||||
"integrity": "sha512-A+9MQFAUha9W8MjIPmrvETy98qVmZFr5Unox9D95y7kvz3fBpGiFS7JOZs07B2KvTHoRNI5MrGudRVeCmv4Alw==",
|
||||
"requires": {
|
||||
"callsites": "^3.1.0",
|
||||
"debug": "^4.2.0",
|
||||
"is-observable": "^2.1.0",
|
||||
"observable-fns": "^0.5.1",
|
||||
"tiny-worker": ">= 2"
|
||||
},
|
||||
"dependencies": {
|
||||
"callsites": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://mirrors.tencent.com/npm/callsites/-/callsites-3.1.0.tgz",
|
||||
"integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"threads-plugin": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "http://mirrors.cloud.tencent.com/npm/threads-plugin/-/threads-plugin-1.4.0.tgz",
|
||||
"integrity": "sha512-lQENPueZLsD+6Cvxvj/QaQyUskwnFZO+2ZGDMnPIvtytSeywWvYzete8paZ9L+5IR4v8jnSYNZPlIQrEhSK1EA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"loader-utils": "^1.1.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"json5": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "http://mirrors.cloud.tencent.com/npm/json5/-/json5-1.0.1.tgz",
|
||||
"integrity": "sha512-aKS4WQjPenRxiQsC93MNfjx+nbF4PAdYzmd/1JIj8HYzqfbu86beTuNgXDzPknWk0n0uARlyewZo4s++ES36Ow==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"minimist": "^1.2.0"
|
||||
}
|
||||
},
|
||||
"loader-utils": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "http://mirrors.cloud.tencent.com/npm/loader-utils/-/loader-utils-1.4.0.tgz",
|
||||
"integrity": "sha512-qH0WSMBtn/oHuwjy/NucEgbx5dbxxnxup9s4PVXJUDHZBQY+s0NWA9rJf53RBnQZxfch7euUui7hpoAPvALZdA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"big.js": "^5.2.2",
|
||||
"emojis-list": "^3.0.0",
|
||||
"json5": "^1.0.1"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"throttle-debounce": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/throttle-debounce/-/throttle-debounce-1.1.0.tgz",
|
||||
|
@ -12278,6 +12350,15 @@
|
|||
"integrity": "sha1-QFQRqOfmM5/mTbmiNN4R3DHgK9Q=",
|
||||
"dev": true
|
||||
},
|
||||
"tiny-worker": {
|
||||
"version": "2.3.0",
|
||||
"resolved": "http://mirrors.cloud.tencent.com/npm/tiny-worker/-/tiny-worker-2.3.0.tgz",
|
||||
"integrity": "sha512-pJ70wq5EAqTAEl9IkGzA+fN0836rycEuz2Cn6yeZ6FRzlVS5IDOkFHpIoEsksPRQV34GDqXm65+OlnZqUSyK2g==",
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"esm": "^3.2.25"
|
||||
}
|
||||
},
|
||||
"tinycolor2": {
|
||||
"version": "1.4.2",
|
||||
"resolved": "https://registry.npmjs.org/tinycolor2/-/tinycolor2-1.4.2.tgz",
|
||||
|
@ -13003,11 +13084,6 @@
|
|||
"resolved": "https://registry.npmjs.org/vue/-/vue-2.6.12.tgz",
|
||||
"integrity": "sha512-uhmLFETqPPNyuLLbsKz6ioJ4q7AZHzD8ZVFNATNyICSZouqP2Sz0rotWQC8UNBF6VGSCs5abnKJoStA6JbCbfg=="
|
||||
},
|
||||
"vue-class-component": {
|
||||
"version": "7.2.6",
|
||||
"resolved": "http://mirrors.cloud.tencent.com/npm/vue-class-component/-/vue-class-component-7.2.6.tgz",
|
||||
"integrity": "sha512-+eaQXVrAm/LldalI272PpDe3+i4mPis0ORiMYxF6Ae4hyuCh15W8Idet7wPUEs4N4YptgFHGys4UrgNQOMyO6w=="
|
||||
},
|
||||
"vue-cli-plugin-element": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/vue-cli-plugin-element/-/vue-cli-plugin-element-1.0.1.tgz",
|
||||
|
@ -13130,11 +13206,6 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"vue-property-decorator": {
|
||||
"version": "9.1.2",
|
||||
"resolved": "http://mirrors.cloud.tencent.com/npm/vue-property-decorator/-/vue-property-decorator-9.1.2.tgz",
|
||||
"integrity": "sha512-xYA8MkZynPBGd/w5QFJ2d/NM0z/YeegMqYTphy7NJQXbZcuU6FC6AOdUAcy4SXP+YnkerC6AfH+ldg7PDk9ESQ=="
|
||||
},
|
||||
"vue-style-loader": {
|
||||
"version": "4.1.3",
|
||||
"resolved": "https://registry.npmjs.org/vue-style-loader/-/vue-style-loader-4.1.3.tgz",
|
||||
|
@ -13951,15 +14022,6 @@
|
|||
"microevent.ts": "~0.1.1"
|
||||
}
|
||||
},
|
||||
"workerize-loader": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/workerize-loader/-/workerize-loader-1.3.0.tgz",
|
||||
"integrity": "sha512-utWDc8K6embcICmRBUUkzanPgKBb8yM1OHfh6siZfiMsswE8wLCa9CWS+L7AARz0+Th4KH4ZySrqer/OJ9WuWw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"loader-utils": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"wrap-ansi": {
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-5.1.0.tgz",
|
||||
|
|
16
package.json
16
package.json
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "unlock-music",
|
||||
"version": "1.8.1",
|
||||
"updateInfo": "添加构建为Docker镜像",
|
||||
"version": "v1.9.0-beta",
|
||||
"updateInfo": "新增写入本地文件系统; 优化.kwm解锁; 支持.acc嗅探; 使用Typescript重构",
|
||||
"license": "MIT",
|
||||
"description": "Unlock encrypted music file in browser.",
|
||||
"repository": {
|
||||
|
@ -21,16 +21,16 @@
|
|||
"core-js": "^3.12.1",
|
||||
"crypto-js": "^4.0.0",
|
||||
"element-ui": "^2.15.1",
|
||||
"iconv-lite": "^0.6.2",
|
||||
"iconv-lite": "^0.6.3",
|
||||
"jimp": "^0.16.1",
|
||||
"metaflac-js": "^1.0.5",
|
||||
"music-metadata-browser": "^2.2.6",
|
||||
"register-service-worker": "^1.7.2",
|
||||
"vue": "^2.6.12",
|
||||
"vue-class-component": "^7.2.3",
|
||||
"vue-property-decorator": "^9.1.2"
|
||||
"threads": "^1.6.4",
|
||||
"vue": "^2.6.12"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/crypto-js": "^4.0.1",
|
||||
"@vue/cli-plugin-babel": "^4.5.13",
|
||||
"@vue/cli-plugin-pwa": "^4.5.13",
|
||||
"@vue/cli-plugin-typescript": "^4.5.13",
|
||||
|
@ -39,9 +39,9 @@
|
|||
"node-sass": "^5.0.0",
|
||||
"sass-loader": "^10.2.0",
|
||||
"semver": "^7.3.5",
|
||||
"threads-plugin": "^1.4.0",
|
||||
"typescript": "~4.1.5",
|
||||
"vue-cli-plugin-element": "^1.0.1",
|
||||
"vue-template-compiler": "^2.6.12",
|
||||
"workerize-loader": "^1.3.0"
|
||||
"vue-template-compiler": "^2.6.12"
|
||||
}
|
||||
}
|
||||
|
|
195
src/App.vue
195
src/App.vue
|
@ -1,41 +1,12 @@
|
|||
<template>
|
||||
|
||||
<el-container id="app">
|
||||
<el-main>
|
||||
<x-upload v-on:handle_error="showFail" v-on:handle_finish="showSuccess"></x-upload>
|
||||
|
||||
<div id="app-control">
|
||||
<el-row class="mb-3">
|
||||
<span>歌曲命名格式:</span>
|
||||
<el-radio label="1" name="format" v-model="download_format">歌手-歌曲名</el-radio>
|
||||
<el-radio label="2" name="format" v-model="download_format">歌曲名</el-radio>
|
||||
<el-radio label="3" name="format" v-model="download_format">歌曲名-歌手</el-radio>
|
||||
<el-radio label="4" name="format" v-model="download_format">同原文件名</el-radio>
|
||||
</el-row>
|
||||
<el-row>
|
||||
<el-button @click="handleDownloadAll" icon="el-icon-download" plain>下载全部</el-button>
|
||||
<el-button @click="handleDeleteAll" icon="el-icon-delete" plain type="danger">清除全部</el-button>
|
||||
|
||||
<el-tooltip class="item" effect="dark" placement="top-start">
|
||||
<div slot="content">
|
||||
当您使用此工具进行大量文件解锁的时候,建议开启此选项。<br/>
|
||||
开启后,解锁结果将不会存留于浏览器中,防止内存不足。
|
||||
</div>
|
||||
<el-checkbox border class="ml-2" v-model="instant_download">立即保存</el-checkbox>
|
||||
</el-tooltip>
|
||||
</el-row>
|
||||
</div>
|
||||
|
||||
<audio :autoplay="playing_auto" :src="playing_url" controls/>
|
||||
|
||||
<x-preview :download_format="download_format" :table-data="tableData"
|
||||
v-on:music_changed="changePlaying"></x-preview>
|
||||
|
||||
<Home/>
|
||||
</el-main>
|
||||
<el-footer id="app-footer">
|
||||
<el-row>
|
||||
<a href="https://github.com/ix64/unlock-music" target="_blank">音乐解锁</a>(v<span
|
||||
v-text="version"></span>):移除已购音乐的加密保护。
|
||||
<a href="https://github.com/ix64/unlock-music" target="_blank">音乐解锁</a>({{ version }})
|
||||
:移除已购音乐的加密保护。
|
||||
<a href="https://github.com/ix64/unlock-music/wiki/使用提示" target="_blank">使用提示</a>
|
||||
</el-row>
|
||||
<el-row>
|
||||
|
@ -44,141 +15,71 @@
|
|||
</el-row>
|
||||
<el-row>
|
||||
<!--如果进行二次开发,此行版权信息不得移除且应明显地标注于页面上-->
|
||||
<span>Copyright © 2019-</span><span v-text="(new Date()).getFullYear()"></span> MengYX
|
||||
<span>Copyright © 2019 - {{ (new Date()).getFullYear() }} MengYX</span>
|
||||
音乐解锁使用
|
||||
<a href="https://github.com/ix64/unlock-music/blob/master/LICENSE" target="_blank">MIT许可协议</a>
|
||||
开放源代码
|
||||
</el-row>
|
||||
</el-footer>
|
||||
</el-container>
|
||||
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
||||
import upload from "./component/upload"
|
||||
import preview from "./component/preview"
|
||||
import {DownloadBlobMusic, RemoveBlobMusic} from "./component/util"
|
||||
import config from "../package"
|
||||
import {IXAREA_API_ENDPOINT} from "./decrypt/util";
|
||||
import FileSelector from "@/component/FileSelector"
|
||||
import PreviewTable from "@/component/PreviewTable"
|
||||
import config from "@/../package.json"
|
||||
import Home from "@/view/Home";
|
||||
import {checkUpdate} from "@/utils/api";
|
||||
|
||||
export default {
|
||||
name: 'app',
|
||||
components: {
|
||||
xUpload: upload,
|
||||
xPreview: preview
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
version: config.version,
|
||||
activeIndex: '1',
|
||||
tableData: [],
|
||||
playing_url: "",
|
||||
playing_auto: false,
|
||||
download_format: '1',
|
||||
instant_download: false,
|
||||
export default {
|
||||
name: 'app',
|
||||
components: {
|
||||
FileSelector,
|
||||
PreviewTable,
|
||||
Home
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
version: config.version,
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.$nextTick(() => this.finishLoad());
|
||||
},
|
||||
methods: {
|
||||
async finishLoad() {
|
||||
const mask = document.getElementById("loader-mask");
|
||||
if (!!mask) mask.remove();
|
||||
let updateInfo;
|
||||
try {
|
||||
updateInfo = await checkUpdate(this.version)
|
||||
} catch (e) {
|
||||
console.warn("check version info failed", e)
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.$nextTick(function () {
|
||||
this.finishLoad();
|
||||
});
|
||||
},
|
||||
methods: {
|
||||
async finishLoad() {
|
||||
const mask = document.getElementById("loader-mask");
|
||||
if (!!mask) mask.remove();
|
||||
let updateInfo;
|
||||
try {
|
||||
const resp = await fetch(IXAREA_API_ENDPOINT + "/music/app-version", {
|
||||
method: "POST", headers: {"Content-Type": "application/json"},
|
||||
body: JSON.stringify({"Version": this.version})
|
||||
});
|
||||
updateInfo = await resp.json();
|
||||
} catch (e) {
|
||||
}
|
||||
if ((!!updateInfo && process.env.NODE_ENV === 'production') && (!!updateInfo.HttpsFound ||
|
||||
(!!updateInfo.Found && window.location.protocol !== "https:"))) {
|
||||
this.$notify.warning({
|
||||
if ((updateInfo && process.env.NODE_ENV === 'production') && (updateInfo.HttpsFound ||
|
||||
(updateInfo.Found && window.location.protocol !== "https:"))) {
|
||||
this.$notify.warning({
|
||||
title: '发现更新',
|
||||
message: '发现新版本 v' + updateInfo.Version +
|
||||
'<br/>更新详情:' + updateInfo.Detail +
|
||||
'<br/><a target="_blank" href="' + updateInfo.URL + '">获取更新</a>',
|
||||
message: `发现新版本 v${updateInfo.Version}<br/>更新详情:${updateInfo.Detail}<br/> <a target="_blank" href="${updateInfo.URL}">获取更新</a>`,
|
||||
dangerouslyUseHTMLString: true,
|
||||
duration: 15000,
|
||||
position: 'top-left'
|
||||
});
|
||||
} else {
|
||||
this.$notify.info({
|
||||
title: '离线使用',
|
||||
message: '我们使用PWA技术,无网络也能使用' +
|
||||
'<br/>最近更新:' + config.updateInfo +
|
||||
'<br/><a target="_blank" href="https://github.com/ix64/unlock-music/wiki/使用提示">使用提示</a>',
|
||||
dangerouslyUseHTMLString: true,
|
||||
duration: 10000,
|
||||
position: 'top-left'
|
||||
});
|
||||
}
|
||||
},
|
||||
showSuccess(data) {
|
||||
if (data.status) {
|
||||
if (this.instant_download) {
|
||||
DownloadBlobMusic(data, this.download_format);
|
||||
RemoveBlobMusic(data);
|
||||
} else {
|
||||
this.tableData.push(data);
|
||||
this.$notify.success({
|
||||
title: '解锁成功',
|
||||
message: '成功解锁 ' + data.title,
|
||||
duration: 3000
|
||||
});
|
||||
}
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
let _rp_data = [data.title, data.artist, data.album];
|
||||
window._paq.push(["trackEvent", "Unlock", data.rawExt + "," + data.mime, JSON.stringify(_rp_data)]);
|
||||
}
|
||||
} else {
|
||||
this.showFail(data.message, data.rawFilename + "." + data.rawExt)
|
||||
}
|
||||
},
|
||||
showFail(errInfo, filename) {
|
||||
this.$notify.error({
|
||||
title: '出现问题',
|
||||
message: errInfo + "," + filename +
|
||||
',参考<a target="_blank" href="https://github.com/ix64/unlock-music/wiki/使用提示">使用提示</a>',
|
||||
});
|
||||
} else {
|
||||
this.$notify.info({
|
||||
title: '离线使用',
|
||||
message: `我们使用PWA技术,无网络也能使用<br/>最近更新:${config.updateInfo}<br/><a target="_blank" href="https://github.com/ix64/unlock-music/wiki/使用提示">使用提示</a>`,
|
||||
dangerouslyUseHTMLString: true,
|
||||
duration: 6000
|
||||
duration: 10000,
|
||||
position: 'top-left'
|
||||
});
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
window._paq.push(["trackEvent", "Error", errInfo, filename]);
|
||||
}
|
||||
console.error(errInfo, filename);
|
||||
},
|
||||
changePlaying(url) {
|
||||
this.playing_url = url;
|
||||
this.playing_auto = true;
|
||||
},
|
||||
handleDeleteAll() {
|
||||
this.tableData.forEach(value => {
|
||||
RemoveBlobMusic(value);
|
||||
});
|
||||
this.tableData = [];
|
||||
},
|
||||
handleDownloadAll() {
|
||||
let index = 0;
|
||||
let c = setInterval(() => {
|
||||
if (index < this.tableData.length) {
|
||||
DownloadBlobMusic(this.tableData[index], this.download_format);
|
||||
index++;
|
||||
} else {
|
||||
clearInterval(c);
|
||||
}
|
||||
}, 300);
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
@import "scss/unlock-music";
|
||||
@import "scss/unlock-music";
|
||||
</style>
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
<template>
|
||||
<el-upload
|
||||
:auto-upload="false"
|
||||
:on-change="addFile"
|
||||
:show-file-list="false"
|
||||
action=""
|
||||
drag
|
||||
multiple>
|
||||
<i class="el-icon-upload"/>
|
||||
<div class="el-upload__text">将文件拖到此处,或<em>点击选择</em></div>
|
||||
<div slot="tip" class="el-upload__tip">
|
||||
<div>
|
||||
仅在浏览器内对文件进行解锁,无需消耗流量
|
||||
<el-tooltip effect="dark" placement="top-start">
|
||||
<div slot="content">
|
||||
算法在源代码中已经提供,所有运算都发生在本地
|
||||
</div>
|
||||
<i class="el-icon-info" style="font-size: 12px"/>
|
||||
</el-tooltip>
|
||||
</div>
|
||||
<div>
|
||||
工作模式: {{ parallel ? "多线程 Worker" : "单线程 Queue" }}
|
||||
<el-tooltip effect="dark" placement="top-start">
|
||||
<div slot="content">
|
||||
将此工具部署在HTTPS环境下,可以启用Web Worker特性,<br/>
|
||||
从而更快的利用并行处理完成解锁
|
||||
</div>
|
||||
<i class="el-icon-info" style="font-size: 12px"/>
|
||||
</el-tooltip>
|
||||
</div>
|
||||
</div>
|
||||
<transition name="el-fade-in"><!--todo: add delay to animation-->
|
||||
<el-progress
|
||||
v-show="progress_show" :format="progress_string" :percentage="progress_value"
|
||||
:stroke-width="16" :text-inside="true"
|
||||
style="margin: 16px 6px 0 6px"
|
||||
></el-progress>
|
||||
</transition>
|
||||
</el-upload>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {spawn, Worker, Pool} from "threads"
|
||||
import {CommonDecrypt} from "@/decrypt/common.ts";
|
||||
import {DecryptQueue} from "@/utils/utils";
|
||||
|
||||
export default {
|
||||
name: "FileSelector",
|
||||
data() {
|
||||
return {
|
||||
task_all: 0,
|
||||
task_finished: 0,
|
||||
queue: new DecryptQueue(), // for http or file protocol
|
||||
parallel: false
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
progress_value() {
|
||||
return this.task_all ? this.task_finished / this.task_all * 100 : 0
|
||||
},
|
||||
progress_show() {
|
||||
return this.task_all !== this.task_finished
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
if (window.Worker && process.env.NODE_ENV === 'production') {
|
||||
console.log("Using Worker Pool")
|
||||
this.queue = Pool(
|
||||
() => spawn(new Worker('@/utils/worker.ts')),
|
||||
navigator.hardwareConcurrency || 1
|
||||
)
|
||||
this.parallel = true
|
||||
} else {
|
||||
console.log("Using Queue in Main Thread")
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
progress_string() {
|
||||
return `${this.task_finished} / ${this.task_all}`
|
||||
},
|
||||
async addFile(file) {
|
||||
this.task_all++
|
||||
this.queue.queue(async (dec = CommonDecrypt) => {
|
||||
console.log("start handling", file.name)
|
||||
try {
|
||||
this.$emit("success", await dec(file));
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
this.$emit("error", e, file.name)
|
||||
} finally {
|
||||
this.task_finished++
|
||||
}
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
<template>
|
||||
<el-table :data="tableData" style="width: 100%">
|
||||
|
||||
<el-table-column label="封面">
|
||||
<template slot-scope="scope">
|
||||
<el-image :src="scope.row.picture" style="width: 100px; height: 100px">
|
||||
<div slot="error" class="image-slot el-image__error">
|
||||
暂无封面
|
||||
</div>
|
||||
</el-image>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="歌曲">
|
||||
<template #default="scope">
|
||||
<span>{{ scope.row.title }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="歌手">
|
||||
<template #default="scope">
|
||||
<p>{{ scope.row.artist }}</p>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="专辑">
|
||||
<template #default="scope">
|
||||
<p>{{ scope.row.album }}</p>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作">
|
||||
<template #default="scope">
|
||||
<el-button circle
|
||||
icon="el-icon-video-play" type="success" @click="handlePlay(scope.$index, scope.row)">
|
||||
</el-button>
|
||||
<el-button circle
|
||||
icon="el-icon-download" @click="handleDownload(scope.row)">
|
||||
</el-button>
|
||||
<el-button circle
|
||||
icon="el-icon-delete" type="danger" @click="handleDelete(scope.$index, scope.row)">
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {RemoveBlobMusic} from '@/utils/utils'
|
||||
|
||||
export default {
|
||||
name: "PreviewTable",
|
||||
props: {
|
||||
tableData: {type: Array, required: true},
|
||||
policy: {type: Number, required: true}
|
||||
},
|
||||
|
||||
methods: {
|
||||
handlePlay(index, row) {
|
||||
this.$emit("play", row.file);
|
||||
},
|
||||
handleDelete(index, row) {
|
||||
RemoveBlobMusic(row);
|
||||
this.tableData.splice(index, 1);
|
||||
},
|
||||
handleDownload(row) {
|
||||
this.$emit("download", row)
|
||||
},
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
|
@ -1,71 +0,0 @@
|
|||
<template>
|
||||
<el-table :data="tableData" style="width: 100%">
|
||||
|
||||
<el-table-column label="封面">
|
||||
<template slot-scope="scope">
|
||||
<el-image :src="scope.row.picture" style="width: 100px; height: 100px">
|
||||
<div class="image-slot el-image__error" slot="error">
|
||||
暂无封面
|
||||
</div>
|
||||
</el-image>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="歌曲">
|
||||
<template slot-scope="scope">
|
||||
<span>{{ scope.row.title }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="歌手">
|
||||
<template slot-scope="scope">
|
||||
<p>{{ scope.row.artist }}</p>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="专辑">
|
||||
<template slot-scope="scope">
|
||||
<p>{{ scope.row.album }}</p>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作">
|
||||
<template slot-scope="scope">
|
||||
<el-button @click="handlePlay(scope.$index, scope.row)"
|
||||
circle icon="el-icon-video-play" type="success">
|
||||
</el-button>
|
||||
<el-button @click="handleDownload(scope.row)"
|
||||
circle icon="el-icon-download">
|
||||
</el-button>
|
||||
<el-button @click="handleDelete(scope.$index, scope.row)"
|
||||
circle icon="el-icon-delete" type="danger">
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {DownloadBlobMusic, RemoveBlobMusic} from './util'
|
||||
|
||||
export default {
|
||||
name: "preview",
|
||||
props: {
|
||||
tableData: {type: Array, required: true},
|
||||
download_format: {type: String, required: true}
|
||||
},
|
||||
|
||||
methods: {
|
||||
handlePlay(index, row) {
|
||||
this.$emit("music_changed", row.file);
|
||||
},
|
||||
handleDelete(index, row) {
|
||||
RemoveBlobMusic(row);
|
||||
this.tableData.splice(index, 1);
|
||||
},
|
||||
handleDownload(row) {
|
||||
DownloadBlobMusic(row, this.download_format)
|
||||
},
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
|
@ -1,120 +0,0 @@
|
|||
<template>
|
||||
<el-upload
|
||||
:auto-upload="false"
|
||||
:on-change="handleFile"
|
||||
:show-file-list="false"
|
||||
action=""
|
||||
drag
|
||||
multiple>
|
||||
<i class="el-icon-upload"/>
|
||||
<div class="el-upload__text">将文件拖到此处,或<em>点击选择</em></div>
|
||||
<div class="el-upload__tip" slot="tip">本工具仅在浏览器内对文件进行解锁,无需消耗流量</div>
|
||||
<transition name="el-fade-in">
|
||||
<el-progress
|
||||
:format="progressFormat" :percentage="progress_percent" :stroke-width="16"
|
||||
:text-inside="true" style="margin: 16px 6px 0 6px"
|
||||
v-show="progress_show"
|
||||
></el-progress>
|
||||
</transition>
|
||||
</el-upload>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
"use strict";// 严格模式 用于尾调用优化
|
||||
|
||||
export default {
|
||||
name: "upload",
|
||||
data() {
|
||||
return {
|
||||
cacheQueue: [],
|
||||
workers: [],
|
||||
idle_workers: [],
|
||||
thread_num: 1,
|
||||
|
||||
progress_show: false,
|
||||
|
||||
progress_finished: 0,
|
||||
progress_all: 0,
|
||||
progress_percent: 0,
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
if (document.location.host !== "" && process.env.NODE_ENV === 'production') {
|
||||
this.thread_num = navigator.hardwareConcurrency || 1;
|
||||
const worker = require("workerize-loader!../decrypt/common");
|
||||
// noinspection JSValidateTypes,JSUnresolvedVariable
|
||||
this.workers.push(worker().CommonDecrypt);
|
||||
this.idle_workers.push(0);
|
||||
// delay to optimize for first loading
|
||||
setTimeout(() => {
|
||||
for (let i = 1; i < this.thread_num; i++) {
|
||||
// noinspection JSValidateTypes,JSUnresolvedVariable
|
||||
this.workers.push(worker().CommonDecrypt);
|
||||
this.idle_workers.push(i);
|
||||
}
|
||||
}, 5000);
|
||||
} else {
|
||||
const dec = require('../decrypt/common');
|
||||
this.workers.push(dec.CommonDecrypt);
|
||||
this.idle_workers.push(0)
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
progressFormat() {
|
||||
return this.progress_finished + "/" + (this.progress_all)
|
||||
},
|
||||
progressChange(finish, all) {
|
||||
this.progress_all += all;
|
||||
this.progress_finished += finish;
|
||||
this.progress_percent = Math.round(this.progress_finished / this.progress_all * 100);
|
||||
if (this.progress_finished === this.progress_all) {
|
||||
setTimeout(() => {
|
||||
this.progress_show = false;
|
||||
this.progress_finished = 0;
|
||||
this.progress_all = 0;
|
||||
}, 3000);
|
||||
} else {
|
||||
this.progress_show = true;
|
||||
}
|
||||
},
|
||||
handleFile(file) {
|
||||
this.progressChange(0, +1);
|
||||
// 有空闲worker 立刻处理文件
|
||||
if (this.idle_workers.length > 0) {
|
||||
this.handleDoFile(file, this.idle_workers.shift());
|
||||
}
|
||||
// 无空闲worker 则放入缓存队列
|
||||
else {
|
||||
this.cacheQueue.push(file);
|
||||
}
|
||||
},
|
||||
handleCacheQueue(worker_id) {
|
||||
// 调用方法消费缓存队列中的数据
|
||||
if (this.cacheQueue.length === 0) {
|
||||
this.idle_workers.push(worker_id);
|
||||
return
|
||||
}
|
||||
this.handleDoFile(this.cacheQueue.shift(), worker_id);
|
||||
},
|
||||
handleDoFile(file, worker_id) {
|
||||
this.workers[worker_id](file).then(data => {
|
||||
this.$emit("handle_finish", data);
|
||||
// 完成之后 执行新任务 todo: 可能导致call stack过长
|
||||
this.handleCacheQueue(worker_id);
|
||||
this.progressChange(+1, 0);
|
||||
}).catch(err => {
|
||||
this.$emit("handle_error", err, file.name);
|
||||
this.handleCacheQueue(worker_id);
|
||||
this.progressChange(+1, 0);
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
/*noinspection CssUnusedSymbol*/
|
||||
.el-upload-dragger {
|
||||
width: 80vw !important;
|
||||
}
|
||||
</style>
|
|
@ -1,30 +0,0 @@
|
|||
export function DownloadBlobMusic(data, format) {
|
||||
const a = document.createElement('a');
|
||||
a.href = data.file;
|
||||
switch (format) {
|
||||
default:
|
||||
case "1":
|
||||
a.download = data.artist + " - " + data.title + "." + data.ext;
|
||||
break;
|
||||
case "2":
|
||||
a.download = data.title + "." + data.ext;
|
||||
break;
|
||||
case "3":
|
||||
a.download = data.title + " - " + data.artist + "." + data.ext;
|
||||
break;
|
||||
case "4":
|
||||
a.download = data.rawFilename + "." + data.ext;
|
||||
break;
|
||||
}
|
||||
document.body.append(a);
|
||||
a.click();
|
||||
a.remove();
|
||||
}
|
||||
|
||||
export function RemoveBlobMusic(data) {
|
||||
URL.revokeObjectURL(data.file);
|
||||
if (data.picture.startsWith("blob:")) {
|
||||
URL.revokeObjectURL(data.picture);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,27 +1,17 @@
|
|||
import {Decrypt as NcmDecrypt} from "./ncm";
|
||||
import {Decrypt as XmDecrypt} from "./xm";
|
||||
import {Decrypt as QmcDecrypt} from "./qmc";
|
||||
import {Decrypt as KgmDecrypt} from "./kgm";
|
||||
import {Decrypt as NcmDecrypt} from "@/decrypt/ncm";
|
||||
import {Decrypt as XmDecrypt} from "@/decrypt/xm";
|
||||
import {Decrypt as QmcDecrypt} from "@/decrypt/qmc";
|
||||
import {Decrypt as KgmDecrypt} from "@/decrypt/kgm";
|
||||
import {Decrypt as KwmDecrypt} from "@/decrypt/kwm";
|
||||
import {Decrypt as RawDecrypt} from "@/decrypt/raw";
|
||||
import {Decrypt as TmDecrypt} from "@/decrypt/tm";
|
||||
import {DecryptResult} from "@/decrypt/entity";
|
||||
import {DecryptResult, FileInfo} from "@/decrypt/entity";
|
||||
|
||||
|
||||
interface FileInfo {
|
||||
status: string
|
||||
name: string,
|
||||
size: number,
|
||||
percentage: number,
|
||||
uid: number,
|
||||
raw: File
|
||||
}
|
||||
|
||||
|
||||
export async function CommonDecrypt(file: FileInfo) {
|
||||
export async function CommonDecrypt(file: FileInfo): Promise<DecryptResult> {
|
||||
let raw_ext = file.name.substring(file.name.lastIndexOf(".") + 1, file.name.length).toLowerCase();
|
||||
let raw_filename = file.name.substring(0, file.name.lastIndexOf("."));
|
||||
let rt_data: Partial<DecryptResult>;
|
||||
let rt_data: DecryptResult;
|
||||
switch (raw_ext) {
|
||||
case "ncm":// Netease Mp3/Flac
|
||||
rt_data = await NcmDecrypt(file.raw, raw_filename, raw_ext);
|
||||
|
@ -70,7 +60,7 @@ export async function CommonDecrypt(file: FileInfo) {
|
|||
rt_data = await KgmDecrypt(file.raw, raw_filename, raw_ext);
|
||||
break
|
||||
default:
|
||||
rt_data = {status: false, message: "不支持此文件格式",}
|
||||
throw "不支持此文件格式"
|
||||
}
|
||||
|
||||
if (!rt_data.rawExt) rt_data.rawExt = raw_ext;
|
||||
|
@ -78,3 +68,4 @@ export async function CommonDecrypt(file: FileInfo) {
|
|||
console.log(rt_data);
|
||||
return rt_data;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
export interface DecryptResult {
|
||||
status: boolean,//todo: remove & use Exception
|
||||
|
||||
title: string
|
||||
album?: string
|
||||
artist?: string
|
||||
|
@ -9,10 +7,20 @@ export interface DecryptResult {
|
|||
ext: string
|
||||
|
||||
file: string
|
||||
picture: string
|
||||
blob: Blob
|
||||
picture?: string
|
||||
|
||||
message?: string
|
||||
rawExt?: string
|
||||
rawFilename?: string
|
||||
|
||||
}
|
||||
|
||||
export interface FileInfo {
|
||||
status: string
|
||||
name: string,
|
||||
size: number,
|
||||
percentage: number,
|
||||
uid: number,
|
||||
raw: File
|
||||
}
|
||||
|
|
|
@ -1,126 +0,0 @@
|
|||
import {
|
||||
AudioMimeType,
|
||||
BytesHasPrefix,
|
||||
GetArrayBuffer,
|
||||
GetCoverFromFile,
|
||||
GetMetaFromFile,
|
||||
SniffAudioExt
|
||||
} from "@/decrypt/utils.ts";
|
||||
import {parseBlob as metaParseBlob} from "music-metadata-browser";
|
||||
|
||||
const VprHeader = [
|
||||
0x05, 0x28, 0xBC, 0x96, 0xE9, 0xE4, 0x5A, 0x43,
|
||||
0x91, 0xAA, 0xBD, 0xD0, 0x7A, 0xF5, 0x36, 0x31]
|
||||
const KgmHeader = [
|
||||
0x7C, 0xD5, 0x32, 0xEB, 0x86, 0x02, 0x7F, 0x4B,
|
||||
0xA8, 0xAF, 0xA6, 0x8E, 0x0F, 0xFF, 0x99, 0x14]
|
||||
const VprMaskDiff = [0x25, 0xDF, 0xE8, 0xA6, 0x75, 0x1E, 0x75, 0x0E,
|
||||
0x2F, 0x80, 0xF3, 0x2D, 0xB8, 0xB6, 0xE3, 0x11,
|
||||
0x00]
|
||||
|
||||
export async function Decrypt(file, raw_filename, raw_ext) {
|
||||
try {
|
||||
if (window.location.protocol === "file:") {
|
||||
return {
|
||||
status: false,
|
||||
message: "请使用<a target='_blank' href='https://github.com/ix64/unlock-music/wiki/其他音乐格式工具'>CLI版本</a>进行解锁"
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
}
|
||||
const oriData = new Uint8Array(await GetArrayBuffer(file));
|
||||
if (raw_ext === "vpr") {
|
||||
if (!BytesHasPrefix(oriData, VprHeader))
|
||||
return {status: false, message: "Not a valid vpr file!"}
|
||||
} else {
|
||||
if (!BytesHasPrefix(oriData, KgmHeader))
|
||||
return {status: false, message: "Not a valid kgm/kgma file!"}
|
||||
}
|
||||
let bHeaderLen = new DataView(oriData.slice(0x10, 0x14).buffer)
|
||||
let headerLen = bHeaderLen.getUint32(0, true)
|
||||
|
||||
let audioData = oriData.slice(headerLen)
|
||||
let dataLen = audioData.length
|
||||
if (audioData.byteLength > 1 << 26) {
|
||||
return {
|
||||
status: false,
|
||||
message: "文件过大,请使用<a target='_blank' href='https://github.com/ix64/unlock-music/wiki/其他音乐格式工具'>CLI版本</a>进行解锁"
|
||||
}
|
||||
}
|
||||
|
||||
let key1 = new Uint8Array(17)
|
||||
key1.set(oriData.slice(0x1c, 0x2c), 0)
|
||||
if (MaskV2 == null) {
|
||||
if (!await LoadMaskV2()) {
|
||||
return {status: false, message: "加载Kgm/Vpr Mask数据失败"}
|
||||
}
|
||||
}
|
||||
|
||||
for (let i = 0; i < dataLen; i++) {
|
||||
let med8 = key1[i % 17] ^ audioData[i]
|
||||
med8 ^= (med8 & 0xf) << 4
|
||||
|
||||
let msk8 = GetMask(i)
|
||||
msk8 ^= (msk8 & 0xf) << 4
|
||||
audioData[i] = med8 ^ msk8
|
||||
}
|
||||
if (raw_ext === "vpr") {
|
||||
for (let i = 0; i < dataLen; i++) audioData[i] ^= VprMaskDiff[i % 17]
|
||||
}
|
||||
|
||||
const ext = SniffAudioExt(audioData);
|
||||
const mime = AudioMimeType[ext];
|
||||
let musicBlob = new Blob([audioData], {type: mime});
|
||||
const musicMeta = await metaParseBlob(musicBlob);
|
||||
const {title, artist} = GetMetaFromFile(raw_filename, musicMeta.common.title, musicMeta.common.artist)
|
||||
return {
|
||||
status: true,
|
||||
album: musicMeta.common.album,
|
||||
picture: GetCoverFromFile(musicMeta),
|
||||
file: URL.createObjectURL(musicBlob),
|
||||
ext,
|
||||
mime,
|
||||
title,
|
||||
artist
|
||||
}
|
||||
}
|
||||
|
||||
function GetMask(pos) {
|
||||
return MaskV2PreDef[pos % 272] ^ MaskV2[pos >> 4]
|
||||
}
|
||||
|
||||
let MaskV2 = null;
|
||||
|
||||
async function LoadMaskV2() {
|
||||
try {
|
||||
let resp = await fetch("./static/kgm.mask", {
|
||||
method: "GET"
|
||||
})
|
||||
MaskV2 = new Uint8Array(await resp.arrayBuffer());
|
||||
return true
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
const MaskV2PreDef = [
|
||||
0xB8, 0xD5, 0x3D, 0xB2, 0xE9, 0xAF, 0x78, 0x8C, 0x83, 0x33, 0x71, 0x51, 0x76, 0xA0, 0xCD, 0x37,
|
||||
0x2F, 0x3E, 0x35, 0x8D, 0xA9, 0xBE, 0x98, 0xB7, 0xE7, 0x8C, 0x22, 0xCE, 0x5A, 0x61, 0xDF, 0x68,
|
||||
0x69, 0x89, 0xFE, 0xA5, 0xB6, 0xDE, 0xA9, 0x77, 0xFC, 0xC8, 0xBD, 0xBD, 0xE5, 0x6D, 0x3E, 0x5A,
|
||||
0x36, 0xEF, 0x69, 0x4E, 0xBE, 0xE1, 0xE9, 0x66, 0x1C, 0xF3, 0xD9, 0x02, 0xB6, 0xF2, 0x12, 0x9B,
|
||||
0x44, 0xD0, 0x6F, 0xB9, 0x35, 0x89, 0xB6, 0x46, 0x6D, 0x73, 0x82, 0x06, 0x69, 0xC1, 0xED, 0xD7,
|
||||
0x85, 0xC2, 0x30, 0xDF, 0xA2, 0x62, 0xBE, 0x79, 0x2D, 0x62, 0x62, 0x3D, 0x0D, 0x7E, 0xBE, 0x48,
|
||||
0x89, 0x23, 0x02, 0xA0, 0xE4, 0xD5, 0x75, 0x51, 0x32, 0x02, 0x53, 0xFD, 0x16, 0x3A, 0x21, 0x3B,
|
||||
0x16, 0x0F, 0xC3, 0xB2, 0xBB, 0xB3, 0xE2, 0xBA, 0x3A, 0x3D, 0x13, 0xEC, 0xF6, 0x01, 0x45, 0x84,
|
||||
0xA5, 0x70, 0x0F, 0x93, 0x49, 0x0C, 0x64, 0xCD, 0x31, 0xD5, 0xCC, 0x4C, 0x07, 0x01, 0x9E, 0x00,
|
||||
0x1A, 0x23, 0x90, 0xBF, 0x88, 0x1E, 0x3B, 0xAB, 0xA6, 0x3E, 0xC4, 0x73, 0x47, 0x10, 0x7E, 0x3B,
|
||||
0x5E, 0xBC, 0xE3, 0x00, 0x84, 0xFF, 0x09, 0xD4, 0xE0, 0x89, 0x0F, 0x5B, 0x58, 0x70, 0x4F, 0xFB,
|
||||
0x65, 0xD8, 0x5C, 0x53, 0x1B, 0xD3, 0xC8, 0xC6, 0xBF, 0xEF, 0x98, 0xB0, 0x50, 0x4F, 0x0F, 0xEA,
|
||||
0xE5, 0x83, 0x58, 0x8C, 0x28, 0x2C, 0x84, 0x67, 0xCD, 0xD0, 0x9E, 0x47, 0xDB, 0x27, 0x50, 0xCA,
|
||||
0xF4, 0x63, 0x63, 0xE8, 0x97, 0x7F, 0x1B, 0x4B, 0x0C, 0xC2, 0xC1, 0x21, 0x4C, 0xCC, 0x58, 0xF5,
|
||||
0x94, 0x52, 0xA3, 0xF3, 0xD3, 0xE0, 0x68, 0xF4, 0x00, 0x23, 0xF3, 0x5E, 0x0A, 0x7B, 0x93, 0xDD,
|
||||
0xAB, 0x12, 0xB2, 0x13, 0xE8, 0x84, 0xD7, 0xA7, 0x9F, 0x0F, 0x32, 0x4C, 0x55, 0x1D, 0x04, 0x36,
|
||||
0x52, 0xDC, 0x03, 0xF3, 0xF9, 0x4E, 0x42, 0xE9, 0x3D, 0x61, 0xEF, 0x7C, 0xB6, 0xB3, 0x93, 0x50,
|
||||
]
|
||||
|
|
@ -41,10 +41,10 @@ export async function Decrypt(file: File, raw_filename: string, _: string): Prom
|
|||
const musicMeta = await metaParseBlob(musicBlob);
|
||||
const {title, artist} = GetMetaFromFile(raw_filename, musicMeta.common.title, musicMeta.common.artist)
|
||||
return {
|
||||
status: true,
|
||||
album: musicMeta.common.album,
|
||||
picture: GetCoverFromFile(musicMeta),
|
||||
file: URL.createObjectURL(musicBlob),
|
||||
blob: musicBlob,
|
||||
mime,
|
||||
title,
|
||||
artist,
|
||||
|
|
|
@ -1,175 +0,0 @@
|
|||
import {AudioMimeType, BytesHasPrefix, GetArrayBuffer, GetMetaFromFile, SniffAudioExt} from "@/decrypt/utils.ts";
|
||||
import {parseBlob as metaParseBlob} from "music-metadata-browser";
|
||||
|
||||
const CryptoJS = require("crypto-js");
|
||||
const MetaFlac = require('metaflac-js');
|
||||
const CORE_KEY = CryptoJS.enc.Hex.parse("687a4852416d736f356b496e62617857");
|
||||
const META_KEY = CryptoJS.enc.Hex.parse("2331346C6A6B5F215C5D2630553C2728");
|
||||
const MagicHeader = [0x43, 0x54, 0x45, 0x4E, 0x46, 0x44, 0x41, 0x4D];
|
||||
|
||||
import jimp from 'jimp';
|
||||
|
||||
import {
|
||||
GetWebImage,
|
||||
WriteMp3Meta
|
||||
} from "./util"
|
||||
|
||||
export async function Decrypt(file, raw_filename, _) {
|
||||
const fileBuffer = await GetArrayBuffer(file);
|
||||
const dataView = new DataView(fileBuffer);
|
||||
|
||||
if (!BytesHasPrefix(new Uint8Array(fileBuffer, 0, 8), MagicHeader))
|
||||
return {status: false, message: "此ncm文件已损坏"};
|
||||
|
||||
const keyDataObj = getKeyData(dataView, fileBuffer, 10);
|
||||
const keyBox = getKeyBox(keyDataObj.data);
|
||||
|
||||
const musicMetaObj = getMetaData(dataView, fileBuffer, keyDataObj.offset);
|
||||
const musicMeta = musicMetaObj.data;
|
||||
let audioOffset = musicMetaObj.offset + dataView.getUint32(musicMetaObj.offset + 5, true) + 13;
|
||||
let audioData = new Uint8Array(fileBuffer, audioOffset);
|
||||
|
||||
let lenAudioData = audioData.length;
|
||||
for (let cur = 0; cur < lenAudioData; ++cur) audioData[cur] ^= keyBox[cur & 0xff];
|
||||
|
||||
if (musicMeta.album === undefined) musicMeta.album = "";
|
||||
|
||||
const artists = [];
|
||||
if (!!musicMeta.artist) musicMeta.artist.forEach(arr => artists.push(arr[0]));
|
||||
const info = GetMetaFromFile(raw_filename, musicMeta.musicName, artists.join("; "))
|
||||
if (artists.length === 0) artists.push(info.artist);
|
||||
|
||||
if (musicMeta.format === undefined) musicMeta.format = SniffAudioExt(audioData);
|
||||
|
||||
const imageInfo = await GetWebImage(musicMeta.albumPic);
|
||||
while (!!imageInfo.buffer && imageInfo.buffer.byteLength >= 16 * 1024 * 1024) {
|
||||
let img = await jimp.read(imageInfo.buffer)
|
||||
await img.resize(Math.round(img.getHeight() / 2), jimp.AUTO)
|
||||
imageInfo.buffer = await img.getBufferAsync("image/jpeg")
|
||||
}
|
||||
const mime = AudioMimeType[musicMeta.format]
|
||||
try {
|
||||
let musicBlob = new Blob([audioData], {type: mime});
|
||||
const originalMeta = await metaParseBlob(musicBlob);
|
||||
let shouldWrite = !originalMeta.common.album && !originalMeta.common.artists && !originalMeta.common.title
|
||||
if (musicMeta.format === "mp3") {
|
||||
audioData = await WriteMp3Meta(
|
||||
audioData, artists, info.title, musicMeta.album, imageInfo.buffer, musicMeta.albumPic, shouldWrite ? null : originalMeta)
|
||||
} else if (musicMeta.format === "flac") {
|
||||
const writer = new MetaFlac(Buffer.from(audioData))
|
||||
if (shouldWrite) {
|
||||
writer.setTag("TITLE=" + info.title)
|
||||
writer.setTag("ALBUM=" + musicMeta.album)
|
||||
writer.removeTag("ARTIST")
|
||||
artists.forEach(artist => writer.setTag("ARTIST=" + artist))
|
||||
}
|
||||
writer.importPictureFromBuffer(Buffer.from(imageInfo.buffer))
|
||||
audioData = writer.save()
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn("Error while appending cover image to file " + e)
|
||||
}
|
||||
|
||||
const musicData = new Blob([audioData], {type: mime})
|
||||
|
||||
return {
|
||||
status: true,
|
||||
title: info.title,
|
||||
artist: info.artist,
|
||||
ext: musicMeta.format,
|
||||
album: musicMeta.album,
|
||||
picture: imageInfo.url,
|
||||
file: URL.createObjectURL(musicData),
|
||||
mime: mime
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function getKeyData(dataView, fileBuffer, offset) {
|
||||
const keyLen = dataView.getUint32(offset, true);
|
||||
offset += 4;
|
||||
const cipherText = new Uint8Array(fileBuffer, offset, keyLen).map(
|
||||
uint8 => uint8 ^ 0x64
|
||||
);
|
||||
offset += keyLen;
|
||||
|
||||
const plainText = CryptoJS.AES.decrypt(
|
||||
{ciphertext: CryptoJS.lib.WordArray.create(cipherText)},
|
||||
CORE_KEY,
|
||||
{
|
||||
mode: CryptoJS.mode.ECB,
|
||||
padding: CryptoJS.pad.Pkcs7
|
||||
}
|
||||
);
|
||||
|
||||
const result = new Uint8Array(plainText.sigBytes);
|
||||
|
||||
const words = plainText.words;
|
||||
const sigBytes = plainText.sigBytes;
|
||||
for (let i = 0; i < sigBytes; i++) {
|
||||
result[i] = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
|
||||
}
|
||||
|
||||
return {offset: offset, data: result.slice(17)};
|
||||
}
|
||||
|
||||
function getKeyBox(keyData) {
|
||||
const box = new Uint8Array(Array(256).keys());
|
||||
|
||||
const keyDataLen = keyData.length;
|
||||
|
||||
let j = 0;
|
||||
|
||||
for (let i = 0; i < 256; i++) {
|
||||
j = (box[i] + j + keyData[i % keyDataLen]) & 0xff;
|
||||
[box[i], box[j]] = [box[j], box[i]];
|
||||
}
|
||||
|
||||
return box.map((_, i, arr) => {
|
||||
i = (i + 1) & 0xff;
|
||||
const si = arr[i];
|
||||
const sj = arr[(i + si) & 0xff];
|
||||
return arr[(si + sj) & 0xff];
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @typedef {Object} MusicMetaType
|
||||
* @property {Number} musicId
|
||||
* @property {String} musicName
|
||||
* @property {[[String, Number]]} artist
|
||||
* @property {String} album
|
||||
* @property {"flac"|"mp3"} format
|
||||
* @property {String} albumPic
|
||||
*/
|
||||
|
||||
function getMetaData(dataView, fileBuffer, offset) {
|
||||
const metaDataLen = dataView.getUint32(offset, true);
|
||||
offset += 4;
|
||||
if (metaDataLen === 0) return {data: {}, offset: offset};
|
||||
|
||||
const cipherText = new Uint8Array(fileBuffer, offset, metaDataLen).map(
|
||||
data => data ^ 0x63
|
||||
);
|
||||
offset += metaDataLen;
|
||||
|
||||
const plainText = CryptoJS.AES.decrypt({
|
||||
ciphertext: CryptoJS.enc.Base64.parse(
|
||||
CryptoJS.lib.WordArray.create(cipherText.slice(22)).toString(CryptoJS.enc.Utf8)
|
||||
)
|
||||
},
|
||||
META_KEY,
|
||||
{mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7}
|
||||
).toString(CryptoJS.enc.Utf8);
|
||||
const labelIndex = plainText.indexOf(":");
|
||||
let result = JSON.parse(plainText.slice(labelIndex + 1));
|
||||
if (plainText.slice(0, labelIndex) === "dj") {
|
||||
result = result.mainMusic;
|
||||
}
|
||||
if (!!result.albumPic && result.albumPic !== "")
|
||||
result.albumPic = result.albumPic.replace("http://", "https://") + "?param=500y500";
|
||||
|
||||
return {data: result, offset: offset};
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,235 @@
|
|||
import {
|
||||
AudioMimeType,
|
||||
BytesHasPrefix,
|
||||
GetArrayBuffer,
|
||||
GetImageFromURL,
|
||||
GetMetaFromFile, IMusicMeta,
|
||||
SniffAudioExt,
|
||||
WriteMetaToFlac,
|
||||
WriteMetaToMp3
|
||||
} from "@/decrypt/utils.ts";
|
||||
import {parseBlob as metaParseBlob} from "music-metadata-browser";
|
||||
import jimp from 'jimp';
|
||||
|
||||
import CryptoJS from "crypto-js";
|
||||
import {DecryptResult} from "@/decrypt/entity";
|
||||
|
||||
const CORE_KEY = CryptoJS.enc.Hex.parse("687a4852416d736f356b496e62617857");
|
||||
const META_KEY = CryptoJS.enc.Hex.parse("2331346C6A6B5F215C5D2630553C2728");
|
||||
const MagicHeader = [0x43, 0x54, 0x45, 0x4E, 0x46, 0x44, 0x41, 0x4D];
|
||||
|
||||
|
||||
export async function Decrypt(file: File, raw_filename: string, _: string): Promise<DecryptResult> {
|
||||
return (new NcmDecrypt(await GetArrayBuffer(file), raw_filename)).decrypt()
|
||||
}
|
||||
|
||||
|
||||
interface NcmMusicMeta {
|
||||
//musicId: number
|
||||
musicName?: string
|
||||
artist?: Array<string | number>[]
|
||||
format?: string
|
||||
album?: string
|
||||
albumPic?: string
|
||||
}
|
||||
|
||||
interface NcmDjMeta {
|
||||
mainMusic: NcmMusicMeta
|
||||
}
|
||||
|
||||
|
||||
class NcmDecrypt {
|
||||
raw: ArrayBuffer
|
||||
view: DataView
|
||||
offset: number = 0
|
||||
filename: string
|
||||
format: string = ""
|
||||
mime: string = ""
|
||||
audio?: Uint8Array
|
||||
blob?: Blob
|
||||
oriMeta?: NcmMusicMeta
|
||||
newMeta?: IMusicMeta
|
||||
image?: { mime: string, buffer: ArrayBuffer, url: string }
|
||||
|
||||
constructor(buf: ArrayBuffer, filename: string) {
|
||||
const prefix = new Uint8Array(buf, 0, 8)
|
||||
if (!BytesHasPrefix(prefix, MagicHeader)) throw Error("此ncm文件已损坏")
|
||||
this.offset = 10
|
||||
this.raw = buf
|
||||
this.view = new DataView(buf)
|
||||
this.filename = filename
|
||||
}
|
||||
|
||||
_getKeyData(): Uint8Array {
|
||||
const keyLen = this.view.getUint32(this.offset, true);
|
||||
this.offset += 4;
|
||||
const cipherText = new Uint8Array(this.raw, this.offset, keyLen)
|
||||
.map(uint8 => uint8 ^ 0x64);
|
||||
this.offset += keyLen;
|
||||
|
||||
const plainText = CryptoJS.AES.decrypt(
|
||||
// @ts-ignore
|
||||
{ciphertext: CryptoJS.lib.WordArray.create(cipherText)},
|
||||
CORE_KEY,
|
||||
{mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7}
|
||||
);
|
||||
|
||||
const result = new Uint8Array(plainText.sigBytes);
|
||||
|
||||
const words = plainText.words;
|
||||
const sigBytes = plainText.sigBytes;
|
||||
for (let i = 0; i < sigBytes; i++) {
|
||||
result[i] = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
|
||||
}
|
||||
|
||||
return result.slice(17)
|
||||
}
|
||||
|
||||
_getKeyBox(): Uint8Array {
|
||||
const keyData = this._getKeyData()
|
||||
const box = new Uint8Array(Array(256).keys());
|
||||
|
||||
const keyDataLen = keyData.length;
|
||||
|
||||
let j = 0;
|
||||
|
||||
for (let i = 0; i < 256; i++) {
|
||||
j = (box[i] + j + keyData[i % keyDataLen]) & 0xff;
|
||||
[box[i], box[j]] = [box[j], box[i]];
|
||||
}
|
||||
|
||||
return box.map((_, i, arr) => {
|
||||
i = (i + 1) & 0xff;
|
||||
const si = arr[i];
|
||||
const sj = arr[(i + si) & 0xff];
|
||||
return arr[(si + sj) & 0xff];
|
||||
});
|
||||
}
|
||||
|
||||
_getMetaData(): NcmMusicMeta {
|
||||
const metaDataLen = this.view.getUint32(this.offset, true);
|
||||
this.offset += 4;
|
||||
if (metaDataLen === 0) return {};
|
||||
|
||||
const cipherText = new Uint8Array(this.raw, this.offset, metaDataLen)
|
||||
.map(data => data ^ 0x63);
|
||||
this.offset += metaDataLen;
|
||||
|
||||
const plainText = CryptoJS.AES.decrypt(
|
||||
//@ts-ignore
|
||||
{
|
||||
ciphertext: CryptoJS.enc.Base64.parse(
|
||||
//@ts-ignore
|
||||
CryptoJS.lib.WordArray.create(cipherText.slice(22)).toString(CryptoJS.enc.Utf8)
|
||||
)
|
||||
},
|
||||
META_KEY,
|
||||
{mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7}
|
||||
).toString(CryptoJS.enc.Utf8);
|
||||
|
||||
const labelIndex = plainText.indexOf(":");
|
||||
let result: NcmMusicMeta;
|
||||
if (plainText.slice(0, labelIndex) === "dj") {
|
||||
const tmp: NcmDjMeta = JSON.parse(plainText.slice(labelIndex + 1));
|
||||
result = tmp.mainMusic;
|
||||
} else {
|
||||
result = JSON.parse(plainText.slice(labelIndex + 1));
|
||||
}
|
||||
if (!!result.albumPic) {
|
||||
result.albumPic = result.albumPic.replace("http://", "https://") + "?param=500y500"
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
_getAudio(keyBox: Uint8Array): Uint8Array {
|
||||
this.offset += this.view.getUint32(this.offset + 5, true) + 13
|
||||
const audioData = new Uint8Array(this.raw, this.offset)
|
||||
let lenAudioData = audioData.length
|
||||
for (let cur = 0; cur < lenAudioData; ++cur) audioData[cur] ^= keyBox[cur & 0xff]
|
||||
return audioData
|
||||
}
|
||||
|
||||
async _buildMeta() {
|
||||
if (!this.oriMeta) throw Error("invalid sequence")
|
||||
|
||||
const info = GetMetaFromFile(this.filename, this.oriMeta.musicName)
|
||||
|
||||
// build artists
|
||||
let artists: string[] = [];
|
||||
if (!!this.oriMeta.artist) {
|
||||
this.oriMeta.artist.forEach(arr => artists.push(<string>arr[0]));
|
||||
}
|
||||
|
||||
if (artists.length === 0 && !!info.artist) {
|
||||
artists = info.artist.split(',')
|
||||
.map(val => val.trim()).filter(val => val != "");
|
||||
}
|
||||
|
||||
if (this.oriMeta.albumPic) try {
|
||||
this.image = await GetImageFromURL(this.oriMeta.albumPic)
|
||||
while (this.image && this.image.buffer.byteLength >= 1 << 24) {
|
||||
let img = await jimp.read(Buffer.from(this.image.buffer))
|
||||
await img.resize(Math.round(img.getHeight() / 2), jimp.AUTO)
|
||||
this.image.buffer = await img.getBufferAsync("image/jpeg")
|
||||
}
|
||||
} catch (e) {
|
||||
console.log("get cover image failed", e)
|
||||
}
|
||||
|
||||
|
||||
this.newMeta = {title: info.title, artists, album: this.oriMeta.album, picture: this.image?.buffer}
|
||||
}
|
||||
|
||||
async _writeMeta() {
|
||||
if (!this.audio || !this.newMeta) throw Error("invalid sequence")
|
||||
|
||||
if (!this.blob) this.blob = new Blob([this.audio], {type: this.mime})
|
||||
const ori = await metaParseBlob(this.blob);
|
||||
|
||||
let shouldWrite = !ori.common.album && !ori.common.artists && !ori.common.title
|
||||
if (shouldWrite || this.newMeta.picture) {
|
||||
if (this.format === "mp3") {
|
||||
this.audio = WriteMetaToMp3(Buffer.from(this.audio), this.newMeta, ori)
|
||||
} else if (this.format === "flac") {
|
||||
this.audio = WriteMetaToFlac(Buffer.from(this.audio), this.newMeta, ori)
|
||||
} else {
|
||||
console.info(`writing meta for ${this.format} is not being supported for now`)
|
||||
return
|
||||
}
|
||||
this.blob = new Blob([this.audio], {type: this.mime})
|
||||
}
|
||||
}
|
||||
|
||||
gatherResult(): DecryptResult {
|
||||
if (!this.newMeta) throw Error("bad sequence")
|
||||
return {
|
||||
title: this.newMeta.title,
|
||||
artist: this.newMeta.artists?.join("; "),
|
||||
ext: this.format,
|
||||
album: this.newMeta.album,
|
||||
picture: this.image?.url,
|
||||
file: URL.createObjectURL(this.blob),
|
||||
blob: this.blob as Blob,
|
||||
mime: this.mime
|
||||
}
|
||||
}
|
||||
|
||||
async decrypt() {
|
||||
const keyBox = this._getKeyBox()
|
||||
this.oriMeta = this._getMetaData()
|
||||
this.audio = this._getAudio(keyBox)
|
||||
this.format = this.oriMeta.format || SniffAudioExt(this.audio)
|
||||
this.mime = AudioMimeType[this.format]
|
||||
await this._buildMeta()
|
||||
try {
|
||||
await this._writeMeta()
|
||||
} catch (e) {
|
||||
console.warn("write meta data failed", e)
|
||||
}
|
||||
return this.gatherResult()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -1,156 +0,0 @@
|
|||
import {
|
||||
GetWebImage,
|
||||
IXAREA_API_ENDPOINT,
|
||||
WriteMp3Meta
|
||||
} from "./util";
|
||||
import {QmcMaskCreate58, QmcMaskDetectMflac, QmcMaskDetectMgg, QmcMaskGetDefault} from "./qmcMask";
|
||||
import {fromByteArray as Base64Encode, toByteArray as Base64Decode} from 'base64-js'
|
||||
import {AudioMimeType, GetArrayBuffer, GetCoverFromFile, GetMetaFromFile, SniffAudioExt} from "@/decrypt/utils.ts";
|
||||
import {parseBlob as metaParseBlob} from "music-metadata-browser";
|
||||
|
||||
const MetaFlac = require('metaflac-js');
|
||||
|
||||
|
||||
const iconv = require('iconv-lite');
|
||||
const decode = iconv.decode
|
||||
|
||||
const HandlerMap = {
|
||||
"mgg": {handler: QmcMaskDetectMgg, ext: "ogg", detect: true},
|
||||
"mflac": {handler: QmcMaskDetectMflac, ext: "flac", detect: true},
|
||||
"qmc0": {handler: QmcMaskGetDefault, ext: "mp3", detect: false},
|
||||
"qmc2": {handler: QmcMaskGetDefault, ext: "ogg", detect: false},
|
||||
"qmc3": {handler: QmcMaskGetDefault, ext: "mp3", detect: false},
|
||||
"qmcogg": {handler: QmcMaskGetDefault, ext: "ogg", detect: false},
|
||||
"qmcflac": {handler: QmcMaskGetDefault, ext: "flac", detect: false},
|
||||
"bkcmp3": {handler: QmcMaskGetDefault, ext: "mp3", detect: false},
|
||||
"bkcflac": {handler: QmcMaskGetDefault, ext: "flac", detect: false},
|
||||
"tkm": {handler: QmcMaskGetDefault, ext: "m4a", detect: false},
|
||||
"666c6163": {handler: QmcMaskGetDefault, ext: "flac", detect: false},
|
||||
"6d7033": {handler: QmcMaskGetDefault, ext: "mp3", detect: false},
|
||||
"6f6767": {handler: QmcMaskGetDefault, ext: "ogg", detect: false},
|
||||
"6d3461": {handler: QmcMaskGetDefault, ext: "m4a", detect: false},
|
||||
"776176": {handler: QmcMaskGetDefault, ext: "wav", detect: false}
|
||||
};
|
||||
|
||||
export async function Decrypt(file, raw_filename, raw_ext) {
|
||||
if (!(raw_ext in HandlerMap)) return {status: false, message: "File type is incorrect!"};
|
||||
const handler = HandlerMap[raw_ext];
|
||||
|
||||
const fileData = new Uint8Array(await GetArrayBuffer(file));
|
||||
let audioData, seed, keyData;
|
||||
if (handler.detect) {
|
||||
const keyLen = new DataView(fileData.slice(fileData.length - 4).buffer).getUint32(0, true)
|
||||
const keyPos = fileData.length - 4 - keyLen;
|
||||
audioData = fileData.slice(0, keyPos);
|
||||
seed = handler.handler(audioData);
|
||||
keyData = fileData.slice(keyPos, keyPos + keyLen);
|
||||
if (seed === undefined) seed = await queryKeyInfo(keyData, raw_filename, raw_ext);
|
||||
if (seed === undefined) return {status: false, message: raw_ext + "格式仅提供实验性支持"};
|
||||
} else {
|
||||
audioData = fileData;
|
||||
seed = handler.handler(audioData);
|
||||
}
|
||||
let musicDecoded = seed.Decrypt(audioData);
|
||||
|
||||
const ext = SniffAudioExt(musicDecoded, handler.ext);
|
||||
const mime = AudioMimeType[ext];
|
||||
|
||||
let musicBlob = new Blob([musicDecoded], {type: mime});
|
||||
|
||||
const musicMeta = await metaParseBlob(musicBlob);
|
||||
for (let metaIdx in musicMeta.native) {
|
||||
if (musicMeta.native[metaIdx].some(item => item.id === "TCON" && item.value === "(12)")) {
|
||||
console.warn("The metadata is using gbk encoding")
|
||||
musicMeta.common.artist = decode(musicMeta.common.artist, "gbk");
|
||||
musicMeta.common.title = decode(musicMeta.common.title, "gbk");
|
||||
musicMeta.common.album = decode(musicMeta.common.album, "gbk");
|
||||
}
|
||||
}
|
||||
|
||||
const info = GetMetaFromFile(raw_filename, musicMeta.common.title, musicMeta.common.artist)
|
||||
if (handler.detect) reportKeyUsage(keyData, seed.Matrix128,
|
||||
info.artist, info.title, musicMeta.common.album, raw_filename, raw_ext);
|
||||
|
||||
let imgUrl = GetCoverFromFile(musicMeta);
|
||||
if (!imgUrl) {
|
||||
imgUrl = await queryAlbumCoverImage(info.artist, info.title, musicMeta.common.album);
|
||||
if (imgUrl !== "") {
|
||||
const imageInfo = await GetWebImage(imgUrl);
|
||||
if (imageInfo.url !== "") {
|
||||
imgUrl = imageInfo.url
|
||||
try {
|
||||
if (ext === "mp3") {
|
||||
musicDecoded = await WriteMp3Meta(musicDecoded,
|
||||
info.artist.split(" _ "), info.title, "",
|
||||
imageInfo.buffer, "Cover", musicMeta)
|
||||
musicBlob = new Blob([musicDecoded], {type: mime});
|
||||
} else if (ext === 'flac') {
|
||||
const writer = new MetaFlac(Buffer.from(musicDecoded))
|
||||
writer.importPictureFromBuffer(Buffer.from(imageInfo.buffer))
|
||||
musicDecoded = writer.save()
|
||||
musicBlob = new Blob([musicDecoded], {type: mime});
|
||||
} else {
|
||||
console.info("writing metadata for " + ext + " is not being supported for now")
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn("Error while appending cover image to file " + e)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
status: true,
|
||||
title: info.title,
|
||||
artist: info.artist,
|
||||
ext: ext,
|
||||
album: musicMeta.common.album,
|
||||
picture: imgUrl,
|
||||
file: URL.createObjectURL(musicBlob),
|
||||
mime: mime
|
||||
}
|
||||
}
|
||||
|
||||
function reportKeyUsage(keyData, maskData, artist, title, album, filename, format) {
|
||||
fetch(IXAREA_API_ENDPOINT + "/qmcmask/usage", {
|
||||
method: "POST",
|
||||
headers: {"Content-Type": "application/json"},
|
||||
body: JSON.stringify({
|
||||
Mask: Base64Encode(new Uint8Array(maskData)), Key: Base64Encode(keyData),
|
||||
Artist: artist, Title: title, Album: album, Filename: filename, Format: format
|
||||
}),
|
||||
}).then().catch()
|
||||
}
|
||||
|
||||
async function queryKeyInfo(keyData, filename, format) {
|
||||
try {
|
||||
const resp = await fetch(IXAREA_API_ENDPOINT + "/qmcmask/query", {
|
||||
method: "POST",
|
||||
headers: {"Content-Type": "application/json"},
|
||||
body: JSON.stringify({Format: format, Key: Base64Encode(keyData), Filename: filename, Type: 44}),
|
||||
});
|
||||
let data = await resp.json();
|
||||
return QmcMaskCreate58(Base64Decode(data.Matrix44));
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
async function queryAlbumCoverImage(artist, title, album) {
|
||||
const song_query_url = IXAREA_API_ENDPOINT + "/music/qq-cover"
|
||||
try {
|
||||
const params = {Artist: artist, Title: title, Album: album};
|
||||
let _url = song_query_url + "?";
|
||||
for (let pKey in params) {
|
||||
_url += pKey + "=" + encodeURIComponent(params[pKey]) + "&"
|
||||
}
|
||||
const resp = await fetch(_url)
|
||||
if (resp.ok) {
|
||||
let data = await resp.json();
|
||||
return song_query_url + "/" + data.Type + "/" + data.Id
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
return "";
|
||||
}
|
|
@ -0,0 +1,138 @@
|
|||
import {QmcMask, QmcMaskDetectMflac, QmcMaskDetectMgg, QmcMaskGetDefault} from "./qmcMask";
|
||||
import {toByteArray as Base64Decode} from 'base64-js'
|
||||
import {
|
||||
AudioMimeType,
|
||||
GetArrayBuffer,
|
||||
GetCoverFromFile,
|
||||
GetImageFromURL,
|
||||
GetMetaFromFile,
|
||||
SniffAudioExt, WriteMetaToFlac, WriteMetaToMp3
|
||||
} from "@/decrypt/utils.ts";
|
||||
import {parseBlob as metaParseBlob} from "music-metadata-browser";
|
||||
|
||||
|
||||
import iconv from "iconv-lite";
|
||||
import {DecryptResult} from "@/decrypt/entity";
|
||||
import {queryAlbumCover, queryKeyInfo, reportKeyUsage} from "@/utils/api";
|
||||
|
||||
interface Handler {
|
||||
ext: string
|
||||
detect: boolean
|
||||
|
||||
handler(data?: Uint8Array): QmcMask | undefined
|
||||
}
|
||||
|
||||
const HandlerMap: { [key: string]: Handler } = {
|
||||
"mgg": {handler: QmcMaskDetectMgg, ext: "ogg", detect: true},
|
||||
"mflac": {handler: QmcMaskDetectMflac, ext: "flac", detect: true},
|
||||
"qmc0": {handler: QmcMaskGetDefault, ext: "mp3", detect: false},
|
||||
"qmc2": {handler: QmcMaskGetDefault, ext: "ogg", detect: false},
|
||||
"qmc3": {handler: QmcMaskGetDefault, ext: "mp3", detect: false},
|
||||
"qmcogg": {handler: QmcMaskGetDefault, ext: "ogg", detect: false},
|
||||
"qmcflac": {handler: QmcMaskGetDefault, ext: "flac", detect: false},
|
||||
"bkcmp3": {handler: QmcMaskGetDefault, ext: "mp3", detect: false},
|
||||
"bkcflac": {handler: QmcMaskGetDefault, ext: "flac", detect: false},
|
||||
"tkm": {handler: QmcMaskGetDefault, ext: "m4a", detect: false},
|
||||
"666c6163": {handler: QmcMaskGetDefault, ext: "flac", detect: false},
|
||||
"6d7033": {handler: QmcMaskGetDefault, ext: "mp3", detect: false},
|
||||
"6f6767": {handler: QmcMaskGetDefault, ext: "ogg", detect: false},
|
||||
"6d3461": {handler: QmcMaskGetDefault, ext: "m4a", detect: false},
|
||||
"776176": {handler: QmcMaskGetDefault, ext: "wav", detect: false}
|
||||
};
|
||||
|
||||
export async function Decrypt(file: File, raw_filename: string, raw_ext: string): Promise<DecryptResult> {
|
||||
if (!(raw_ext in HandlerMap)) throw "File type is incorrect!";
|
||||
const handler = HandlerMap[raw_ext];
|
||||
|
||||
const fileData = new Uint8Array(await GetArrayBuffer(file));
|
||||
let audioData, seed, keyData;
|
||||
if (handler.detect) {
|
||||
const keyLen = new DataView(fileData.slice(fileData.length - 4).buffer).getUint32(0, true)
|
||||
const keyPos = fileData.length - 4 - keyLen;
|
||||
audioData = fileData.slice(0, keyPos);
|
||||
seed = handler.handler(audioData);
|
||||
keyData = fileData.slice(keyPos, keyPos + keyLen);
|
||||
if (!seed) seed = await queryKey(keyData, raw_filename, raw_ext);
|
||||
if (!seed) throw raw_ext + "格式仅提供实验性支持";
|
||||
} else {
|
||||
audioData = fileData;
|
||||
seed = handler.handler(audioData) as QmcMask;
|
||||
}
|
||||
let musicDecoded = seed.Decrypt(audioData);
|
||||
|
||||
const ext = SniffAudioExt(musicDecoded, handler.ext);
|
||||
const mime = AudioMimeType[ext];
|
||||
|
||||
let musicBlob = new Blob([musicDecoded], {type: mime});
|
||||
|
||||
const musicMeta = await metaParseBlob(musicBlob);
|
||||
for (let metaIdx in musicMeta.native) {
|
||||
if (!musicMeta.native.hasOwnProperty(metaIdx)) continue
|
||||
if (musicMeta.native[metaIdx].some(item => item.id === "TCON" && item.value === "(12)")) {
|
||||
console.warn("try using gbk encoding to decode meta")
|
||||
musicMeta.common.artist = iconv.decode(new Buffer(musicMeta.common.artist ?? ""), "gbk");
|
||||
musicMeta.common.title = iconv.decode(new Buffer(musicMeta.common.title ?? ""), "gbk");
|
||||
musicMeta.common.album = iconv.decode(new Buffer(musicMeta.common.album ?? ""), "gbk");
|
||||
}
|
||||
}
|
||||
|
||||
const info = GetMetaFromFile(raw_filename, musicMeta.common.title, musicMeta.common.artist)
|
||||
if (keyData) reportKeyUsage(keyData, seed.getMatrix128(),
|
||||
raw_filename, raw_ext, info.title, info.artist, musicMeta.common.album).then().catch();
|
||||
|
||||
let imgUrl = GetCoverFromFile(musicMeta);
|
||||
if (!imgUrl) {
|
||||
imgUrl = await getCoverImage(info.title, info.artist, musicMeta.common.album);
|
||||
if (imgUrl) {
|
||||
const imageInfo = await GetImageFromURL(imgUrl);
|
||||
if (imageInfo) {
|
||||
imgUrl = imageInfo.url
|
||||
try {
|
||||
const newMeta = {picture: imageInfo.buffer, title: info.title, artists: info.artist?.split(" _ ")}
|
||||
if (ext === "mp3") {
|
||||
musicDecoded = WriteMetaToMp3(Buffer.from(musicDecoded), newMeta, musicMeta)
|
||||
musicBlob = new Blob([musicDecoded], {type: mime});
|
||||
} else if (ext === 'flac') {
|
||||
musicDecoded = WriteMetaToFlac(Buffer.from(musicDecoded), newMeta, musicMeta)
|
||||
musicBlob = new Blob([musicDecoded], {type: mime});
|
||||
} else {
|
||||
console.info("writing metadata for " + ext + " is not being supported for now")
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn("Error while appending cover image to file " + e)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
title: info.title,
|
||||
artist: info.artist,
|
||||
ext: ext,
|
||||
album: musicMeta.common.album,
|
||||
picture: imgUrl,
|
||||
file: URL.createObjectURL(musicBlob),
|
||||
blob: musicBlob,
|
||||
mime: mime
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function queryKey(keyData: Uint8Array, filename: string, format: string): Promise<QmcMask | undefined> {
|
||||
try {
|
||||
const data = await queryKeyInfo(keyData, filename, format)
|
||||
return new QmcMask(Base64Decode(data.Matrix44));
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
}
|
||||
}
|
||||
|
||||
async function getCoverImage(title: string, artist?: string, album?: string): Promise<string> {
|
||||
const song_query_url = "https://stats.ixarea.com/apis" + "/music/qq-cover"
|
||||
try {
|
||||
const data = await queryAlbumCover(title, artist, album)
|
||||
return `${song_query_url}/${data.Type}/${data.Id}`
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
}
|
||||
return ""
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
import {BytesEquals, BytesHasPrefix, FLAC_HEADER, OGG_HEADER} from "@/decrypt/utils.ts";
|
||||
import {BytesHasPrefix, FLAC_HEADER, OGG_HEADER} from "@/decrypt/utils.ts";
|
||||
|
||||
const QMOggPublicHeader1 = [
|
||||
0x4f, 0x67, 0x67, 0x53, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff,
|
||||
|
@ -35,96 +35,65 @@ const QMCDefaultMaskMatrix = [
|
|||
0xf9, 0xbc, 0x00, 0x11];
|
||||
|
||||
|
||||
class QmcMask {
|
||||
constructor(matrix, superA, superB) {
|
||||
if (superA === undefined || superB === undefined) {
|
||||
if (matrix.length === 44) {
|
||||
this.Matrix44 = matrix
|
||||
this.generateMask128from44()
|
||||
} else {
|
||||
this.Matrix128 = matrix
|
||||
this.generateMask44from128()
|
||||
}
|
||||
this.generateMask58from128()
|
||||
const AllMapping: number[][] = [];
|
||||
const Mask128to44: number[] = [];
|
||||
|
||||
(function () {
|
||||
for (let i = 0; i < 128; i++) {
|
||||
let realIdx = (i * i + 27) % 256
|
||||
if (realIdx in AllMapping) {
|
||||
AllMapping[realIdx].push(i)
|
||||
} else {
|
||||
this.Matrix58 = matrix;
|
||||
this.Super58A = superA;
|
||||
this.Super58B = superB;
|
||||
this.generateMask128from58();
|
||||
this.generateMask44from128()
|
||||
AllMapping[realIdx] = [i]
|
||||
}
|
||||
}
|
||||
|
||||
generateMask128from58() {
|
||||
if (this.Matrix58.length !== 56) throw "incorrect mask58 matrix length";
|
||||
let idx44 = 0
|
||||
AllMapping.forEach(all128 => {
|
||||
all128.forEach(_i128 => {
|
||||
Mask128to44[_i128] = idx44
|
||||
})
|
||||
idx44++
|
||||
})
|
||||
})();
|
||||
|
||||
let matrix128 = [];
|
||||
for (let rowIdx = 0; rowIdx < 8; rowIdx += 1) {
|
||||
matrix128 = matrix128.concat(
|
||||
[this.Super58A],
|
||||
this.Matrix58.slice(7 * rowIdx, 7 * rowIdx + 7),
|
||||
[this.Super58B],
|
||||
this.Matrix58.slice(56 - 7 - 7 * rowIdx, 56 - 7 * rowIdx).reverse()
|
||||
);
|
||||
|
||||
export class QmcMask {
|
||||
private readonly Matrix128: number[];
|
||||
|
||||
constructor(matrix: number[] | Uint8Array) {
|
||||
if (matrix instanceof Uint8Array) matrix = Array.from(matrix)
|
||||
if (matrix.length === 44) {
|
||||
this.Matrix128 = this._generate128(matrix)
|
||||
} else if (matrix.length === 128) {
|
||||
this.Matrix128 = matrix
|
||||
} else {
|
||||
throw Error("invalid mask length")
|
||||
}
|
||||
this.Matrix128 = matrix128;
|
||||
}
|
||||
|
||||
generateMask58from128() {
|
||||
if (this.Matrix128.length !== 128) throw "incorrect mask128 length";
|
||||
|
||||
const superA = this.Matrix128[0], superB = this.Matrix128[8];
|
||||
let matrix58 = [];
|
||||
|
||||
for (let rowIdx = 0; rowIdx < 8; rowIdx += 1) {
|
||||
let lenStart = 16 * rowIdx;
|
||||
let lenRightStart = 120 - lenStart;
|
||||
if (this.Matrix128[lenStart] !== superA || this.Matrix128[lenStart + 8] !== superB) {
|
||||
throw "decode mask-128 to mask-58 failed"
|
||||
}
|
||||
let rowLeft = this.Matrix128.slice(lenStart + 1, lenStart + 8);
|
||||
let rowRight = this.Matrix128.slice(lenRightStart + 1, lenRightStart + 8).reverse();
|
||||
if (BytesEquals(rowLeft, rowRight)) {
|
||||
matrix58 = matrix58.concat(rowLeft);
|
||||
} else {
|
||||
throw "decode mask-128 to mask-58 failed"
|
||||
}
|
||||
}
|
||||
this.Matrix58 = matrix58;
|
||||
this.Super58A = superA;
|
||||
this.Super58B = superB;
|
||||
getMatrix128() {
|
||||
return this.Matrix128
|
||||
}
|
||||
|
||||
generateMask44from128() {
|
||||
if (this.Matrix128.length !== 128) throw "incorrect mask128 matrix length";
|
||||
let mapping = GetConvertMapping()
|
||||
this.Matrix44 = []
|
||||
getMatrix44(): number[] {
|
||||
const matrix44: number[] = []
|
||||
let idxI44 = 0
|
||||
mapping.forEach(it256 => {
|
||||
AllMapping.forEach(it256 => {
|
||||
let it256Len = it256.length
|
||||
for (let i = 1; i < it256Len; i++) {
|
||||
if (this.Matrix128[it256[0]] !== this.Matrix128[it256[i]]) {
|
||||
throw "decode mask-128 to mask-44 failed"
|
||||
}
|
||||
}
|
||||
this.Matrix44[idxI44] = this.Matrix128[it256[0]]
|
||||
matrix44[idxI44] = this.Matrix128[it256[0]]
|
||||
idxI44++
|
||||
})
|
||||
return matrix44
|
||||
}
|
||||
|
||||
generateMask128from44() {
|
||||
if (this.Matrix44.length !== 44) throw "incorrect mask length"
|
||||
this.Matrix128 = []
|
||||
let idx44 = 0
|
||||
GetConvertMapping().forEach(it256 => {
|
||||
it256.forEach(m => {
|
||||
this.Matrix128[m] = this.Matrix44[idx44]
|
||||
})
|
||||
idx44++
|
||||
})
|
||||
}
|
||||
|
||||
Decrypt(data) {
|
||||
Decrypt(data: Uint8Array) {
|
||||
if (!this.Matrix128) throw Error("bad call sequence")
|
||||
let dst = data.slice(0);
|
||||
let index = -1;
|
||||
let maskIdx = -1;
|
||||
|
@ -140,13 +109,25 @@ class QmcMask {
|
|||
}
|
||||
return dst;
|
||||
}
|
||||
|
||||
private _generate128(matrix44: number[]): number[] {
|
||||
const matrix128: number[] = []
|
||||
let idx44 = 0
|
||||
AllMapping.forEach(it256 => {
|
||||
it256.forEach(m => {
|
||||
matrix128[m] = matrix44[idx44]
|
||||
})
|
||||
idx44++
|
||||
})
|
||||
return matrix128
|
||||
}
|
||||
}
|
||||
|
||||
export function QmcMaskGetDefault() {
|
||||
return new QmcMask(QMCDefaultMaskMatrix)
|
||||
}
|
||||
|
||||
export function QmcMaskDetectMflac(data) {
|
||||
export function QmcMaskDetectMflac(data: Uint8Array) {
|
||||
let search_len = Math.min(0x8000, data.length), mask;
|
||||
for (let block_idx = 0; block_idx < search_len; block_idx += 128) {
|
||||
try {
|
||||
|
@ -160,9 +141,9 @@ export function QmcMaskDetectMflac(data) {
|
|||
return mask;
|
||||
}
|
||||
|
||||
export function QmcMaskDetectMgg(data) {
|
||||
export function QmcMaskDetectMgg(data: Uint8Array) {
|
||||
if (data.length < 0x100) return
|
||||
let matrixConfidence = {};
|
||||
let matrixConfidence: { [key: number]: { [key: number]: number } } = {};
|
||||
for (let i = 0; i < 44; i++) matrixConfidence[i] = {};
|
||||
|
||||
const page2 = data[0x54] ^ data[0xC] ^ QMOggPublicHeader1[0xC];
|
||||
|
@ -171,7 +152,7 @@ export function QmcMaskDetectMgg(data) {
|
|||
|
||||
for (let idx128 = 0; idx128 < spHeader.length; idx128++) {
|
||||
if (spConf[idx128] === 0) continue;
|
||||
let idx44 = GetMask44Index(idx128);
|
||||
let idx44 = Mask128to44[idx128 % 128];
|
||||
let _m = data[idx128] ^ spHeader[idx128]
|
||||
let confidence = spConf[idx128];
|
||||
if (_m in matrixConfidence[idx44]) {
|
||||
|
@ -183,7 +164,7 @@ export function QmcMaskDetectMgg(data) {
|
|||
let matrix = [];
|
||||
try {
|
||||
for (let i = 0; i < 44; i++)
|
||||
matrix[i] = getMaskConfidenceResult(matrixConfidence[i]);
|
||||
matrix[i] = calcMaskFromConfidence(matrixConfidence[i]);
|
||||
} catch (e) {
|
||||
return;
|
||||
}
|
||||
|
@ -191,82 +172,33 @@ export function QmcMaskDetectMgg(data) {
|
|||
if (!BytesHasPrefix(mask.Decrypt(data.slice(0, OGG_HEADER.length)), OGG_HEADER)) {
|
||||
return;
|
||||
}
|
||||
|
||||
return mask;
|
||||
}
|
||||
|
||||
export function QmcMaskCreate128(mask128) {
|
||||
return new QmcMask(mask128)
|
||||
}
|
||||
|
||||
export function QmcMaskCreate58(matrix, superA, superB) {
|
||||
return new QmcMask(matrix, superA, superB)
|
||||
}
|
||||
|
||||
export function QmcMaskCreate44(mask44) {
|
||||
return new QmcMask(mask44)
|
||||
}
|
||||
|
||||
/**
|
||||
* @param confidence {{}}
|
||||
* @returns {number}
|
||||
*/
|
||||
function getMaskConfidenceResult(confidence) {
|
||||
if (confidence.length === 0) throw "can not match at least one key";
|
||||
if (confidence.length > 1) console.warn("There are 2 potential value for the mask!")
|
||||
let result, conf = 0;
|
||||
function calcMaskFromConfidence(confidence: { [key: number]: number }) {
|
||||
const count = Object.keys(confidence).length
|
||||
if (count === 0) throw "can not match at least one key";
|
||||
if (count > 1) console.warn("There are 2 potential value for the mask!")
|
||||
let result = ""
|
||||
let conf = 0
|
||||
for (let idx in confidence) {
|
||||
if (confidence[idx] > conf) {
|
||||
result = idx;
|
||||
conf = confidence[idx];
|
||||
}
|
||||
}
|
||||
return parseInt(result)
|
||||
return Number(result)
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {number}
|
||||
*/
|
||||
|
||||
|
||||
const allMapping = [];
|
||||
const mask128to44 = [];
|
||||
|
||||
(function () {
|
||||
for (let i = 0; i < 128; i++) {
|
||||
let realIdx = (i * i + 27) % 256
|
||||
if (realIdx in allMapping) {
|
||||
allMapping[realIdx].push(i)
|
||||
} else {
|
||||
allMapping[realIdx] = [i]
|
||||
}
|
||||
}
|
||||
|
||||
let idx44 = 0
|
||||
allMapping.forEach(all128 => {
|
||||
all128.forEach(_i128 => {
|
||||
mask128to44[_i128] = idx44
|
||||
})
|
||||
idx44++
|
||||
})
|
||||
})();
|
||||
|
||||
function GetConvertMapping() {
|
||||
return allMapping;
|
||||
}
|
||||
|
||||
function GetMask44Index(idx128) {
|
||||
return mask128to44[idx128 % 128]
|
||||
}
|
||||
|
||||
function QmcGenerateOggHeader(page2) {
|
||||
function QmcGenerateOggHeader(page2: number) {
|
||||
let spec = [page2, 0xFF]
|
||||
for (let i = 2; i < page2; i++) spec.push(0xFF)
|
||||
spec.push(0xFF)
|
||||
return QMOggPublicHeader1.concat(spec, QMOggPublicHeader2)
|
||||
}
|
||||
|
||||
function QmcGenerateOggConf(page2) {
|
||||
function QmcGenerateOggConf(page2: number) {
|
||||
let specConf = [6, 0]
|
||||
for (let i = 2; i < page2; i++) specConf.push(4)
|
||||
specConf.push(0)
|
|
@ -16,13 +16,13 @@ export async function Decrypt(file: Blob, raw_filename: string, raw_ext: string,
|
|||
const {title, artist} = GetMetaFromFile(raw_filename, tag.common.title, tag.common.artist)
|
||||
|
||||
return {
|
||||
status: true,
|
||||
title,
|
||||
artist,
|
||||
ext,
|
||||
album: tag.common.album,
|
||||
picture: GetCoverFromFile(tag),
|
||||
file: URL.createObjectURL(file),
|
||||
blob: file,
|
||||
mime: AudioMimeType[ext]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,51 +0,0 @@
|
|||
const ID3Writer = require("browser-id3-writer");
|
||||
|
||||
|
||||
export const IXAREA_API_ENDPOINT = "https://stats.ixarea.com/apis"
|
||||
|
||||
|
||||
export async function GetWebImage(pic_url) {
|
||||
try {
|
||||
let resp = await fetch(pic_url);
|
||||
let mime = resp.headers.get("Content-Type");
|
||||
if (mime.startsWith("image/")) {
|
||||
let buf = await resp.arrayBuffer();
|
||||
let objBlob = new Blob([buf], {type: mime});
|
||||
let objUrl = URL.createObjectURL(objBlob);
|
||||
return {"buffer": buf, "src": pic_url, "url": objUrl, "type": mime};
|
||||
}
|
||||
} catch (e) {
|
||||
}
|
||||
return {"buffer": null, "src": pic_url, "url": "", "type": ""}
|
||||
}
|
||||
|
||||
export async function WriteMp3Meta(audioData, artistList, title, album, pictureData = null, pictureDesc = "Cover", originalMeta = null) {
|
||||
const writer = new ID3Writer(audioData);
|
||||
if (originalMeta !== null) {
|
||||
artistList = originalMeta.common.artists || artistList
|
||||
title = originalMeta.common.title || title
|
||||
album = originalMeta.common.album || album
|
||||
const frames = originalMeta.native['ID3v2.4'] || originalMeta.native['ID3v2.3'] || originalMeta.native['ID3v2.2'] || []
|
||||
frames.forEach(frame => {
|
||||
if (frame.id !== 'TPE1' && frame.id !== 'TIT2' && frame.id !== 'TALB') {
|
||||
try {
|
||||
writer.setFrame(frame.id, frame.value)
|
||||
} catch (e) {
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
writer.setFrame('TPE1', artistList)
|
||||
.setFrame('TIT2', title)
|
||||
.setFrame('TALB', album);
|
||||
if (pictureData !== null) {
|
||||
writer.setFrame('APIC', {
|
||||
type: 3,
|
||||
data: pictureData,
|
||||
description: pictureDesc,
|
||||
})
|
||||
}
|
||||
writer.addTag();
|
||||
return writer.arrayBuffer;
|
||||
}
|
||||
|
|
@ -1,4 +1,6 @@
|
|||
import {IAudioMetadata} from "music-metadata-browser";
|
||||
import ID3Writer from "browser-id3-writer";
|
||||
import MetaFlac from "metaflac-js";
|
||||
|
||||
export const FLAC_HEADER = [0x66, 0x4C, 0x61, 0x43];
|
||||
export const MP3_HEADER = [0x49, 0x44, 0x33];
|
||||
|
@ -19,6 +21,7 @@ export const AudioMimeType: { [key: string]: string } = {
|
|||
wav: "audio/x-wav"
|
||||
};
|
||||
|
||||
|
||||
export function BytesHasPrefix(data: Uint8Array, prefix: number[]): boolean {
|
||||
if (prefix.length > data.length) return false
|
||||
return prefix.every((val, idx) => {
|
||||
|
@ -26,12 +29,6 @@ export function BytesHasPrefix(data: Uint8Array, prefix: number[]): boolean {
|
|||
})
|
||||
}
|
||||
|
||||
export function BytesEquals(data: Uint8Array, another: Uint8Array): boolean {
|
||||
if (another.length != data.length) return false
|
||||
return data.every((val, idx) => {
|
||||
return val === another[idx];
|
||||
})
|
||||
}
|
||||
|
||||
export function SniffAudioExt(data: Uint8Array, fallback_ext: string = "mp3"): string {
|
||||
if (BytesHasPrefix(data, MP3_HEADER)) return "mp3"
|
||||
|
@ -89,3 +86,73 @@ export function GetMetaFromFile(filename: string, exist_title?: string, exist_ar
|
|||
}
|
||||
return meta
|
||||
}
|
||||
|
||||
export async function GetImageFromURL(src: string):
|
||||
Promise<{ mime: string; buffer: ArrayBuffer; url: string } | undefined> {
|
||||
try {
|
||||
const resp = await fetch(src);
|
||||
const mime = resp.headers.get("Content-Type");
|
||||
if (mime?.startsWith("image/")) {
|
||||
const buffer = await resp.arrayBuffer();
|
||||
const url = URL.createObjectURL(new Blob([buffer], {type: mime}))
|
||||
return {buffer, url, mime}
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn(e)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export interface IMusicMeta {
|
||||
title: string
|
||||
artists?: string[]
|
||||
album?: string
|
||||
picture?: ArrayBuffer
|
||||
picture_desc?: string
|
||||
}
|
||||
|
||||
export function WriteMetaToMp3(audioData: Buffer, info: IMusicMeta, original: IAudioMetadata) {
|
||||
const writer = new ID3Writer(audioData);
|
||||
|
||||
// reserve original data
|
||||
const frames = original.native['ID3v2.4'] || original.native['ID3v2.3'] || original.native['ID3v2.2'] || []
|
||||
frames.forEach(frame => {
|
||||
if (frame.id !== 'TPE1' && frame.id !== 'TIT2' && frame.id !== 'TALB') {
|
||||
try {
|
||||
writer.setFrame(frame.id, frame.value)
|
||||
} catch (e) {
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const old = original.common
|
||||
writer.setFrame('TPE1', old?.artists || info.artists || [])
|
||||
.setFrame('TIT2', old?.title || info.title)
|
||||
.setFrame('TALB', old?.album || info.album || "");
|
||||
if (info.picture) {
|
||||
writer.setFrame('APIC', {
|
||||
type: 3,
|
||||
data: info.picture,
|
||||
description: info.picture_desc || "Cover",
|
||||
})
|
||||
}
|
||||
return writer.addTag();
|
||||
}
|
||||
|
||||
export function WriteMetaToFlac(audioData: Buffer, info: IMusicMeta, original: IAudioMetadata) {
|
||||
const writer = new MetaFlac(audioData)
|
||||
const old = original.common
|
||||
if (!old.title && !old.album && old.artists) {
|
||||
writer.setTag("TITLE=" + info.title)
|
||||
writer.setTag("ALBUM=" + info.album)
|
||||
if (info.artists) {
|
||||
writer.removeTag("ARTIST")
|
||||
info.artists.forEach(artist => writer.setTag("ARTIST=" + artist))
|
||||
}
|
||||
}
|
||||
|
||||
if (info.picture) {
|
||||
writer.importPictureFromBuffer(Buffer.from(info.picture))
|
||||
}
|
||||
return writer.save()
|
||||
}
|
||||
|
|
|
@ -1,22 +1,23 @@
|
|||
import {Decrypt as RawDecrypt} from "./raw";
|
||||
import {Decrypt as RawDecrypt} from "@/decrypt/raw";
|
||||
import {DecryptResult} from "@/decrypt/entity";
|
||||
import {AudioMimeType, BytesHasPrefix, GetArrayBuffer, GetCoverFromFile, GetMetaFromFile} from "@/decrypt/utils.ts";
|
||||
|
||||
import {parseBlob as metaParseBlob} from "music-metadata-browser";
|
||||
|
||||
const MagicHeader = [0x69, 0x66, 0x6D, 0x74]
|
||||
const MagicHeader2 = [0xfe, 0xfe, 0xfe, 0xfe]
|
||||
const FileTypeMap = {
|
||||
const FileTypeMap: { [key: string]: string } = {
|
||||
" WAV": ".wav",
|
||||
"FLAC": ".flac",
|
||||
" MP3": ".mp3",
|
||||
" A4M": ".m4a",
|
||||
}
|
||||
|
||||
export async function Decrypt(file, raw_filename, raw_ext) {
|
||||
export async function Decrypt(file: File, raw_filename: string, raw_ext: string): Promise<DecryptResult> {
|
||||
const oriData = new Uint8Array(await GetArrayBuffer(file));
|
||||
if (!BytesHasPrefix(oriData, MagicHeader) || !BytesHasPrefix(oriData.slice(8, 12), MagicHeader2)) {
|
||||
if (raw_ext === "xm") {
|
||||
return {status: false, message: "此xm文件已损坏"}
|
||||
throw Error("此xm文件已损坏")
|
||||
} else {
|
||||
return await RawDecrypt(file, raw_filename, raw_ext, true)
|
||||
}
|
||||
|
@ -24,7 +25,7 @@ export async function Decrypt(file, raw_filename, raw_ext) {
|
|||
|
||||
let typeText = (new TextDecoder()).decode(oriData.slice(4, 8))
|
||||
if (!FileTypeMap.hasOwnProperty(typeText)) {
|
||||
return {status: false, message: "未知的xm文件类型"}
|
||||
throw Error("未知的.xm文件类型")
|
||||
}
|
||||
|
||||
let key = oriData[0xf]
|
||||
|
@ -41,7 +42,7 @@ export async function Decrypt(file, raw_filename, raw_ext) {
|
|||
const musicMeta = await metaParseBlob(musicBlob);
|
||||
if (ext === "wav") {
|
||||
//todo:未知的编码方式
|
||||
console.log(musicMeta.common)
|
||||
console.info(musicMeta.common)
|
||||
musicMeta.common.album = "";
|
||||
musicMeta.common.artist = "";
|
||||
musicMeta.common.title = "";
|
||||
|
@ -51,7 +52,6 @@ export async function Decrypt(file, raw_filename, raw_ext) {
|
|||
raw_filename.indexOf("_") === -1 ? "-" : "_")
|
||||
|
||||
return {
|
||||
status: true,
|
||||
title,
|
||||
artist,
|
||||
ext,
|
||||
|
@ -59,6 +59,7 @@ export async function Decrypt(file, raw_filename, raw_ext) {
|
|||
album: musicMeta.common.album,
|
||||
picture: GetCoverFromFile(musicMeta),
|
||||
file: URL.createObjectURL(musicBlob),
|
||||
blob: musicBlob,
|
||||
rawExt: "xm"
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
import Vue from 'vue'
|
||||
import App from './App.vue'
|
||||
import './registerServiceWorker'
|
||||
import App from '@/App.vue'
|
||||
import '@/registerServiceWorker'
|
||||
import {
|
||||
Button,
|
||||
Checkbox,
|
||||
|
@ -18,7 +18,8 @@ import {
|
|||
Table,
|
||||
TableColumn,
|
||||
Tooltip,
|
||||
Upload
|
||||
Upload,
|
||||
MessageBox
|
||||
} from 'element-ui';
|
||||
import 'element-ui/lib/theme-chalk/base.css';
|
||||
|
||||
|
@ -39,6 +40,7 @@ Vue.use(Radio);
|
|||
Vue.use(Tooltip);
|
||||
Vue.use(Progress);
|
||||
Vue.prototype.$notify = Notification;
|
||||
Vue.prototype.$confirm = MessageBox.confirm;
|
||||
|
||||
Vue.config.productionTip = false;
|
||||
new Vue({
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
declare module "browser-id3-writer" {
|
||||
export default class ID3Writer {
|
||||
constructor(buffer: Buffer | ArrayBuffer)
|
||||
|
||||
setFrame(name: string, value: string | object | string[])
|
||||
|
||||
addTag(): Uint8Array
|
||||
}
|
||||
}
|
||||
|
||||
declare module "metaflac-js" {
|
||||
export default class Metaflac {
|
||||
constructor(buffer: Buffer)
|
||||
|
||||
setTag(field: string)
|
||||
|
||||
removeTag(name: string)
|
||||
|
||||
importPictureFromBuffer(picture: Buffer)
|
||||
|
||||
save(): Buffer
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
export interface FileSystemGetFileOptions {
|
||||
create?: boolean
|
||||
}
|
||||
|
||||
interface FileSystemCreateWritableOptions {
|
||||
keepExistingData?: boolean
|
||||
}
|
||||
|
||||
interface FileSystemFileHandle {
|
||||
getFile(): Promise<File>;
|
||||
|
||||
createWritable(options?: FileSystemCreateWritableOptions): Promise<FileSystemWritableFileStream>
|
||||
}
|
||||
|
||||
enum WriteCommandType {
|
||||
write = "write",
|
||||
seek = "seek",
|
||||
truncate = "truncate",
|
||||
}
|
||||
|
||||
interface WriteParams {
|
||||
type: WriteCommandType
|
||||
size?: number
|
||||
position?: number
|
||||
data: BufferSource | Blob | string
|
||||
}
|
||||
|
||||
type FileSystemWriteChunkType = BufferSource | Blob | string | WriteParams
|
||||
|
||||
interface FileSystemWritableFileStream extends WritableStream {
|
||||
write(data: FileSystemWriteChunkType): Promise<undefined>
|
||||
|
||||
seek(position: number): Promise<undefined>
|
||||
|
||||
truncate(size: number): Promise<undefined>
|
||||
|
||||
close(): Promise<undefined> // should be implemented in WritableStream
|
||||
}
|
||||
|
||||
export declare interface FileSystemDirectoryHandle {
|
||||
getFileHandle(name: string, options?: FileSystemGetFileOptions): Promise<FileSystemFileHandle>
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
FileSystemDirectoryHandle
|
||||
|
||||
showDirectoryPicker?(): Promise<FileSystemDirectoryHandle>
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
import {fromByteArray as Base64Encode} from "base64-js";
|
||||
|
||||
export const IXAREA_API_ENDPOINT = "https://stats.ixarea.com/apis"
|
||||
|
||||
export interface UpdateInfo {
|
||||
Found: boolean
|
||||
HttpsFound: boolean
|
||||
Version: string
|
||||
URL: string
|
||||
Detail: string
|
||||
}
|
||||
|
||||
export async function checkUpdate(version: string): Promise<UpdateInfo> {
|
||||
const resp = await fetch(IXAREA_API_ENDPOINT + "/music/app-version", {
|
||||
method: "POST",
|
||||
headers: {"Content-Type": "application/json"},
|
||||
body: JSON.stringify({"Version": version})
|
||||
});
|
||||
return await resp.json();
|
||||
}
|
||||
|
||||
export function reportKeyUsage(keyData: Uint8Array, maskData: number[], filename: string, format: string, title: string, artist?: string, album?: string) {
|
||||
return fetch(IXAREA_API_ENDPOINT + "/qmcmask/usage", {
|
||||
method: "POST",
|
||||
headers: {"Content-Type": "application/json"},
|
||||
body: JSON.stringify({
|
||||
Mask: Base64Encode(new Uint8Array(maskData)), Key: Base64Encode(keyData),
|
||||
Artist: artist, Title: title, Album: album, Filename: filename, Format: format
|
||||
}),
|
||||
})
|
||||
}
|
||||
|
||||
interface KeyInfo {
|
||||
Matrix44: string
|
||||
}
|
||||
|
||||
export async function queryKeyInfo(keyData: Uint8Array, filename: string, format: string): Promise<KeyInfo> {
|
||||
const resp = await fetch(IXAREA_API_ENDPOINT + "/qmcmask/query", {
|
||||
method: "POST",
|
||||
headers: {"Content-Type": "application/json"},
|
||||
body: JSON.stringify({Format: format, Key: Base64Encode(keyData), Filename: filename, Type: 44}),
|
||||
});
|
||||
return await resp.json();
|
||||
}
|
||||
|
||||
export interface CoverInfo {
|
||||
Id: string
|
||||
Type: number
|
||||
}
|
||||
|
||||
export async function queryAlbumCover(title: string, artist?: string, album?: string): Promise<CoverInfo> {
|
||||
const endpoint = IXAREA_API_ENDPOINT + "/music/qq-cover"
|
||||
const params = new URLSearchParams([["Title", title], ["Artist", artist ?? ""], ["Album", album ?? ""]])
|
||||
const resp = await fetch(`${endpoint}?${params.toString()}`)
|
||||
return await resp.json()
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
import {DecryptResult} from "@/decrypt/entity";
|
||||
import {FileSystemDirectoryHandle} from "@/shims-fs";
|
||||
|
||||
export enum FilenamePolicy {
|
||||
ArtistAndTitle,
|
||||
TitleOnly,
|
||||
TitleAndArtist,
|
||||
SameAsOriginal,
|
||||
}
|
||||
|
||||
export const FilenamePolicies: { key: FilenamePolicy, text: string }[] = [
|
||||
{key: FilenamePolicy.ArtistAndTitle, text: "歌手-歌曲名"},
|
||||
{key: FilenamePolicy.TitleOnly, text: "歌曲名"},
|
||||
{key: FilenamePolicy.TitleAndArtist, text: "歌曲名-歌手"},
|
||||
{key: FilenamePolicy.SameAsOriginal, text: "同源文件名"},
|
||||
]
|
||||
|
||||
export function GetDownloadFilename(data: DecryptResult, policy: FilenamePolicy): string {
|
||||
switch (policy) {
|
||||
case FilenamePolicy.TitleOnly:
|
||||
return `${data.title}.${data.ext}`;
|
||||
case FilenamePolicy.TitleAndArtist:
|
||||
return `${data.title} - ${data.artist}.${data.ext}`;
|
||||
case FilenamePolicy.SameAsOriginal:
|
||||
return `${data.rawFilename}.${data.ext}`;
|
||||
default:
|
||||
case FilenamePolicy.ArtistAndTitle:
|
||||
return `${data.artist} - ${data.title}.${data.ext}`;
|
||||
}
|
||||
}
|
||||
|
||||
export async function DirectlyWriteFile(data: DecryptResult, policy: FilenamePolicy, dir: FileSystemDirectoryHandle) {
|
||||
let filename = GetDownloadFilename(data, policy)
|
||||
// prevent filename exist
|
||||
try {
|
||||
await dir.getFileHandle(filename)
|
||||
filename = `${new Date().getTime()} - ${filename}`
|
||||
} catch (e) {
|
||||
}
|
||||
const file = await dir.getFileHandle(filename, {create: true})
|
||||
const w = await file.createWritable()
|
||||
await w.write(data.blob)
|
||||
await w.close()
|
||||
|
||||
}
|
||||
|
||||
export function DownloadBlobMusic(data: DecryptResult, policy: FilenamePolicy) {
|
||||
const a = document.createElement('a');
|
||||
a.href = data.file;
|
||||
a.download = GetDownloadFilename(data, policy)
|
||||
document.body.append(a);
|
||||
a.click();
|
||||
a.remove();
|
||||
}
|
||||
|
||||
export function RemoveBlobMusic(data: DecryptResult) {
|
||||
URL.revokeObjectURL(data.file);
|
||||
if (data.picture?.startsWith("blob:")) {
|
||||
URL.revokeObjectURL(data.picture);
|
||||
}
|
||||
}
|
||||
|
||||
export class DecryptQueue {
|
||||
private readonly pending: (() => Promise<void>)[];
|
||||
|
||||
constructor() {
|
||||
this.pending = []
|
||||
}
|
||||
|
||||
queue(fn: () => Promise<void>) {
|
||||
this.pending.push(fn)
|
||||
this.consume()
|
||||
}
|
||||
|
||||
private consume() {
|
||||
const fn = this.pending.shift()
|
||||
if (fn) fn().then(() => this.consume).catch(console.error)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
import {expose} from "threads/worker";
|
||||
import {CommonDecrypt} from "@/decrypt/common";
|
||||
|
||||
expose(CommonDecrypt)
|
|
@ -0,0 +1,157 @@
|
|||
<template>
|
||||
<div>
|
||||
<file-selector @error="showFail" @success="showSuccess"/>
|
||||
|
||||
<div id="app-control">
|
||||
<el-row class="mb-3">
|
||||
<span>歌曲命名格式:</span>
|
||||
<el-radio v-for="k in FilenamePolicies" :key="k.key"
|
||||
v-model="filename_policy" :label="k.key">
|
||||
{{ k.text }}
|
||||
</el-radio>
|
||||
</el-row>
|
||||
<el-row>
|
||||
<el-button icon="el-icon-download" plain @click="handleDownloadAll">下载全部</el-button>
|
||||
<el-button icon="el-icon-delete" plain type="danger" @click="handleDeleteAll">清除全部</el-button>
|
||||
|
||||
<el-tooltip class="item" effect="dark" placement="top-start">
|
||||
<div slot="content">
|
||||
<span v-if="instant_save">工作模式: {{ dir ? "写入本地文件系统" : "调用浏览器下载" }}</span>
|
||||
<span v-else>
|
||||
当您使用此工具进行大量文件解锁的时候,建议开启此选项。<br/>
|
||||
开启后,解锁结果将不会存留于浏览器中,防止内存不足。
|
||||
</span>
|
||||
</div>
|
||||
<el-checkbox v-model="instant_save" border class="ml-2">立即保存</el-checkbox>
|
||||
</el-tooltip>
|
||||
</el-row>
|
||||
</div>
|
||||
|
||||
<audio :autoplay="playing_auto" :src="playing_url" controls/>
|
||||
|
||||
<PreviewTable :policy="filename_policy" :table-data="tableData" @download="saveFile" @play="changePlaying"/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
||||
import FileSelector from "@/component/FileSelector"
|
||||
import PreviewTable from "@/component/PreviewTable"
|
||||
import {DownloadBlobMusic, FilenamePolicy, FilenamePolicies, RemoveBlobMusic, DirectlyWriteFile} from "@/utils/utils"
|
||||
|
||||
export default {
|
||||
name: 'Home',
|
||||
components: {
|
||||
FileSelector,
|
||||
PreviewTable
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
tableData: [],
|
||||
playing_url: "",
|
||||
playing_auto: false,
|
||||
filename_policy: FilenamePolicy.ArtistAndTitle,
|
||||
instant_save: false,
|
||||
FilenamePolicies,
|
||||
dir: null
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
instant_save(val) {
|
||||
if (val) this.showDirectlySave()
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
async showSuccess(data) {
|
||||
if (this.instant_save) {
|
||||
await this.saveFile(data)
|
||||
RemoveBlobMusic(data);
|
||||
} else {
|
||||
this.tableData.push(data);
|
||||
this.$notify.success({
|
||||
title: '解锁成功',
|
||||
message: '成功解锁 ' + data.title,
|
||||
duration: 3000
|
||||
});
|
||||
}
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
let _rp_data = [data.title, data.artist, data.album];
|
||||
window._paq.push(["trackEvent", "Unlock", data.rawExt + "," + data.mime, JSON.stringify(_rp_data)]);
|
||||
}
|
||||
},
|
||||
showFail(errInfo, filename) {
|
||||
console.error(errInfo, filename)
|
||||
this.$notify.error({
|
||||
title: '出现问题',
|
||||
message: errInfo + "," + filename +
|
||||
',参考<a target="_blank" href="https://github.com/ix64/unlock-music/wiki/使用提示">使用提示</a>',
|
||||
dangerouslyUseHTMLString: true,
|
||||
duration: 6000
|
||||
});
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
window._paq.push(["trackEvent", "Error", String(errInfo), filename]);
|
||||
}
|
||||
},
|
||||
changePlaying(url) {
|
||||
this.playing_url = url;
|
||||
this.playing_auto = true;
|
||||
},
|
||||
handleDeleteAll() {
|
||||
this.tableData.forEach(value => {
|
||||
RemoveBlobMusic(value);
|
||||
});
|
||||
this.tableData = [];
|
||||
},
|
||||
handleDownloadAll() {
|
||||
let index = 0;
|
||||
let c = setInterval(() => {
|
||||
if (index < this.tableData.length) {
|
||||
this.saveFile(this.tableData[index])
|
||||
index++;
|
||||
} else {
|
||||
clearInterval(c);
|
||||
}
|
||||
}, 300);
|
||||
},
|
||||
|
||||
async saveFile(data) {
|
||||
if (this.dir) {
|
||||
await DirectlyWriteFile(data, this.filename_policy, this.dir)
|
||||
this.$notify({
|
||||
title: "保存成功",
|
||||
message: data.title,
|
||||
position: "top-left",
|
||||
type: "success",
|
||||
duration: 3000
|
||||
})
|
||||
} else {
|
||||
DownloadBlobMusic(data, this.filename_policy)
|
||||
}
|
||||
},
|
||||
async showDirectlySave() {
|
||||
if (!window.showDirectoryPicker) return
|
||||
try {
|
||||
await this.$confirm("您的浏览器支持文件直接保存到磁盘,是否使用?",
|
||||
"新特性提示", {
|
||||
confirmButtonText: "使用",
|
||||
cancelButtonText: "不使用",
|
||||
type: "warning",
|
||||
center: true
|
||||
})
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
return
|
||||
}
|
||||
try {
|
||||
this.dir = await window.showDirectoryPicker()
|
||||
window.dir = this.dir
|
||||
window.f = await this.dir.getFileHandle("write-test.txt", {create: true})
|
||||
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "esnext",
|
||||
"target": "es5",
|
||||
"module": "esnext",
|
||||
"strict": true,
|
||||
"jsx": "preserve",
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
const ThreadsPlugin = require('threads-plugin');
|
||||
module.exports = {
|
||||
publicPath: '',
|
||||
productionSourceMap: false,
|
||||
|
@ -35,5 +36,8 @@ module.exports = {
|
|||
workboxOptions: {
|
||||
skipWaiting: true
|
||||
}
|
||||
},
|
||||
configureWebpack: {
|
||||
plugins: [new ThreadsPlugin()]
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue