all: format with prettier
This commit is contained in:
parent
4c9d79242d
commit
7045360079
150
src/App.vue
150
src/App.vue
|
@ -1,85 +1,87 @@
|
|||
<template>
|
||||
<el-container id="app">
|
||||
<el-main>
|
||||
<Home/>
|
||||
</el-main>
|
||||
<el-footer id="app-footer">
|
||||
<el-row>
|
||||
<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>
|
||||
目前支持 QQ音乐(qmc, mflac, mgg), 酷狗音乐(kgm), 虾米音乐(xm), 酷我音乐(.kwm)
|
||||
<a href="https://github.com/ix64/unlock-music/blob/master/README.md" target="_blank">更多</a>。
|
||||
</el-row>
|
||||
<el-row>
|
||||
<!--如果进行二次开发,此行版权信息不得移除且应明显地标注于页面上-->
|
||||
<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>
|
||||
<el-container id="app">
|
||||
<el-main>
|
||||
<Home />
|
||||
</el-main>
|
||||
<el-footer id="app-footer">
|
||||
<el-row>
|
||||
<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>
|
||||
目前支持 QQ音乐(qmc, mflac, mgg), 酷狗音乐(kgm), 虾米音乐(xm), 酷我音乐(.kwm)
|
||||
<a href="https://github.com/ix64/unlock-music/blob/master/README.md" target="_blank">更多</a>。
|
||||
</el-row>
|
||||
<el-row>
|
||||
<!--如果进行二次开发,此行版权信息不得移除且应明显地标注于页面上-->
|
||||
<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 FileSelector from "@/component/FileSelector"
|
||||
import PreviewTable from "@/component/PreviewTable"
|
||||
import config from "@/../package.json"
|
||||
import Home from "@/view/Home";
|
||||
import {checkUpdate} from "@/utils/api";
|
||||
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: {
|
||||
FileSelector,
|
||||
PreviewTable,
|
||||
Home
|
||||
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);
|
||||
}
|
||||
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>`,
|
||||
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',
|
||||
});
|
||||
}
|
||||
},
|
||||
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)
|
||||
}
|
||||
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>`,
|
||||
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'
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
@import "scss/unlock-music";
|
||||
@import 'scss/unlock-music';
|
||||
</style>
|
||||
|
|
|
@ -1,99 +1,90 @@
|
|||
<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>
|
||||
<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";
|
||||
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
|
||||
}
|
||||
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;
|
||||
},
|
||||
computed: {
|
||||
progress_value() {
|
||||
return this.task_all ? this.task_finished / this.task_all * 100 : 0
|
||||
},
|
||||
progress_show() {
|
||||
return this.task_all !== this.task_finished
|
||||
}
|
||||
progress_show() {
|
||||
return this.task_all !== this.task_finished;
|
||||
},
|
||||
mounted() {
|
||||
if (window.Worker && window.location.protocol !== "file:" && 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++
|
||||
}
|
||||
})
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
if (window.Worker && window.location.protocol !== 'file:' && 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>
|
||||
|
||||
|
|
|
@ -1,71 +1,62 @@
|
|||
<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>
|
||||
<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'
|
||||
import { RemoveBlobMusic } from '@/utils/utils';
|
||||
|
||||
export default {
|
||||
name: "PreviewTable",
|
||||
props: {
|
||||
tableData: {type: Array, required: true},
|
||||
policy: {type: Number, required: true}
|
||||
},
|
||||
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)
|
||||
},
|
||||
}
|
||||
}
|
||||
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>
|
||||
<style scoped></style>
|
||||
|
|
|
@ -1,73 +1,71 @@
|
|||
import {Decrypt as XmDecrypt} from "@/decrypt/xm";
|
||||
import {Decrypt as QmcDecrypt} from "@/decrypt/qmc";
|
||||
import {Decrypt as QmcCacheDecrypt} from "@/decrypt/qmccache";
|
||||
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, FileInfo} from "@/decrypt/entity";
|
||||
import {SplitFilename} from "@/decrypt/utils";
|
||||
|
||||
import { Decrypt as XmDecrypt } from '@/decrypt/xm';
|
||||
import { Decrypt as QmcDecrypt } from '@/decrypt/qmc';
|
||||
import { Decrypt as QmcCacheDecrypt } from '@/decrypt/qmccache';
|
||||
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, FileInfo } from '@/decrypt/entity';
|
||||
import { SplitFilename } from '@/decrypt/utils';
|
||||
|
||||
export async function CommonDecrypt(file: FileInfo): Promise<DecryptResult> {
|
||||
const raw = SplitFilename(file.name)
|
||||
let rt_data: DecryptResult;
|
||||
switch (raw.ext) {
|
||||
case "kwm":// Kuwo Mp3/Flac
|
||||
rt_data = await KwmDecrypt(file.raw, raw.name, raw.ext);
|
||||
break
|
||||
case "xm": // Xiami Wav/M4a/Mp3/Flac
|
||||
case "wav":// Xiami/Raw Wav
|
||||
case "mp3":// Xiami/Raw Mp3
|
||||
case "flac":// Xiami/Raw Flac
|
||||
case "m4a":// Xiami/Raw M4a
|
||||
rt_data = await XmDecrypt(file.raw, raw.name, raw.ext);
|
||||
break;
|
||||
case "ogg":// Raw Ogg
|
||||
rt_data = await RawDecrypt(file.raw, raw.name, raw.ext);
|
||||
break;
|
||||
case "tm0":// QQ Music IOS Mp3
|
||||
case "tm3":// QQ Music IOS Mp3
|
||||
rt_data = await RawDecrypt(file.raw, raw.name, "mp3");
|
||||
break;
|
||||
case "qmc3"://QQ Music Android Mp3
|
||||
case "qmc2"://QQ Music Android Ogg
|
||||
case "qmc0"://QQ Music Android Mp3
|
||||
case "qmcflac"://QQ Music Android Flac
|
||||
case "qmcogg"://QQ Music Android Ogg
|
||||
case "tkm"://QQ Music Accompaniment M4a
|
||||
case "bkcmp3"://Moo Music Mp3
|
||||
case "bkcflac"://Moo Music Flac
|
||||
case "mflac"://QQ Music New Flac
|
||||
case "mflac0"://QQ Music New Flac
|
||||
case "mgg": //QQ Music New Ogg
|
||||
case "mgg1": //QQ Music New Ogg
|
||||
case "666c6163"://QQ Music Weiyun Flac
|
||||
case "6d7033"://QQ Music Weiyun Mp3
|
||||
case "6f6767"://QQ Music Weiyun Ogg
|
||||
case "6d3461"://QQ Music Weiyun M4a
|
||||
case "776176"://QQ Music Weiyun Wav
|
||||
rt_data = await QmcDecrypt(file.raw, raw.name, raw.ext);
|
||||
break;
|
||||
case "tm2":// QQ Music IOS M4a
|
||||
case "tm6":// QQ Music IOS M4a
|
||||
rt_data = await TmDecrypt(file.raw, raw.name);
|
||||
break;
|
||||
case "cache"://QQ Music Cache
|
||||
rt_data = await QmcCacheDecrypt(file.raw, raw.name, raw.ext);
|
||||
break;
|
||||
case "vpr":
|
||||
case "kgm":
|
||||
case "kgma":
|
||||
rt_data = await KgmDecrypt(file.raw, raw.name, raw.ext);
|
||||
break
|
||||
default:
|
||||
throw "不支持此文件格式"
|
||||
}
|
||||
const raw = SplitFilename(file.name);
|
||||
let rt_data: DecryptResult;
|
||||
switch (raw.ext) {
|
||||
case 'kwm': // Kuwo Mp3/Flac
|
||||
rt_data = await KwmDecrypt(file.raw, raw.name, raw.ext);
|
||||
break;
|
||||
case 'xm': // Xiami Wav/M4a/Mp3/Flac
|
||||
case 'wav': // Xiami/Raw Wav
|
||||
case 'mp3': // Xiami/Raw Mp3
|
||||
case 'flac': // Xiami/Raw Flac
|
||||
case 'm4a': // Xiami/Raw M4a
|
||||
rt_data = await XmDecrypt(file.raw, raw.name, raw.ext);
|
||||
break;
|
||||
case 'ogg': // Raw Ogg
|
||||
rt_data = await RawDecrypt(file.raw, raw.name, raw.ext);
|
||||
break;
|
||||
case 'tm0': // QQ Music IOS Mp3
|
||||
case 'tm3': // QQ Music IOS Mp3
|
||||
rt_data = await RawDecrypt(file.raw, raw.name, 'mp3');
|
||||
break;
|
||||
case 'qmc3': //QQ Music Android Mp3
|
||||
case 'qmc2': //QQ Music Android Ogg
|
||||
case 'qmc0': //QQ Music Android Mp3
|
||||
case 'qmcflac': //QQ Music Android Flac
|
||||
case 'qmcogg': //QQ Music Android Ogg
|
||||
case 'tkm': //QQ Music Accompaniment M4a
|
||||
case 'bkcmp3': //Moo Music Mp3
|
||||
case 'bkcflac': //Moo Music Flac
|
||||
case 'mflac': //QQ Music New Flac
|
||||
case 'mflac0': //QQ Music New Flac
|
||||
case 'mgg': //QQ Music New Ogg
|
||||
case 'mgg1': //QQ Music New Ogg
|
||||
case '666c6163': //QQ Music Weiyun Flac
|
||||
case '6d7033': //QQ Music Weiyun Mp3
|
||||
case '6f6767': //QQ Music Weiyun Ogg
|
||||
case '6d3461': //QQ Music Weiyun M4a
|
||||
case '776176': //QQ Music Weiyun Wav
|
||||
rt_data = await QmcDecrypt(file.raw, raw.name, raw.ext);
|
||||
break;
|
||||
case 'tm2': // QQ Music IOS M4a
|
||||
case 'tm6': // QQ Music IOS M4a
|
||||
rt_data = await TmDecrypt(file.raw, raw.name);
|
||||
break;
|
||||
case 'cache': //QQ Music Cache
|
||||
rt_data = await QmcCacheDecrypt(file.raw, raw.name, raw.ext);
|
||||
break;
|
||||
case 'vpr':
|
||||
case 'kgm':
|
||||
case 'kgma':
|
||||
rt_data = await KgmDecrypt(file.raw, raw.name, raw.ext);
|
||||
break;
|
||||
default:
|
||||
throw '不支持此文件格式';
|
||||
}
|
||||
|
||||
if (!rt_data.rawExt) rt_data.rawExt = raw.ext;
|
||||
if (!rt_data.rawFilename) rt_data.rawFilename = raw.name;
|
||||
console.log(rt_data);
|
||||
return rt_data;
|
||||
if (!rt_data.rawExt) rt_data.rawExt = raw.ext;
|
||||
if (!rt_data.rawFilename) rt_data.rawFilename = raw.name;
|
||||
console.log(rt_data);
|
||||
return rt_data;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,26 +1,25 @@
|
|||
export interface DecryptResult {
|
||||
title: string
|
||||
album?: string
|
||||
artist?: string
|
||||
title: string;
|
||||
album?: string;
|
||||
artist?: string;
|
||||
|
||||
mime: string
|
||||
ext: string
|
||||
mime: string;
|
||||
ext: string;
|
||||
|
||||
file: string
|
||||
blob: Blob
|
||||
picture?: string
|
||||
|
||||
message?: string
|
||||
rawExt?: string
|
||||
rawFilename?: string
|
||||
file: 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
|
||||
status: string;
|
||||
name: string;
|
||||
size: number;
|
||||
percentage: number;
|
||||
uid: number;
|
||||
raw: File;
|
||||
}
|
||||
|
|
|
@ -1,77 +1,74 @@
|
|||
import {
|
||||
AudioMimeType,
|
||||
BytesHasPrefix,
|
||||
GetArrayBuffer,
|
||||
GetCoverFromFile,
|
||||
GetMetaFromFile,
|
||||
SniffAudioExt
|
||||
} from "@/decrypt/utils";
|
||||
import {Decrypt as RawDecrypt} from "@/decrypt/raw";
|
||||
AudioMimeType,
|
||||
BytesHasPrefix,
|
||||
GetArrayBuffer,
|
||||
GetCoverFromFile,
|
||||
GetMetaFromFile,
|
||||
SniffAudioExt,
|
||||
} from '@/decrypt/utils';
|
||||
import { Decrypt as RawDecrypt } from '@/decrypt/raw';
|
||||
|
||||
import {parseBlob as metaParseBlob} from "music-metadata-browser";
|
||||
import {DecryptResult} from "@/decrypt/entity";
|
||||
import { parseBlob as metaParseBlob } from 'music-metadata-browser';
|
||||
import { DecryptResult } from '@/decrypt/entity';
|
||||
|
||||
//prettier-ignore
|
||||
const MagicHeader = [
|
||||
0x79, 0x65, 0x65, 0x6C, 0x69, 0x6F, 0x6E, 0x2D,
|
||||
0x6B, 0x75, 0x77, 0x6F, 0x2D, 0x74, 0x6D, 0x65,
|
||||
0x79, 0x65, 0x65, 0x6C, 0x69, 0x6F, 0x6E, 0x2D,
|
||||
0x6B, 0x75, 0x77, 0x6F, 0x2D, 0x74, 0x6D, 0x65,
|
||||
]
|
||||
const PreDefinedKey = "MoOtOiTvINGwd2E6n0E1i7L5t2IoOoNk"
|
||||
const PreDefinedKey = 'MoOtOiTvINGwd2E6n0E1i7L5t2IoOoNk';
|
||||
|
||||
export async function Decrypt(file: File, raw_filename: string, _: string): Promise<DecryptResult> {
|
||||
const oriData = new Uint8Array(await GetArrayBuffer(file));
|
||||
if (!BytesHasPrefix(oriData, MagicHeader)) {
|
||||
if (SniffAudioExt(oriData) === "aac") {
|
||||
return await RawDecrypt(file, raw_filename, "aac", false)
|
||||
}
|
||||
throw Error("not a valid kwm file")
|
||||
const oriData = new Uint8Array(await GetArrayBuffer(file));
|
||||
if (!BytesHasPrefix(oriData, MagicHeader)) {
|
||||
if (SniffAudioExt(oriData) === 'aac') {
|
||||
return await RawDecrypt(file, raw_filename, 'aac', false);
|
||||
}
|
||||
throw Error('not a valid kwm file');
|
||||
}
|
||||
|
||||
let fileKey = oriData.slice(0x18, 0x20)
|
||||
let mask = createMaskFromKey(fileKey)
|
||||
let audioData = oriData.slice(0x400);
|
||||
let lenAudioData = audioData.length;
|
||||
for (let cur = 0; cur < lenAudioData; ++cur)
|
||||
audioData[cur] ^= mask[cur % 0x20];
|
||||
let fileKey = oriData.slice(0x18, 0x20);
|
||||
let mask = createMaskFromKey(fileKey);
|
||||
let audioData = oriData.slice(0x400);
|
||||
let lenAudioData = audioData.length;
|
||||
for (let cur = 0; cur < lenAudioData; ++cur) audioData[cur] ^= mask[cur % 0x20];
|
||||
|
||||
const ext = SniffAudioExt(audioData);
|
||||
const mime = AudioMimeType[ext];
|
||||
let musicBlob = new Blob([audioData], { type: mime });
|
||||
|
||||
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 {
|
||||
album: musicMeta.common.album,
|
||||
picture: GetCoverFromFile(musicMeta),
|
||||
file: URL.createObjectURL(musicBlob),
|
||||
blob: musicBlob,
|
||||
mime,
|
||||
title,
|
||||
artist,
|
||||
ext
|
||||
}
|
||||
const musicMeta = await metaParseBlob(musicBlob);
|
||||
const { title, artist } = GetMetaFromFile(raw_filename, musicMeta.common.title, musicMeta.common.artist);
|
||||
return {
|
||||
album: musicMeta.common.album,
|
||||
picture: GetCoverFromFile(musicMeta),
|
||||
file: URL.createObjectURL(musicBlob),
|
||||
blob: musicBlob,
|
||||
mime,
|
||||
title,
|
||||
artist,
|
||||
ext,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
function createMaskFromKey(keyBytes: Uint8Array): Uint8Array {
|
||||
let keyView = new DataView(keyBytes.buffer)
|
||||
let keyStr = keyView.getBigUint64(0, true).toString()
|
||||
let keyStrTrim = trimKey(keyStr)
|
||||
let key = new Uint8Array(32)
|
||||
for (let i = 0; i < 32; i++) {
|
||||
key[i] = PreDefinedKey.charCodeAt(i) ^ keyStrTrim.charCodeAt(i)
|
||||
}
|
||||
return key
|
||||
let keyView = new DataView(keyBytes.buffer);
|
||||
let keyStr = keyView.getBigUint64(0, true).toString();
|
||||
let keyStrTrim = trimKey(keyStr);
|
||||
let key = new Uint8Array(32);
|
||||
for (let i = 0; i < 32; i++) {
|
||||
key[i] = PreDefinedKey.charCodeAt(i) ^ keyStrTrim.charCodeAt(i);
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
|
||||
function trimKey(keyRaw: string): string {
|
||||
let lenRaw = keyRaw.length;
|
||||
let out = keyRaw;
|
||||
if (lenRaw > 32) {
|
||||
out = keyRaw.slice(0, 32)
|
||||
} else if (lenRaw < 32) {
|
||||
out = keyRaw.padEnd(32, keyRaw)
|
||||
}
|
||||
return out
|
||||
let lenRaw = keyRaw.length;
|
||||
let out = keyRaw;
|
||||
if (lenRaw > 32) {
|
||||
out = keyRaw.slice(0, 32);
|
||||
} else if (lenRaw < 32) {
|
||||
out = keyRaw.padEnd(32, keyRaw);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
|
|
@ -1,28 +1,32 @@
|
|||
import {AudioMimeType, GetArrayBuffer, GetCoverFromFile, GetMetaFromFile, SniffAudioExt} from "@/decrypt/utils";
|
||||
import { AudioMimeType, GetArrayBuffer, GetCoverFromFile, GetMetaFromFile, SniffAudioExt } from '@/decrypt/utils';
|
||||
|
||||
import {DecryptResult} from "@/decrypt/entity";
|
||||
import { DecryptResult } from '@/decrypt/entity';
|
||||
|
||||
import {parseBlob as metaParseBlob} from "music-metadata-browser";
|
||||
import { parseBlob as metaParseBlob } from 'music-metadata-browser';
|
||||
|
||||
export async function Decrypt(file: Blob, raw_filename: string, raw_ext: string, detect: boolean = true)
|
||||
: Promise<DecryptResult> {
|
||||
let ext = raw_ext;
|
||||
if (detect) {
|
||||
const buffer = new Uint8Array(await GetArrayBuffer(file));
|
||||
ext = SniffAudioExt(buffer, raw_ext);
|
||||
if (ext !== raw_ext) file = new Blob([buffer], {type: AudioMimeType[ext]})
|
||||
}
|
||||
const tag = await metaParseBlob(file);
|
||||
const {title, artist} = GetMetaFromFile(raw_filename, tag.common.title, tag.common.artist)
|
||||
export async function Decrypt(
|
||||
file: Blob,
|
||||
raw_filename: string,
|
||||
raw_ext: string,
|
||||
detect: boolean = true,
|
||||
): Promise<DecryptResult> {
|
||||
let ext = raw_ext;
|
||||
if (detect) {
|
||||
const buffer = new Uint8Array(await GetArrayBuffer(file));
|
||||
ext = SniffAudioExt(buffer, raw_ext);
|
||||
if (ext !== raw_ext) file = new Blob([buffer], { type: AudioMimeType[ext] });
|
||||
}
|
||||
const tag = await metaParseBlob(file);
|
||||
const { title, artist } = GetMetaFromFile(raw_filename, tag.common.title, tag.common.artist);
|
||||
|
||||
return {
|
||||
title,
|
||||
artist,
|
||||
ext,
|
||||
album: tag.common.album,
|
||||
picture: GetCoverFromFile(tag),
|
||||
file: URL.createObjectURL(file),
|
||||
blob: file,
|
||||
mime: AudioMimeType[ext]
|
||||
}
|
||||
return {
|
||||
title,
|
||||
artist,
|
||||
ext,
|
||||
album: tag.common.album,
|
||||
picture: GetCoverFromFile(tag),
|
||||
file: URL.createObjectURL(file),
|
||||
blob: file,
|
||||
mime: AudioMimeType[ext],
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
import {Decrypt as RawDecrypt} from "./raw";
|
||||
import {GetArrayBuffer} from "@/decrypt/utils";
|
||||
import {DecryptResult} from "@/decrypt/entity";
|
||||
import { Decrypt as RawDecrypt } from './raw';
|
||||
import { GetArrayBuffer } from '@/decrypt/utils';
|
||||
import { DecryptResult } from '@/decrypt/entity';
|
||||
|
||||
const TM_HEADER = [0x00, 0x00, 0x00, 0x20, 0x66, 0x74, 0x79, 0x70];
|
||||
|
||||
export async function Decrypt(file: File, raw_filename: string): Promise<DecryptResult> {
|
||||
const audioData = new Uint8Array(await GetArrayBuffer(file));
|
||||
for (let cur = 0; cur < 8; ++cur) {
|
||||
audioData[cur] = TM_HEADER[cur];
|
||||
}
|
||||
const musicData = new Blob([audioData], {type: "audio/mp4"});
|
||||
return await RawDecrypt(musicData, raw_filename, "m4a", false)
|
||||
const audioData = new Uint8Array(await GetArrayBuffer(file));
|
||||
for (let cur = 0; cur < 8; ++cur) {
|
||||
audioData[cur] = TM_HEADER[cur];
|
||||
}
|
||||
const musicData = new Blob([audioData], { type: 'audio/mp4' });
|
||||
return await RawDecrypt(musicData, raw_filename, 'm4a', false);
|
||||
}
|
||||
|
|
|
@ -1,177 +1,176 @@
|
|||
import {IAudioMetadata} from "music-metadata-browser";
|
||||
import ID3Writer from "browser-id3-writer";
|
||||
import MetaFlac from "metaflac-js";
|
||||
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 FLAC_HEADER = [0x66, 0x4c, 0x61, 0x43];
|
||||
export const MP3_HEADER = [0x49, 0x44, 0x33];
|
||||
export const OGG_HEADER = [0x4F, 0x67, 0x67, 0x53];
|
||||
export const OGG_HEADER = [0x4f, 0x67, 0x67, 0x53];
|
||||
export const M4A_HEADER = [0x66, 0x74, 0x79, 0x70];
|
||||
export const WMA_HEADER = [
|
||||
0x30, 0x26, 0xB2, 0x75, 0x8E, 0x66, 0xCF, 0x11,
|
||||
0xA6, 0xD9, 0x00, 0xAA, 0x00, 0x62, 0xCE, 0x6C,
|
||||
]
|
||||
export const WAV_HEADER = [0x52, 0x49, 0x46, 0x46]
|
||||
export const AAC_HEADER = [0xFF, 0xF1]
|
||||
export const DFF_HEADER = [0x46, 0x52, 0x4D, 0x38]
|
||||
0x30, 0x26, 0xb2, 0x75, 0x8e, 0x66, 0xcf, 0x11, 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c,
|
||||
];
|
||||
export const WAV_HEADER = [0x52, 0x49, 0x46, 0x46];
|
||||
export const AAC_HEADER = [0xff, 0xf1];
|
||||
export const DFF_HEADER = [0x46, 0x52, 0x4d, 0x38];
|
||||
|
||||
export const AudioMimeType: { [key: string]: string } = {
|
||||
mp3: "audio/mpeg",
|
||||
flac: "audio/flac",
|
||||
m4a: "audio/mp4",
|
||||
ogg: "audio/ogg",
|
||||
wma: "audio/x-ms-wma",
|
||||
wav: "audio/x-wav",
|
||||
dff: "audio/x-dff"
|
||||
mp3: 'audio/mpeg',
|
||||
flac: 'audio/flac',
|
||||
m4a: 'audio/mp4',
|
||||
ogg: 'audio/ogg',
|
||||
wma: 'audio/x-ms-wma',
|
||||
wav: 'audio/x-wav',
|
||||
dff: 'audio/x-dff',
|
||||
};
|
||||
|
||||
|
||||
export function BytesHasPrefix(data: Uint8Array, prefix: number[]): boolean {
|
||||
if (prefix.length > data.length) return false
|
||||
return prefix.every((val, idx) => {
|
||||
return val === data[idx];
|
||||
})
|
||||
if (prefix.length > data.length) return false;
|
||||
return prefix.every((val, idx) => {
|
||||
return val === data[idx];
|
||||
});
|
||||
}
|
||||
|
||||
export function BytesEqual(a: Uint8Array, b: Uint8Array,): boolean {
|
||||
if (a.length !== b.length) return false
|
||||
return a.every((val, idx) => {
|
||||
return val === b[idx];
|
||||
})
|
||||
export function BytesEqual(a: Uint8Array, b: Uint8Array): boolean {
|
||||
if (a.length !== b.length) return false;
|
||||
return a.every((val, idx) => {
|
||||
return val === b[idx];
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
export function SniffAudioExt(data: Uint8Array, fallback_ext: string = "mp3"): string {
|
||||
if (BytesHasPrefix(data, MP3_HEADER)) return "mp3"
|
||||
if (BytesHasPrefix(data, FLAC_HEADER)) return "flac"
|
||||
if (BytesHasPrefix(data, OGG_HEADER)) return "ogg"
|
||||
if (data.length >= 4 + M4A_HEADER.length &&
|
||||
BytesHasPrefix(data.slice(4), M4A_HEADER)) return "m4a"
|
||||
if (BytesHasPrefix(data, WAV_HEADER)) return "wav"
|
||||
if (BytesHasPrefix(data, WMA_HEADER)) return "wma"
|
||||
if (BytesHasPrefix(data, AAC_HEADER)) return "aac"
|
||||
if (BytesHasPrefix(data, DFF_HEADER)) return "dff"
|
||||
return fallback_ext;
|
||||
export function SniffAudioExt(data: Uint8Array, fallback_ext: string = 'mp3'): string {
|
||||
if (BytesHasPrefix(data, MP3_HEADER)) return 'mp3';
|
||||
if (BytesHasPrefix(data, FLAC_HEADER)) return 'flac';
|
||||
if (BytesHasPrefix(data, OGG_HEADER)) return 'ogg';
|
||||
if (data.length >= 4 + M4A_HEADER.length && BytesHasPrefix(data.slice(4), M4A_HEADER)) return 'm4a';
|
||||
if (BytesHasPrefix(data, WAV_HEADER)) return 'wav';
|
||||
if (BytesHasPrefix(data, WMA_HEADER)) return 'wma';
|
||||
if (BytesHasPrefix(data, AAC_HEADER)) return 'aac';
|
||||
if (BytesHasPrefix(data, DFF_HEADER)) return 'dff';
|
||||
return fallback_ext;
|
||||
}
|
||||
|
||||
export function GetArrayBuffer(obj: Blob): Promise<ArrayBuffer> {
|
||||
if (!!obj.arrayBuffer) return obj.arrayBuffer()
|
||||
return new Promise((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
reader.onload = (e) => {
|
||||
const rs = e.target?.result
|
||||
if (!rs) {
|
||||
reject("read file failed")
|
||||
} else {
|
||||
resolve(rs as ArrayBuffer)
|
||||
}
|
||||
};
|
||||
reader.readAsArrayBuffer(obj);
|
||||
});
|
||||
if (!!obj.arrayBuffer) return obj.arrayBuffer();
|
||||
return new Promise((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
reader.onload = (e) => {
|
||||
const rs = e.target?.result;
|
||||
if (!rs) {
|
||||
reject('read file failed');
|
||||
} else {
|
||||
resolve(rs as ArrayBuffer);
|
||||
}
|
||||
};
|
||||
reader.readAsArrayBuffer(obj);
|
||||
});
|
||||
}
|
||||
|
||||
export function GetCoverFromFile(metadata: IAudioMetadata): string {
|
||||
if (metadata.common?.picture && metadata.common.picture.length > 0) {
|
||||
return URL.createObjectURL(new Blob(
|
||||
[metadata.common.picture[0].data],
|
||||
{type: metadata.common.picture[0].format}
|
||||
));
|
||||
}
|
||||
return "";
|
||||
if (metadata.common?.picture && metadata.common.picture.length > 0) {
|
||||
return URL.createObjectURL(
|
||||
new Blob([metadata.common.picture[0].data], { type: metadata.common.picture[0].format }),
|
||||
);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
export interface IMusicMetaBasic {
|
||||
title: string
|
||||
artist?: string
|
||||
title: string;
|
||||
artist?: string;
|
||||
}
|
||||
|
||||
export function GetMetaFromFile(filename: string, exist_title?: string, exist_artist?: string, separator = "-")
|
||||
: IMusicMetaBasic {
|
||||
const meta: IMusicMetaBasic = {title: exist_title ?? "", artist: exist_artist}
|
||||
export function GetMetaFromFile(
|
||||
filename: string,
|
||||
exist_title?: string,
|
||||
exist_artist?: string,
|
||||
separator = '-',
|
||||
): IMusicMetaBasic {
|
||||
const meta: IMusicMetaBasic = { title: exist_title ?? '', artist: exist_artist };
|
||||
|
||||
const items = filename.split(separator);
|
||||
if (items.length > 1) {
|
||||
if (!meta.artist) meta.artist = items[0].trim();
|
||||
if (!meta.title) meta.title = items[1].trim();
|
||||
} else if (items.length === 1) {
|
||||
if (!meta.title) meta.title = items[0].trim();
|
||||
const items = filename.split(separator);
|
||||
if (items.length > 1) {
|
||||
if (!meta.artist) meta.artist = items[0].trim();
|
||||
if (!meta.title) meta.title = items[1].trim();
|
||||
} else if (items.length === 1) {
|
||||
if (!meta.title) meta.title = items[0].trim();
|
||||
}
|
||||
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 };
|
||||
}
|
||||
return meta
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
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);
|
||||
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",
|
||||
})
|
||||
// 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) {}
|
||||
}
|
||||
return writer.addTag();
|
||||
});
|
||||
|
||||
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))
|
||||
}
|
||||
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()
|
||||
if (info.picture) {
|
||||
writer.importPictureFromBuffer(Buffer.from(info.picture));
|
||||
}
|
||||
return writer.save();
|
||||
}
|
||||
|
||||
export function SplitFilename(n: string): { name: string; ext: string } {
|
||||
const pos = n.lastIndexOf(".")
|
||||
return {
|
||||
ext: n.substring(pos + 1).toLowerCase(),
|
||||
name: n.substring(0, pos)
|
||||
}
|
||||
const pos = n.lastIndexOf('.');
|
||||
return {
|
||||
ext: n.substring(pos + 1).toLowerCase(),
|
||||
name: n.substring(0, pos),
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,66 +1,67 @@
|
|||
import {Decrypt as RawDecrypt} from "@/decrypt/raw";
|
||||
import {DecryptResult} from "@/decrypt/entity";
|
||||
import {AudioMimeType, BytesHasPrefix, GetArrayBuffer, GetCoverFromFile, GetMetaFromFile} from "@/decrypt/utils";
|
||||
import { Decrypt as RawDecrypt } from '@/decrypt/raw';
|
||||
import { DecryptResult } from '@/decrypt/entity';
|
||||
import { AudioMimeType, BytesHasPrefix, GetArrayBuffer, GetCoverFromFile, GetMetaFromFile } from '@/decrypt/utils';
|
||||
|
||||
import {parseBlob as metaParseBlob} from "music-metadata-browser";
|
||||
import { parseBlob as metaParseBlob } from 'music-metadata-browser';
|
||||
|
||||
const MagicHeader = [0x69, 0x66, 0x6D, 0x74]
|
||||
const MagicHeader2 = [0xfe, 0xfe, 0xfe, 0xfe]
|
||||
const MagicHeader = [0x69, 0x66, 0x6d, 0x74];
|
||||
const MagicHeader2 = [0xfe, 0xfe, 0xfe, 0xfe];
|
||||
const FileTypeMap: { [key: string]: string } = {
|
||||
" WAV": ".wav",
|
||||
"FLAC": ".flac",
|
||||
" MP3": ".mp3",
|
||||
" A4M": ".m4a",
|
||||
}
|
||||
' WAV': '.wav',
|
||||
FLAC: '.flac',
|
||||
' MP3': '.mp3',
|
||||
' A4M': '.m4a',
|
||||
};
|
||||
|
||||
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") {
|
||||
throw Error("此xm文件已损坏")
|
||||
} else {
|
||||
return await RawDecrypt(file, raw_filename, raw_ext, true)
|
||||
}
|
||||
const oriData = new Uint8Array(await GetArrayBuffer(file));
|
||||
if (!BytesHasPrefix(oriData, MagicHeader) || !BytesHasPrefix(oriData.slice(8, 12), MagicHeader2)) {
|
||||
if (raw_ext === 'xm') {
|
||||
throw Error('此xm文件已损坏');
|
||||
} else {
|
||||
return await RawDecrypt(file, raw_filename, raw_ext, true);
|
||||
}
|
||||
}
|
||||
|
||||
let typeText = (new TextDecoder()).decode(oriData.slice(4, 8))
|
||||
if (!FileTypeMap.hasOwnProperty(typeText)) {
|
||||
throw Error("未知的.xm文件类型")
|
||||
}
|
||||
let typeText = new TextDecoder().decode(oriData.slice(4, 8));
|
||||
if (!FileTypeMap.hasOwnProperty(typeText)) {
|
||||
throw Error('未知的.xm文件类型');
|
||||
}
|
||||
|
||||
let key = oriData[0xf]
|
||||
let dataOffset = oriData[0xc] | oriData[0xd] << 8 | oriData[0xe] << 16
|
||||
let audioData = oriData.slice(0x10);
|
||||
let lenAudioData = audioData.length;
|
||||
for (let cur = dataOffset; cur < lenAudioData; ++cur)
|
||||
audioData[cur] = (audioData[cur] - key) ^ 0xff;
|
||||
let key = oriData[0xf];
|
||||
let dataOffset = oriData[0xc] | (oriData[0xd] << 8) | (oriData[0xe] << 16);
|
||||
let audioData = oriData.slice(0x10);
|
||||
let lenAudioData = audioData.length;
|
||||
for (let cur = dataOffset; cur < lenAudioData; ++cur) audioData[cur] = (audioData[cur] - key) ^ 0xff;
|
||||
|
||||
const ext = FileTypeMap[typeText];
|
||||
const mime = AudioMimeType[ext];
|
||||
let musicBlob = new Blob([audioData], {type: mime});
|
||||
const ext = FileTypeMap[typeText];
|
||||
const mime = AudioMimeType[ext];
|
||||
let musicBlob = new Blob([audioData], { type: mime });
|
||||
|
||||
const musicMeta = await metaParseBlob(musicBlob);
|
||||
if (ext === "wav") {
|
||||
//todo:未知的编码方式
|
||||
console.info(musicMeta.common)
|
||||
musicMeta.common.album = "";
|
||||
musicMeta.common.artist = "";
|
||||
musicMeta.common.title = "";
|
||||
}
|
||||
const {title, artist} = GetMetaFromFile(raw_filename,
|
||||
musicMeta.common.title, musicMeta.common.artist,
|
||||
raw_filename.indexOf("_") === -1 ? "-" : "_")
|
||||
const musicMeta = await metaParseBlob(musicBlob);
|
||||
if (ext === 'wav') {
|
||||
//todo:未知的编码方式
|
||||
console.info(musicMeta.common);
|
||||
musicMeta.common.album = '';
|
||||
musicMeta.common.artist = '';
|
||||
musicMeta.common.title = '';
|
||||
}
|
||||
const { title, artist } = GetMetaFromFile(
|
||||
raw_filename,
|
||||
musicMeta.common.title,
|
||||
musicMeta.common.artist,
|
||||
raw_filename.indexOf('_') === -1 ? '-' : '_',
|
||||
);
|
||||
|
||||
return {
|
||||
title,
|
||||
artist,
|
||||
ext,
|
||||
mime,
|
||||
album: musicMeta.common.album,
|
||||
picture: GetCoverFromFile(musicMeta),
|
||||
file: URL.createObjectURL(musicBlob),
|
||||
blob: musicBlob,
|
||||
rawExt: "xm"
|
||||
}
|
||||
return {
|
||||
title,
|
||||
artist,
|
||||
ext,
|
||||
mime,
|
||||
album: musicMeta.common.album,
|
||||
picture: GetCoverFromFile(musicMeta),
|
||||
file: URL.createObjectURL(musicBlob),
|
||||
blob: musicBlob,
|
||||
rawExt: 'xm',
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,2 @@
|
|||
const bs = chrome || browser
|
||||
bs.tabs.create({
|
||||
url: bs.runtime.getURL('./index.html')
|
||||
}, tab => console.log(tab))
|
||||
|
||||
const bs = chrome || browser;
|
||||
bs.tabs.create({ url: bs.runtime.getURL('./index.html') }, (tab) => console.log(tab));
|
||||
|
|
44
src/main.ts
44
src/main.ts
|
@ -1,25 +1,25 @@
|
|||
import Vue from 'vue'
|
||||
import App from '@/App.vue'
|
||||
import '@/registerServiceWorker'
|
||||
import Vue from 'vue';
|
||||
import App from '@/App.vue';
|
||||
import '@/registerServiceWorker';
|
||||
import {
|
||||
Button,
|
||||
Checkbox,
|
||||
Col,
|
||||
Container,
|
||||
Footer,
|
||||
Icon,
|
||||
Image,
|
||||
Link,
|
||||
Main,
|
||||
Notification,
|
||||
Progress,
|
||||
Radio,
|
||||
Row,
|
||||
Table,
|
||||
TableColumn,
|
||||
Tooltip,
|
||||
Upload,
|
||||
MessageBox
|
||||
Button,
|
||||
Checkbox,
|
||||
Col,
|
||||
Container,
|
||||
Footer,
|
||||
Icon,
|
||||
Image,
|
||||
Link,
|
||||
Main,
|
||||
Notification,
|
||||
Progress,
|
||||
Radio,
|
||||
Row,
|
||||
Table,
|
||||
TableColumn,
|
||||
Tooltip,
|
||||
Upload,
|
||||
MessageBox,
|
||||
} from 'element-ui';
|
||||
import 'element-ui/lib/theme-chalk/base.css';
|
||||
|
||||
|
@ -44,5 +44,5 @@ Vue.prototype.$confirm = MessageBox.confirm;
|
|||
|
||||
Vue.config.productionTip = false;
|
||||
new Vue({
|
||||
render: h => h(App),
|
||||
render: (h) => h(App),
|
||||
}).$mount('#app');
|
||||
|
|
|
@ -1,31 +1,30 @@
|
|||
/* eslint-disable no-console */
|
||||
|
||||
import {register} from 'register-service-worker'
|
||||
import { register } from 'register-service-worker';
|
||||
|
||||
if (process.env.NODE_ENV === 'production' && window.location.protocol === "https:") {
|
||||
|
||||
register(`${process.env.BASE_URL}service-worker.js`, {
|
||||
ready() {
|
||||
console.log('App is being served from cache by a service worker.')
|
||||
},
|
||||
registered() {
|
||||
console.log('Service worker has been registered.')
|
||||
},
|
||||
cached() {
|
||||
console.log('Content has been cached for offline use.')
|
||||
},
|
||||
updatefound() {
|
||||
console.log('New content is downloading.')
|
||||
},
|
||||
updated() {
|
||||
console.log('New content is available.');
|
||||
window.location.reload();
|
||||
},
|
||||
offline() {
|
||||
console.log('No internet connection found. App is running in offline mode.')
|
||||
},
|
||||
error(error) {
|
||||
console.error('Error during service worker registration:', error)
|
||||
}
|
||||
})
|
||||
if (process.env.NODE_ENV === 'production' && window.location.protocol === 'https:') {
|
||||
register(`${process.env.BASE_URL}service-worker.js`, {
|
||||
ready() {
|
||||
console.log('App is being served from cache by a service worker.');
|
||||
},
|
||||
registered() {
|
||||
console.log('Service worker has been registered.');
|
||||
},
|
||||
cached() {
|
||||
console.log('Content has been cached for offline use.');
|
||||
},
|
||||
updatefound() {
|
||||
console.log('New content is downloading.');
|
||||
},
|
||||
updated() {
|
||||
console.log('New content is available.');
|
||||
window.location.reload();
|
||||
},
|
||||
offline() {
|
||||
console.log('No internet connection found. App is running in offline mode.');
|
||||
},
|
||||
error(error) {
|
||||
console.error('Error during service worker registration:', error);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,25 +1,23 @@
|
|||
declare module "browser-id3-writer" {
|
||||
export default class ID3Writer {
|
||||
constructor(buffer: Buffer | ArrayBuffer)
|
||||
declare module 'browser-id3-writer' {
|
||||
export default class ID3Writer {
|
||||
constructor(buffer: Buffer | ArrayBuffer);
|
||||
|
||||
setFrame(name: string, value: string | object | string[])
|
||||
setFrame(name: string, value: string | object | string[]);
|
||||
|
||||
addTag(): Uint8Array
|
||||
}
|
||||
addTag(): Uint8Array;
|
||||
}
|
||||
}
|
||||
|
||||
declare module "metaflac-js" {
|
||||
export default class Metaflac {
|
||||
constructor(buffer: Buffer)
|
||||
declare module 'metaflac-js' {
|
||||
export default class Metaflac {
|
||||
constructor(buffer: Buffer);
|
||||
|
||||
setTag(field: string)
|
||||
setTag(field: string);
|
||||
|
||||
removeTag(name: string)
|
||||
removeTag(name: string);
|
||||
|
||||
importPictureFromBuffer(picture: Buffer)
|
||||
importPictureFromBuffer(picture: Buffer);
|
||||
|
||||
save(): Buffer
|
||||
}
|
||||
save(): Buffer;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,58 +1,54 @@
|
|||
export interface FileSystemGetFileOptions {
|
||||
create?: boolean
|
||||
create?: boolean;
|
||||
}
|
||||
|
||||
interface FileSystemCreateWritableOptions {
|
||||
keepExistingData?: boolean
|
||||
keepExistingData?: boolean;
|
||||
}
|
||||
|
||||
interface FileSystemRemoveOptions {
|
||||
recursive?: boolean
|
||||
recursive?: boolean;
|
||||
}
|
||||
|
||||
interface FileSystemFileHandle {
|
||||
getFile(): Promise<File>;
|
||||
getFile(): Promise<File>;
|
||||
|
||||
createWritable(options?: FileSystemCreateWritableOptions): Promise<FileSystemWritableFileStream>
|
||||
createWritable(options?: FileSystemCreateWritableOptions): Promise<FileSystemWritableFileStream>;
|
||||
}
|
||||
|
||||
enum WriteCommandType {
|
||||
write = "write",
|
||||
seek = "seek",
|
||||
truncate = "truncate",
|
||||
write = 'write',
|
||||
seek = 'seek',
|
||||
truncate = 'truncate',
|
||||
}
|
||||
|
||||
interface WriteParams {
|
||||
type: WriteCommandType
|
||||
size?: number
|
||||
position?: number
|
||||
data: BufferSource | Blob | string
|
||||
type: WriteCommandType;
|
||||
size?: number;
|
||||
position?: number;
|
||||
data: BufferSource | Blob | string;
|
||||
}
|
||||
|
||||
type FileSystemWriteChunkType = BufferSource | Blob | string | WriteParams
|
||||
type FileSystemWriteChunkType = BufferSource | Blob | string | WriteParams;
|
||||
|
||||
interface FileSystemWritableFileStream extends WritableStream {
|
||||
write(data: FileSystemWriteChunkType): Promise<undefined>
|
||||
write(data: FileSystemWriteChunkType): Promise<undefined>;
|
||||
|
||||
seek(position: number): Promise<undefined>
|
||||
seek(position: number): Promise<undefined>;
|
||||
|
||||
truncate(size: number): Promise<undefined>
|
||||
truncate(size: number): Promise<undefined>;
|
||||
|
||||
close(): Promise<undefined> // should be implemented in WritableStream
|
||||
close(): Promise<undefined>; // should be implemented in WritableStream
|
||||
}
|
||||
|
||||
|
||||
export declare interface FileSystemDirectoryHandle {
|
||||
getFileHandle(name: string, options?: FileSystemGetFileOptions): Promise<FileSystemFileHandle>
|
||||
|
||||
removeEntry(name: string, options?: FileSystemRemoveOptions): Promise<undefined>
|
||||
getFileHandle(name: string, options?: FileSystemGetFileOptions): Promise<FileSystemFileHandle>;
|
||||
|
||||
removeEntry(name: string, options?: FileSystemRemoveOptions): Promise<undefined>;
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
|
||||
showDirectoryPicker?(): Promise<FileSystemDirectoryHandle>
|
||||
}
|
||||
interface Window {
|
||||
showDirectoryPicker?(): Promise<FileSystemDirectoryHandle>;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,17 +1,15 @@
|
|||
import Vue, {VNode} from 'vue'
|
||||
import Vue, { VNode } from 'vue';
|
||||
|
||||
declare global {
|
||||
namespace JSX {
|
||||
// tslint:disable no-empty-interface
|
||||
interface Element extends VNode {
|
||||
}
|
||||
interface Element extends VNode {}
|
||||
|
||||
// tslint:disable no-empty-interface
|
||||
interface ElementClass extends Vue {
|
||||
}
|
||||
interface ElementClass extends Vue {}
|
||||
|
||||
interface IntrinsicElements {
|
||||
[elem: string]: any
|
||||
[elem: string]: any;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
declare module '*.vue' {
|
||||
import Vue from 'vue'
|
||||
export default Vue
|
||||
import Vue from 'vue';
|
||||
export default Vue;
|
||||
}
|
||||
|
|
|
@ -1,56 +1,73 @@
|
|||
import {fromByteArray as Base64Encode} from "base64-js";
|
||||
import { fromByteArray as Base64Encode } from 'base64-js';
|
||||
|
||||
export const IXAREA_API_ENDPOINT = "https://um-api.ixarea.com"
|
||||
export const IXAREA_API_ENDPOINT = 'https://um-api.ixarea.com';
|
||||
|
||||
export interface UpdateInfo {
|
||||
Found: boolean
|
||||
HttpsFound: boolean
|
||||
Version: string
|
||||
URL: string
|
||||
Detail: string
|
||||
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();
|
||||
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
|
||||
}),
|
||||
})
|
||||
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
|
||||
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();
|
||||
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
|
||||
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()
|
||||
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();
|
||||
}
|
||||
|
|
|
@ -4,74 +4,67 @@
|
|||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in https://go.dev/LICENSE.
|
||||
|
||||
import {TeaCipher} from "@/utils/tea";
|
||||
import { TeaCipher } from '@/utils/tea';
|
||||
|
||||
test('key size', () => {
|
||||
// prettier-ignore
|
||||
const testKey = new Uint8Array([
|
||||
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
|
||||
0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff,
|
||||
0x00,
|
||||
])
|
||||
expect(() => new TeaCipher(testKey.slice(0, 16))).not.toThrow();
|
||||
|
||||
test("key size", () => {
|
||||
const testKey = new Uint8Array([
|
||||
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
|
||||
0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
|
||||
0x00
|
||||
])
|
||||
expect(() => new TeaCipher(testKey.slice(0, 16)))
|
||||
.not.toThrow()
|
||||
|
||||
expect(() => new TeaCipher(testKey))
|
||||
.toThrow()
|
||||
|
||||
expect(() => new TeaCipher(testKey.slice(0, 15)))
|
||||
.toThrow()
|
||||
|
||||
})
|
||||
expect(() => new TeaCipher(testKey)).toThrow();
|
||||
|
||||
expect(() => new TeaCipher(testKey.slice(0, 15))).toThrow();
|
||||
});
|
||||
|
||||
// prettier-ignore
|
||||
const teaTests = [
|
||||
// These were sourced from https://github.com/froydnj/ironclad/blob/master/testing/test-vectors/tea.testvec
|
||||
{
|
||||
rounds: TeaCipher.numRounds,
|
||||
key: new Uint8Array([
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]),
|
||||
plainText: new Uint8Array([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]),
|
||||
cipherText: new Uint8Array([0x41, 0xea, 0x3a, 0x0a, 0x94, 0xba, 0xa9, 0x40]),
|
||||
},
|
||||
{
|
||||
rounds: TeaCipher.numRounds,
|
||||
key: new Uint8Array([
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]),
|
||||
plainText: new Uint8Array([0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]),
|
||||
cipherText: new Uint8Array([0x31, 0x9b, 0xbe, 0xfb, 0x01, 0x6a, 0xbd, 0xb2]),
|
||||
},
|
||||
{
|
||||
rounds: 16,
|
||||
key: new Uint8Array([
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]),
|
||||
plainText: new Uint8Array([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]),
|
||||
cipherText: new Uint8Array([0xed, 0x28, 0x5d, 0xa1, 0x45, 0x5b, 0x33, 0xc1]),
|
||||
},
|
||||
]
|
||||
// These were sourced from https://github.com/froydnj/ironclad/blob/master/testing/test-vectors/tea.testvec
|
||||
{
|
||||
rounds: TeaCipher.numRounds,
|
||||
key: new Uint8Array([
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
]),
|
||||
plainText: new Uint8Array([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]),
|
||||
cipherText: new Uint8Array([0x41, 0xea, 0x3a, 0x0a, 0x94, 0xba, 0xa9, 0x40]),
|
||||
},
|
||||
{
|
||||
rounds: TeaCipher.numRounds,
|
||||
key: new Uint8Array([
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
]),
|
||||
plainText: new Uint8Array([0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]),
|
||||
cipherText: new Uint8Array([0x31, 0x9b, 0xbe, 0xfb, 0x01, 0x6a, 0xbd, 0xb2]),
|
||||
},
|
||||
{
|
||||
rounds: 16,
|
||||
key: new Uint8Array([
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
]),
|
||||
plainText: new Uint8Array([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]),
|
||||
cipherText: new Uint8Array([0xed, 0x28, 0x5d, 0xa1, 0x45, 0x5b, 0x33, 0xc1]),
|
||||
},
|
||||
];
|
||||
|
||||
test("rounds", () => {
|
||||
const tt = teaTests[0];
|
||||
expect(() => new TeaCipher(tt.key, tt.rounds - 1))
|
||||
.toThrow()
|
||||
})
|
||||
test('rounds', () => {
|
||||
const tt = teaTests[0];
|
||||
expect(() => new TeaCipher(tt.key, tt.rounds - 1)).toThrow();
|
||||
});
|
||||
|
||||
test('encrypt & decrypt', () => {
|
||||
for (const tt of teaTests) {
|
||||
const c = new TeaCipher(tt.key, tt.rounds);
|
||||
|
||||
test("encrypt & decrypt", () => {
|
||||
for (const tt of teaTests) {
|
||||
const c = new TeaCipher(tt.key, tt.rounds)
|
||||
const buf = new Uint8Array(8);
|
||||
const bufView = new DataView(buf.buffer);
|
||||
|
||||
const buf = new Uint8Array(8)
|
||||
const bufView = new DataView(buf.buffer)
|
||||
|
||||
c.encrypt(bufView, new DataView(tt.plainText.buffer))
|
||||
expect(buf).toStrictEqual(tt.cipherText)
|
||||
|
||||
c.decrypt(bufView, new DataView(tt.cipherText.buffer))
|
||||
expect(buf).toStrictEqual(tt.plainText)
|
||||
}
|
||||
})
|
||||
c.encrypt(bufView, new DataView(tt.plainText.buffer));
|
||||
expect(buf).toStrictEqual(tt.cipherText);
|
||||
|
||||
c.decrypt(bufView, new DataView(tt.cipherText.buffer));
|
||||
expect(buf).toStrictEqual(tt.plainText);
|
||||
}
|
||||
});
|
||||
|
|
100
src/utils/tea.ts
100
src/utils/tea.ts
|
@ -15,68 +15,66 @@
|
|||
// where compatibility with legacy systems, not security, is the goal.
|
||||
|
||||
export class TeaCipher {
|
||||
// BlockSize is the size of a TEA block, in bytes.
|
||||
static readonly BlockSize = 8;
|
||||
// BlockSize is the size of a TEA block, in bytes.
|
||||
static readonly BlockSize = 8;
|
||||
|
||||
// KeySize is the size of a TEA key, in bytes.
|
||||
static readonly KeySize = 16;
|
||||
// KeySize is the size of a TEA key, in bytes.
|
||||
static readonly KeySize = 16;
|
||||
|
||||
// delta is the TEA key schedule constant.
|
||||
static readonly delta = 0x9e3779b9;
|
||||
// delta is the TEA key schedule constant.
|
||||
static readonly delta = 0x9e3779b9;
|
||||
|
||||
// numRounds 64 is the standard number of rounds in TEA.
|
||||
static readonly numRounds = 64;
|
||||
// numRounds 64 is the standard number of rounds in TEA.
|
||||
static readonly numRounds = 64;
|
||||
|
||||
k0: number
|
||||
k1: number
|
||||
k2: number
|
||||
k3: number
|
||||
rounds: number
|
||||
k0: number;
|
||||
k1: number;
|
||||
k2: number;
|
||||
k3: number;
|
||||
rounds: number;
|
||||
|
||||
constructor(key: Uint8Array, rounds: number = TeaCipher.numRounds) {
|
||||
if (key.length != 16) {
|
||||
throw Error("incorrect key size")
|
||||
}
|
||||
if ((rounds & 1) != 0) {
|
||||
throw Error("odd number of rounds specified")
|
||||
}
|
||||
|
||||
const k = new DataView(key.buffer)
|
||||
this.k0 = k.getUint32(0, false)
|
||||
this.k1 = k.getUint32(4, false)
|
||||
this.k2 = k.getUint32(8, false)
|
||||
this.k3 = k.getUint32(12, false)
|
||||
this.rounds = rounds
|
||||
constructor(key: Uint8Array, rounds: number = TeaCipher.numRounds) {
|
||||
if (key.length != 16) {
|
||||
throw Error('incorrect key size');
|
||||
}
|
||||
if ((rounds & 1) != 0) {
|
||||
throw Error('odd number of rounds specified');
|
||||
}
|
||||
|
||||
const k = new DataView(key.buffer);
|
||||
this.k0 = k.getUint32(0, false);
|
||||
this.k1 = k.getUint32(4, false);
|
||||
this.k2 = k.getUint32(8, false);
|
||||
this.k3 = k.getUint32(12, false);
|
||||
this.rounds = rounds;
|
||||
}
|
||||
|
||||
encrypt(dst: DataView, src: DataView) {
|
||||
encrypt(dst: DataView, src: DataView) {
|
||||
let v0 = src.getUint32(0, false);
|
||||
let v1 = src.getUint32(4, false);
|
||||
|
||||
let v0 = src.getUint32(0, false)
|
||||
let v1 = src.getUint32(4, false)
|
||||
|
||||
let sum = 0
|
||||
for (let i = 0; i < this.rounds / 2; i++) {
|
||||
sum = sum + TeaCipher.delta
|
||||
v0 += ((v1 << 4) + this.k0) ^ (v1 + sum) ^ ((v1 >>> 5) + this.k1)
|
||||
v1 += ((v0 << 4) + this.k2) ^ (v0 + sum) ^ ((v0 >>> 5) + this.k3)
|
||||
}
|
||||
|
||||
dst.setUint32(0, v0, false)
|
||||
dst.setUint32(4, v1, false)
|
||||
let sum = 0;
|
||||
for (let i = 0; i < this.rounds / 2; i++) {
|
||||
sum = sum + TeaCipher.delta;
|
||||
v0 += ((v1 << 4) + this.k0) ^ (v1 + sum) ^ ((v1 >>> 5) + this.k1);
|
||||
v1 += ((v0 << 4) + this.k2) ^ (v0 + sum) ^ ((v0 >>> 5) + this.k3);
|
||||
}
|
||||
|
||||
decrypt(dst: DataView, src: DataView) {
|
||||
let v0 = src.getUint32(0, false)
|
||||
let v1 = src.getUint32(4, false)
|
||||
dst.setUint32(0, v0, false);
|
||||
dst.setUint32(4, v1, false);
|
||||
}
|
||||
|
||||
let sum = TeaCipher.delta * this.rounds / 2
|
||||
for (let i = 0; i < this.rounds / 2; i++) {
|
||||
v1 -= ((v0 << 4) + this.k2) ^ (v0 + sum) ^ ((v0 >>> 5) + this.k3)
|
||||
v0 -= ((v1 << 4) + this.k0) ^ (v1 + sum) ^ ((v1 >>> 5) + this.k1)
|
||||
sum -= TeaCipher.delta
|
||||
}
|
||||
dst.setUint32(0, v0, false)
|
||||
dst.setUint32(4, v1, false)
|
||||
decrypt(dst: DataView, src: DataView) {
|
||||
let v0 = src.getUint32(0, false);
|
||||
let v1 = src.getUint32(4, false);
|
||||
|
||||
let sum = (TeaCipher.delta * this.rounds) / 2;
|
||||
for (let i = 0; i < this.rounds / 2; i++) {
|
||||
v1 -= ((v0 << 4) + this.k2) ^ (v0 + sum) ^ ((v0 >>> 5) + this.k3);
|
||||
v0 -= ((v1 << 4) + this.k0) ^ (v1 + sum) ^ ((v1 >>> 5) + this.k1);
|
||||
sum -= TeaCipher.delta;
|
||||
}
|
||||
dst.setUint32(0, v0, false);
|
||||
dst.setUint32(4, v1, false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,79 +1,80 @@
|
|||
import {DecryptResult} from "@/decrypt/entity";
|
||||
import {FileSystemDirectoryHandle} from "@/shims-fs";
|
||||
import { DecryptResult } from '@/decrypt/entity';
|
||||
import { FileSystemDirectoryHandle } from '@/shims-fs';
|
||||
|
||||
export enum FilenamePolicy {
|
||||
ArtistAndTitle,
|
||||
TitleOnly,
|
||||
TitleAndArtist,
|
||||
SameAsOriginal,
|
||||
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 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}`;
|
||||
}
|
||||
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()
|
||||
|
||||
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();
|
||||
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);
|
||||
}
|
||||
URL.revokeObjectURL(data.file);
|
||||
if (data.picture?.startsWith('blob:')) {
|
||||
URL.revokeObjectURL(data.picture);
|
||||
}
|
||||
}
|
||||
|
||||
export class DecryptQueue {
|
||||
private readonly pending: (() => Promise<void>)[];
|
||||
private readonly pending: (() => Promise<void>)[];
|
||||
|
||||
constructor() {
|
||||
this.pending = []
|
||||
}
|
||||
constructor() {
|
||||
this.pending = [];
|
||||
}
|
||||
|
||||
queue(fn: () => Promise<void>) {
|
||||
this.pending.push(fn)
|
||||
this.consume()
|
||||
}
|
||||
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)
|
||||
}
|
||||
private consume() {
|
||||
const fn = this.pending.shift();
|
||||
if (fn)
|
||||
fn()
|
||||
.then(() => this.consume)
|
||||
.catch(console.error);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import {expose} from "threads/worker";
|
||||
import {CommonDecrypt} from "@/decrypt/common";
|
||||
import { expose } from 'threads/worker';
|
||||
import { CommonDecrypt } from '@/decrypt/common';
|
||||
|
||||
expose(CommonDecrypt)
|
||||
expose(CommonDecrypt);
|
||||
|
|
|
@ -1,157 +1,156 @@
|
|||
<template>
|
||||
<div>
|
||||
<file-selector @error="showFail" @success="showSuccess"/>
|
||||
<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>
|
||||
<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"/>
|
||||
<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"
|
||||
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
|
||||
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();
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
tableData: [],
|
||||
playing_url: "",
|
||||
playing_auto: false,
|
||||
filename_policy: FilenamePolicy.ArtistAndTitle,
|
||||
instant_save: false,
|
||||
FilenamePolicies,
|
||||
dir: null
|
||||
},
|
||||
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);
|
||||
},
|
||||
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()
|
||||
const test_filename = "__unlock_music_write_test.txt"
|
||||
await this.dir.getFileHandle(test_filename, {create: true})
|
||||
await this.dir.removeEntry(test_filename)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
}
|
||||
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();
|
||||
const test_filename = '__unlock_music_write_test.txt';
|
||||
await this.dir.getFileHandle(test_filename, { create: true });
|
||||
await this.dir.removeEntry(test_filename);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
|
|
Reference in New Issue