Browse Source

Optimize Import

20230320
MengYX 5 years ago
parent
commit
10f09958c4
No known key found for this signature in database GPG Key ID: E63F9C7303E8F604
  1. 1
      src/component/preview.vue
  2. 2
      src/component/upload.vue
  3. 11
      src/decrypt/ncm.js
  4. 22
      src/decrypt/qmc.js
  5. 12
      src/decrypt/raw.js
  6. 16
      src/decrypt/tm.js
  7. 2
      src/decrypt/util.js
  8. 17
      src/main.js

1
src/component/preview.vue

@ -10,6 +10,7 @@
</el-image> </el-image>
</template> </template>
</el-table-column> </el-table-column>
<!--todo: Check sortable-->
<el-table-column label="歌曲" sortable> <el-table-column label="歌曲" sortable>
<template slot-scope="scope"> <template slot-scope="scope">
<span style="margin-left: 10px">{{ scope.row.title }}</span> <span style="margin-left: 10px">{{ scope.row.title }}</span>

2
src/component/upload.vue

@ -27,10 +27,10 @@
}, },
mounted() { mounted() {
if (document.location.host !== "" && process.env.NODE_ENV === 'production') { if (document.location.host !== "" && process.env.NODE_ENV === 'production') {
//todo: Fail on Hot Reload
const worker = require("workerize-loader!../decrypt/common"); const worker = require("workerize-loader!../decrypt/common");
this.thread_num = navigator.hardwareConcurrency || 1; this.thread_num = navigator.hardwareConcurrency || 1;
for (let i = 0; i < this.thread_num; i++) { for (let i = 0; i < this.thread_num; i++) {
//todo: Optimize for first loading
// noinspection JSValidateTypes,JSUnresolvedVariable // noinspection JSValidateTypes,JSUnresolvedVariable
this.workers.push(worker().CommonDecrypt); this.workers.push(worker().CommonDecrypt);
this.idle_workers.push(i); this.idle_workers.push(i);

11
src/decrypt/ncm.js

@ -1,15 +1,12 @@
const CryptoJS = require("crypto-js"); const CryptoJS = require("crypto-js");
const ID3Writer = require("browser-id3-writer"); const ID3Writer = require("browser-id3-writer");
const util = require("./util");
const CORE_KEY = CryptoJS.enc.Hex.parse("687a4852416d736f356b496e62617857"); const CORE_KEY = CryptoJS.enc.Hex.parse("687a4852416d736f356b496e62617857");
const META_KEY = CryptoJS.enc.Hex.parse("2331346C6A6B5F215C5D2630553C2728"); const META_KEY = CryptoJS.enc.Hex.parse("2331346C6A6B5F215C5D2630553C2728");
import {AudioMimeType, GetArrayBuffer} from "./util"
export async function Decrypt(file) {
export {Decrypt}; const fileBuffer = await GetArrayBuffer(file);
async function Decrypt(file) {
const fileBuffer = await util.GetArrayBuffer(file);
const dataView = new DataView(fileBuffer); const dataView = new DataView(fileBuffer);
if (dataView.getUint32(0, true) !== 0x4e455443 || if (dataView.getUint32(0, true) !== 0x4e455443 ||
@ -38,7 +35,7 @@ async function Decrypt(file) {
musicMeta.format = "mp3"; musicMeta.format = "mp3";
} }
} }
const mime = util.AudioMimeType[musicMeta.format]; const mime = AudioMimeType[musicMeta.format];
const artists = []; const artists = [];
musicMeta.artist.forEach(arr => { musicMeta.artist.forEach(arr => {

22
src/decrypt/qmc.js

@ -1,18 +1,18 @@
import {AudioMimeType, GetArrayBuffer, GetCoverURL, GetFileInfo} from "./util"; import {AudioMimeType, GetArrayBuffer, GetCoverURL, GetFileInfo} from "./util";
import * as mask from "./qmcMask" import {QmcMaskCreate58, QmcMaskGetDefault, QmcMaskDetectMgg, QmcMaskDetectMflac} from "./qmcMask";
const musicMetadata = require("music-metadata-browser"); const musicMetadata = require("music-metadata-browser");
const HandlerMap = { const HandlerMap = {
"mgg": {handler: mask.QmcMaskDetectMgg, ext: "ogg", detect: true}, "mgg": {handler: QmcMaskDetectMgg, ext: "ogg", detect: true},
"mflac": {handler: mask.QmcMaskDetectMflac, ext: "flac", detect: true}, "mflac": {handler: QmcMaskDetectMflac, ext: "flac", detect: true},
"qmc0": {handler: mask.QmcMaskGetDefault, ext: "mp3", detect: false}, "qmc0": {handler: QmcMaskGetDefault, ext: "mp3", detect: false},
"qmc3": {handler: mask.QmcMaskGetDefault, ext: "mp3", detect: false}, "qmc3": {handler: QmcMaskGetDefault, ext: "mp3", detect: false},
"qmcogg": {handler: mask.QmcMaskGetDefault, ext: "ogg", detect: false}, "qmcogg": {handler: QmcMaskGetDefault, ext: "ogg", detect: false},
"qmcflac": {handler: mask.QmcMaskGetDefault, ext: "flac", detect: false}, "qmcflac": {handler: QmcMaskGetDefault, ext: "flac", detect: false},
"bkcmp3": {handler: mask.QmcMaskGetDefault, ext: "mp3", detect: false}, "bkcmp3": {handler: QmcMaskGetDefault, ext: "mp3", detect: false},
"bkcflac": {handler: mask.QmcMaskGetDefault, ext: "flac", detect: false}, "bkcflac": {handler: QmcMaskGetDefault, ext: "flac", detect: false},
"tkm": {handler: mask.QmcMaskGetDefault, ext: "m4a", detect: false} "tkm": {handler: QmcMaskGetDefault, ext: "m4a", detect: false}
}; };
//todo: use header to detect media type //todo: use header to detect media type
@ -72,7 +72,7 @@ async function queryKeyInfo(keyData, filename, format) {
body: JSON.stringify({Format: format, Key: Array.from(keyData), Filename: filename}), body: JSON.stringify({Format: format, Key: Array.from(keyData), Filename: filename}),
}); });
let data = await resp.json(); let data = await resp.json();
return mask.QmcMaskCreate58(data.Matrix58, data.Super58A, data.Super58B); return QmcMaskCreate58(data.Matrix58, data.Super58A, data.Super58B);
} catch (e) { } catch (e) {
} }
} }

12
src/decrypt/raw.js

@ -1,19 +1,17 @@
const musicMetadata = require("music-metadata-browser"); const musicMetadata = require("music-metadata-browser");
const util = require("./util"); import {GetCoverURL, GetFileInfo, AudioMimeType} from "./util";
export {Decrypt}
export async function Decrypt(file, raw_filename, raw_ext) {
async function Decrypt(file, raw_filename, raw_ext) {
const tag = await musicMetadata.parseBlob(file); const tag = await musicMetadata.parseBlob(file);
const info = util.GetFileInfo(tag.common.artist, tag.common.title, raw_filename); const info = GetFileInfo(tag.common.artist, tag.common.title, raw_filename);
return { return {
status: true, status: true,
title: info.title, title: info.title,
artist: info.artist, artist: info.artist,
ext: raw_ext, ext: raw_ext,
album: tag.common.album, album: tag.common.album,
picture: util.GetCoverURL(tag), picture: GetCoverURL(tag),
file: URL.createObjectURL(file), file: URL.createObjectURL(file),
mime: util.AudioMimeType[raw_ext] mime: AudioMimeType[raw_ext]
} }
} }

16
src/decrypt/tm.js

@ -1,14 +1,14 @@
const rawDecrypt = require("./raw"); import {Decrypt as RawDecrypt} from "./raw";
const util = require("./util"); import {GetArrayBuffer} from "./util";
export {Decrypt}
const header = [0x00, 0x00, 0x00, 0x20, 0x66, 0x74, 0x79, 0x70];
async function Decrypt(file, raw_filename) { const TM_HEADER = [0x00, 0x00, 0x00, 0x20, 0x66, 0x74, 0x79, 0x70];
const fileBuffer = await util.GetArrayBuffer(file);
export async function Decrypt(file, raw_filename) {
const fileBuffer = await GetArrayBuffer(file);
const audioData = new Uint8Array(fileBuffer); const audioData = new Uint8Array(fileBuffer);
for (let cur = 0; cur < 8; ++cur) { for (let cur = 0; cur < 8; ++cur) {
audioData[cur] = header[cur]; audioData[cur] = TM_HEADER[cur];
} }
const musicData = new Blob([audioData], {type: "audio/mp4"}); const musicData = new Blob([audioData], {type: "audio/mp4"});
return await rawDecrypt.Decrypt(musicData, raw_filename, "m4a") return await RawDecrypt(musicData, raw_filename, "m4a")
} }

2
src/decrypt/util.js

@ -1,10 +1,10 @@
export const FLAC_HEADER = [0x66, 0x4C, 0x61, 0x43, 0x00];
export const AudioMimeType = { export const AudioMimeType = {
mp3: "audio/mpeg", mp3: "audio/mpeg",
flac: "audio/flac", flac: "audio/flac",
m4a: "audio/mp4", m4a: "audio/mp4",
ogg: "audio/ogg" ogg: "audio/ogg"
}; };
export const FLAC_HEADER = [0x66, 0x4C, 0x61, 0x43, 0x00];
// Also a new draft API: blob.arrayBuffer() // Also a new draft API: blob.arrayBuffer()
export async function GetArrayBuffer(blobObject) { export async function GetArrayBuffer(blobObject) {

17
src/main.js

@ -2,21 +2,9 @@ import Vue from 'vue'
import App from './App.vue' import App from './App.vue'
import './registerServiceWorker' import './registerServiceWorker'
import { import {
Button, Button, Col, Container, Footer, Icon, Image, Link, Main,
Col, Row, Table, TableColumn, Upload, Radio, Checkbox,
Container,
Footer,
Icon,
Image,
Link,
Main,
Notification, Notification,
Row,
Table,
TableColumn,
Upload,
Radio,
Checkbox
} from 'element-ui'; } from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css' import 'element-ui/lib/theme-chalk/index.css'
@ -36,7 +24,6 @@ Vue.use(Checkbox);
Vue.use(Radio); Vue.use(Radio);
Vue.prototype.$notify = Notification; Vue.prototype.$notify = Notification;
// only if your build system can import css, otherwise import it wherever you would import your css.
Vue.config.productionTip = false; Vue.config.productionTip = false;
new Vue({ new Vue({

Loading…
Cancel
Save