|
|
@ -1,4 +1,4 @@
|
|
|
|
import {AudioMimeType, BytesHasPrefix, GetArrayBuffer, SniffAudioExt} from "@/decrypt/utils.ts";
|
|
|
|
import {AudioMimeType, BytesHasPrefix, GetArrayBuffer, GetMetaFromFile, SniffAudioExt} from "@/decrypt/utils.ts";
|
|
|
|
|
|
|
|
|
|
|
|
const CryptoJS = require("crypto-js");
|
|
|
|
const CryptoJS = require("crypto-js");
|
|
|
|
const MetaFlac = require('metaflac-js');
|
|
|
|
const MetaFlac = require('metaflac-js');
|
|
|
@ -9,7 +9,6 @@ const musicMetadata = require("music-metadata-browser");
|
|
|
|
import jimp from 'jimp';
|
|
|
|
import jimp from 'jimp';
|
|
|
|
|
|
|
|
|
|
|
|
import {
|
|
|
|
import {
|
|
|
|
GetFileInfo,
|
|
|
|
|
|
|
|
GetWebImage,
|
|
|
|
GetWebImage,
|
|
|
|
WriteMp3Meta
|
|
|
|
WriteMp3Meta
|
|
|
|
} from "./util"
|
|
|
|
} from "./util"
|
|
|
@ -36,11 +35,10 @@ export async function Decrypt(file, raw_filename, _) {
|
|
|
|
|
|
|
|
|
|
|
|
const artists = [];
|
|
|
|
const artists = [];
|
|
|
|
if (!!musicMeta.artist) musicMeta.artist.forEach(arr => artists.push(arr[0]));
|
|
|
|
if (!!musicMeta.artist) musicMeta.artist.forEach(arr => artists.push(arr[0]));
|
|
|
|
const info = GetFileInfo(artists.join("; "), musicMeta.musicName, raw_filename);
|
|
|
|
const info = GetMetaFromFile(raw_filename, musicMeta.musicName, artists.join("; "))
|
|
|
|
if (artists.length === 0) artists.push(info.artist);
|
|
|
|
if (artists.length === 0) artists.push(info.artist);
|
|
|
|
|
|
|
|
|
|
|
|
if (musicMeta.format === undefined) musicMeta.format = SniffAudioExt(audioData);
|
|
|
|
if (musicMeta.format === undefined) musicMeta.format = SniffAudioExt(audioData);
|
|
|
|
console.log(musicMeta)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const imageInfo = await GetWebImage(musicMeta.albumPic);
|
|
|
|
const imageInfo = await GetWebImage(musicMeta.albumPic);
|
|
|
|
while (!!imageInfo.buffer && imageInfo.buffer.byteLength >= 16 * 1024 * 1024) {
|
|
|
|
while (!!imageInfo.buffer && imageInfo.buffer.byteLength >= 16 * 1024 * 1024) {
|
|
|
@ -48,12 +46,10 @@ export async function Decrypt(file, raw_filename, _) {
|
|
|
|
await img.resize(Math.round(img.getHeight() / 2), jimp.AUTO)
|
|
|
|
await img.resize(Math.round(img.getHeight() / 2), jimp.AUTO)
|
|
|
|
imageInfo.buffer = await img.getBufferAsync("image/jpeg")
|
|
|
|
imageInfo.buffer = await img.getBufferAsync("image/jpeg")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
console.log(imageInfo)
|
|
|
|
|
|
|
|
const mime = AudioMimeType[musicMeta.format]
|
|
|
|
const mime = AudioMimeType[musicMeta.format]
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
let musicBlob = new Blob([audioData], {type: mime});
|
|
|
|
let musicBlob = new Blob([audioData], {type: mime});
|
|
|
|
const originalMeta = await musicMetadata.parseBlob(musicBlob);
|
|
|
|
const originalMeta = await musicMetadata.parseBlob(musicBlob);
|
|
|
|
console.log(originalMeta)
|
|
|
|
|
|
|
|
let shouldWrite = !originalMeta.common.album && !originalMeta.common.artists && !originalMeta.common.title
|
|
|
|
let shouldWrite = !originalMeta.common.album && !originalMeta.common.artists && !originalMeta.common.title
|
|
|
|
if (musicMeta.format === "mp3") {
|
|
|
|
if (musicMeta.format === "mp3") {
|
|
|
|
audioData = await WriteMp3Meta(
|
|
|
|
audioData = await WriteMp3Meta(
|
|
|
|