This commit is contained in:
Emmm Monster 2021-05-24 23:48:52 +08:00
parent c7e5dfb4c4
commit 759c1bd87e
No known key found for this signature in database
GPG Key ID: C98279C83FB50DB9
9 changed files with 230 additions and 164 deletions

View File

@ -1,41 +1,12 @@
<template> <template>
<el-container id="app"> <el-container id="app">
<el-main> <el-main>
<file-selector @error="showFail" @success="showSuccess"/> <Home/>
<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/>
<PreviewTable :filename_format="download_format" :table-data="tableData"
@music_changed="changePlaying"></PreviewTable>
</el-main> </el-main>
<el-footer id="app-footer"> <el-footer id="app-footer">
<el-row> <el-row>
<a href="https://github.com/ix64/unlock-music" target="_blank">音乐解锁</a> <a href="https://github.com/ix64/unlock-music" target="_blank">音乐解锁</a>({{ version }})
(v{{ version }})移除已购音乐的加密保护 移除已购音乐的加密保护
<a href="https://github.com/ix64/unlock-music/wiki/使用提示" target="_blank">使用提示</a> <a href="https://github.com/ix64/unlock-music/wiki/使用提示" target="_blank">使用提示</a>
</el-row> </el-row>
<el-row> <el-row>
@ -51,38 +22,30 @@
</el-row> </el-row>
</el-footer> </el-footer>
</el-container> </el-container>
</template> </template>
<script> <script>
import FileSelector from "./component/FileSelector" import FileSelector from "@/component/FileSelector"
import PreviewTable from "./component/PreviewTable" import PreviewTable from "@/component/PreviewTable"
import {DownloadBlobMusic, RemoveBlobMusic} from "./component/utils" import config from "@/../package.json"
import config from "../package" import Home from "@/view/Home";
import {IXAREA_API_ENDPOINT} from "@/decrypt/utils"; import {checkUpdate} from "@/utils/api";
export default { export default {
name: 'app', name: 'app',
components: { components: {
FileSelector, FileSelector,
PreviewTable PreviewTable,
Home
}, },
data() { data() {
return { return {
version: config.version, version: config.version,
activeIndex: '1',
tableData: [],
playing_url: "",
playing_auto: false,
download_format: '1',
instant_download: false,
} }
}, },
created() { created() {
this.$nextTick(function () { this.$nextTick(() => this.finishLoad());
this.finishLoad();
});
}, },
methods: { methods: {
async finishLoad() { async finishLoad() {
@ -90,20 +53,15 @@ export default {
if (!!mask) mask.remove(); if (!!mask) mask.remove();
let updateInfo; let updateInfo;
try { try {
const resp = await fetch(IXAREA_API_ENDPOINT + "/music/app-version", { updateInfo = await checkUpdate(this.version)
method: "POST", headers: {"Content-Type": "application/json"},
body: JSON.stringify({"Version": this.version})
});
updateInfo = await resp.json();
} catch (e) { } catch (e) {
console.warn("check version info failed", e)
} }
if ((!!updateInfo && process.env.NODE_ENV === 'production') && (!!updateInfo.HttpsFound || if ((updateInfo && process.env.NODE_ENV === 'production') && (updateInfo.HttpsFound ||
(!!updateInfo.Found && window.location.protocol !== "https:"))) { (updateInfo.Found && window.location.protocol !== "https:"))) {
this.$notify.warning({ this.$notify.warning({
title: '发现更新', title: '发现更新',
message: '发现新版本 v' + updateInfo.Version + message: `发现新版本 v${updateInfo.Version}<br/>更新详情:${updateInfo.Detail}<br/> <a target="_blank" href="${updateInfo.URL}">获取更新</a>`,
'<br/>更新详情:' + updateInfo.Detail +
'<br/><a target="_blank" href="' + updateInfo.URL + '">获取更新</a>',
dangerouslyUseHTMLString: true, dangerouslyUseHTMLString: true,
duration: 15000, duration: 15000,
position: 'top-left' position: 'top-left'
@ -111,65 +69,12 @@ export default {
} else { } else {
this.$notify.info({ this.$notify.info({
title: '离线使用', title: '离线使用',
message: '我们使用PWA技术无网络也能使用' + message: `我们使用PWA技术无网络也能使用<br/>最近更新:${config.updateInfo}<br/><a target="_blank" href="https://github.com/ix64/unlock-music/wiki/使用提示">使用提示</a>`,
'<br/>最近更新:' + config.updateInfo +
'<br/><a target="_blank" href="https://github.com/ix64/unlock-music/wiki/使用提示">使用提示</a>',
dangerouslyUseHTMLString: true, dangerouslyUseHTMLString: true,
duration: 10000, duration: 10000,
position: 'top-left' position: 'top-left'
}); });
} }
},
showSuccess(data) {
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)]);
}
},
showFail(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", 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);
} }
}, },
} }

View File

@ -22,7 +22,7 @@
<script> <script>
import {spawn, Worker, Pool} from "threads" import {spawn, Worker, Pool} from "threads"
import {CommonDecrypt} from "@/decrypt/common.ts"; import {CommonDecrypt} from "@/decrypt/common.ts";
import {DecryptQueue} from "@/component/utils"; import {DecryptQueue} from "@/utils/utils";
export default { export default {
name: "FileSelector", name: "FileSelector",
@ -42,10 +42,10 @@ export default {
} }
}, },
mounted() { mounted() {
if (window.Worker) { if (window.Worker && process.env.NODE_ENV === 'production') {
console.log("Using Worker Pool") console.log("Using Worker Pool")
this.queue = Pool( this.queue = Pool(
() => spawn(new Worker('@/component/worker.ts')), () => spawn(new Worker('@/utils/worker.ts')),
navigator.hardwareConcurrency || 1 navigator.hardwareConcurrency || 1
) )
} else { } else {
@ -64,7 +64,7 @@ export default {
this.$emit("success", await dec(file)); this.$emit("success", await dec(file));
} catch (e) { } catch (e) {
console.error(e) console.error(e)
this.$emit("error", file) this.$emit("error", e, file.name)
} finally { } finally {
this.task_finished++ this.task_finished++
} }

View File

@ -11,22 +11,22 @@
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="歌曲"> <el-table-column label="歌曲">
<template slot-scope="scope"> <template #default="scope">
<span>{{ scope.row.title }}</span> <span>{{ scope.row.title }}</span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="歌手"> <el-table-column label="歌手">
<template slot-scope="scope"> <template #default="scope">
<p>{{ scope.row.artist }}</p> <p>{{ scope.row.artist }}</p>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="专辑"> <el-table-column label="专辑">
<template slot-scope="scope"> <template #default="scope">
<p>{{ scope.row.album }}</p> <p>{{ scope.row.album }}</p>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="操作"> <el-table-column label="操作">
<template slot-scope="scope"> <template #default="scope">
<el-button circle <el-button circle
icon="el-icon-video-play" type="success" @click="handlePlay(scope.$index, scope.row)"> icon="el-icon-video-play" type="success" @click="handlePlay(scope.$index, scope.row)">
</el-button> </el-button>
@ -42,25 +42,25 @@
</template> </template>
<script> <script>
import {DownloadBlobMusic, RemoveBlobMusic} from '@/component/utils' import {DownloadBlobMusic, RemoveBlobMusic} from '@/utils/utils'
export default { export default {
name: "PreviewTable", name: "PreviewTable",
props: { props: {
tableData: {type: Array, required: true}, tableData: {type: Array, required: true},
filename_format: {type: String, required: true} policy: {type: Number, required: true}
}, },
methods: { methods: {
handlePlay(index, row) { handlePlay(index, row) {
this.$emit("music_changed", row.file); this.$emit("play", row.file);
}, },
handleDelete(index, row) { handleDelete(index, row) {
RemoveBlobMusic(row); RemoveBlobMusic(row);
this.tableData.splice(index, 1); this.tableData.splice(index, 1);
}, },
handleDownload(row) { handleDownload(row) {
DownloadBlobMusic(row, this.download_format) DownloadBlobMusic(row, this.policy)
}, },
} }
} }

View File

@ -1,11 +1,11 @@
import {QmcMask, QmcMaskDetectMflac, QmcMaskDetectMgg, QmcMaskGetDefault} from "./qmcMask"; import {QmcMask, QmcMaskDetectMflac, QmcMaskDetectMgg, QmcMaskGetDefault} from "./qmcMask";
import {fromByteArray as Base64Encode, toByteArray as Base64Decode} from 'base64-js' import {toByteArray as Base64Decode} from 'base64-js'
import { import {
AudioMimeType, AudioMimeType,
GetArrayBuffer, GetArrayBuffer,
GetCoverFromFile, GetCoverFromFile,
GetImageFromURL, GetImageFromURL,
GetMetaFromFile, IXAREA_API_ENDPOINT, GetMetaFromFile,
SniffAudioExt, WriteMetaToFlac, WriteMetaToMp3 SniffAudioExt, WriteMetaToFlac, WriteMetaToMp3
} from "@/decrypt/utils.ts"; } from "@/decrypt/utils.ts";
import {parseBlob as metaParseBlob} from "music-metadata-browser"; import {parseBlob as metaParseBlob} from "music-metadata-browser";
@ -13,6 +13,7 @@ import {parseBlob as metaParseBlob} from "music-metadata-browser";
import iconv from "iconv-lite"; import iconv from "iconv-lite";
import {DecryptResult} from "@/decrypt/entity"; import {DecryptResult} from "@/decrypt/entity";
import {queryAlbumCover, queryKeyInfo, reportKeyUsage} from "@/utils/api";
interface Handler { interface Handler {
ext: string ext: string
@ -51,7 +52,7 @@ export async function Decrypt(file: File, raw_filename: string, raw_ext: string)
audioData = fileData.slice(0, keyPos); audioData = fileData.slice(0, keyPos);
seed = handler.handler(audioData); seed = handler.handler(audioData);
keyData = fileData.slice(keyPos, keyPos + keyLen); keyData = fileData.slice(keyPos, keyPos + keyLen);
if (!seed) seed = await queryKeyInfo(keyData, raw_filename, raw_ext); if (!seed) seed = await queryKey(keyData, raw_filename, raw_ext);
if (!seed) throw raw_ext + "格式仅提供实验性支持"; if (!seed) throw raw_ext + "格式仅提供实验性支持";
} else { } else {
audioData = fileData; audioData = fileData;
@ -77,12 +78,12 @@ export async function Decrypt(file: File, raw_filename: string, raw_ext: string)
const info = GetMetaFromFile(raw_filename, musicMeta.common.title, musicMeta.common.artist) const info = GetMetaFromFile(raw_filename, musicMeta.common.title, musicMeta.common.artist)
if (keyData) reportKeyUsage(keyData, seed.getMatrix128(), if (keyData) reportKeyUsage(keyData, seed.getMatrix128(),
raw_filename, raw_ext, info.title, info.artist, musicMeta.common.album); raw_filename, raw_ext, info.title, info.artist, musicMeta.common.album).then().catch();
let imgUrl = GetCoverFromFile(musicMeta); let imgUrl = GetCoverFromFile(musicMeta);
if (!imgUrl) { if (!imgUrl) {
imgUrl = await queryAlbumCoverImage(info.title, info.artist, musicMeta.common.album); imgUrl = await getCoverImage(info.title, info.artist, musicMeta.common.album);
if (imgUrl !== "") { if (imgUrl) {
const imageInfo = await GetImageFromURL(imgUrl); const imageInfo = await GetImageFromURL(imgUrl);
if (imageInfo) { if (imageInfo) {
imgUrl = imageInfo.url imgUrl = imageInfo.url
@ -115,42 +116,22 @@ export async function Decrypt(file: File, raw_filename: string, raw_ext: string)
} }
function reportKeyUsage(keyData: Uint8Array, maskData: number[], filename: string, format: string, title: string, artist?: string, album?: string) { async function queryKey(keyData: Uint8Array, filename: string, format: string): Promise<QmcMask | undefined> {
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: Uint8Array, filename: string, format: string) {
try { try {
const resp = await fetch(IXAREA_API_ENDPOINT + "/qmcmask/query", { const data = await queryKeyInfo(keyData, filename, format)
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 new QmcMask(Base64Decode(data.Matrix44)); return new QmcMask(Base64Decode(data.Matrix44));
} catch (e) { } catch (e) {
console.warn(e); console.warn(e);
} }
} }
async function queryAlbumCoverImage(title: string, artist?: string, album?: string) { async function getCoverImage(title: string, artist?: string, album?: string): Promise<string> {
const song_query_url = "https://stats.ixarea.com/apis" + "/music/qq-cover" const song_query_url = "https://stats.ixarea.com/apis" + "/music/qq-cover"
try { try {
const params = new URLSearchParams([["Title", title], ["Artist", artist ?? ""], ["Album", album ?? ""]]) const data = await queryAlbumCover(title, artist, album)
const resp = await fetch(`${song_query_url}?${params.toString()}`) return `${song_query_url}/${data.Type}/${data.Id}`
if (resp.ok) {
let data = await resp.json();
return song_query_url + "/" + data.Type + "/" + data.Id
}
} catch (e) { } catch (e) {
console.warn(e); console.warn(e);
} }
return ""; return ""
} }

View File

@ -21,8 +21,6 @@ export const AudioMimeType: { [key: string]: string } = {
wav: "audio/x-wav" wav: "audio/x-wav"
}; };
export const IXAREA_API_ENDPOINT = "https://stats.ixarea.com/apis"
export function BytesHasPrefix(data: Uint8Array, prefix: number[]): boolean { export function BytesHasPrefix(data: Uint8Array, prefix: number[]): boolean {
if (prefix.length > data.length) return false if (prefix.length > data.length) return false

56
src/utils/api.ts Normal file
View File

@ -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()
}

View File

@ -1,20 +1,35 @@
import {DecryptResult} from "@/decrypt/entity"; import {DecryptResult} from "@/decrypt/entity";
export function DownloadBlobMusic(data: DecryptResult, format: string) {//todo: use enum 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 DownloadBlobMusic(data: DecryptResult, policy: FilenamePolicy) {
const a = document.createElement('a'); const a = document.createElement('a');
a.href = data.file; a.href = data.file;
switch (format) { switch (policy) {
default: default:
case "1": case FilenamePolicy.ArtistAndTitle:
a.download = data.artist + " - " + data.title + "." + data.ext; a.download = data.artist + " - " + data.title + "." + data.ext;
break; break;
case "2": case FilenamePolicy.TitleOnly:
a.download = data.title + "." + data.ext; a.download = data.title + "." + data.ext;
break; break;
case "3": case FilenamePolicy.TitleAndArtist:
a.download = data.title + " - " + data.artist + "." + data.ext; a.download = data.title + " - " + data.artist + "." + data.ext;
break; break;
case "4": case FilenamePolicy.SameAsOriginal:
a.download = data.rawFilename + "." + data.ext; a.download = data.rawFilename + "." + data.ext;
break; break;
} }

111
src/view/Home.vue Normal file
View File

@ -0,0 +1,111 @@
<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">
当您使用此工具进行大量文件解锁的时候建议开启此选项<br/>
开启后解锁结果将不会存留于浏览器中防止内存不足
</div>
<el-checkbox v-model="instant_download" 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" @play="changePlaying"/>
</div>
</template>
<script>
import FileSelector from "../component/FileSelector"
import PreviewTable from "../component/PreviewTable"
import {DownloadBlobMusic, FilenamePolicy, FilenamePolicies, RemoveBlobMusic} from "@/utils/utils"
export default {
name: 'Home',
components: {
FileSelector,
PreviewTable
},
data() {
return {
activeIndex: '1',
tableData: [],
playing_url: "",
playing_auto: false,
filename_policy: FilenamePolicy.ArtistAndTitle,
instant_download: false,
FilenamePolicies
}
},
methods: {
showSuccess(data) {
if (this.instant_download) {
DownloadBlobMusic(data, this.filename_policy);
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", 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.filename_policy);
index++;
} else {
clearInterval(c);
}
}, 300);
}
},
}
</script>