Add Support for flac meta/cover

remotes/origin/HEAD
MengYX 4 years ago
parent e2d4283003
commit 59d47c755e
No known key found for this signature in database
GPG Key ID: E63F9C7303E8F604

25
package-lock.json generated

@ -3214,8 +3214,7 @@
"commander": {
"version": "2.20.3",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz",
"integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==",
"dev": true
"integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ=="
},
"common-tags": {
"version": "1.8.0",
@ -5868,6 +5867,11 @@
"integrity": "sha512-Pgs951kaMm5GXP7MOvxERINe3gsaVjUWFm+UZPSq9xYriQAksyhg0csnS0KXSNRD5NmNdapXEpjxG49+AKh/ug==",
"dev": true
},
"image-size": {
"version": "0.6.3",
"resolved": "https://registry.npmjs.org/image-size/-/image-size-0.6.3.tgz",
"integrity": "sha512-47xSUiQioGaB96nqtp5/q55m0aBQSQdyIloMOc/x+QVTDZLNmXE892IIDrJ0hM1A5vcNUDD5tDffkSP5lCaIIA=="
},
"import-cwd": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/import-cwd/-/import-cwd-2.1.0.tgz",
@ -6793,6 +6797,23 @@
"integrity": "sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==",
"dev": true
},
"metaflac-js": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/metaflac-js/-/metaflac-js-1.0.5.tgz",
"integrity": "sha512-JxMDjEWQRHu+JTvA77vk0uOSt2NGqKYFAcheI8Qop7V5fxsEbRhSSjg8QnAhcmCuMo9zkSLjpj6ndRyZHb77sg==",
"requires": {
"commander": "^2.19.0",
"file-type": "^10.7.0",
"image-size": "^0.6.3"
},
"dependencies": {
"file-type": {
"version": "10.11.0",
"resolved": "https://registry.npmjs.org/file-type/-/file-type-10.11.0.tgz",
"integrity": "sha512-uzk64HRpUZyTGZtVuvrjP0FYxzQrBf4rojot6J65YMEbwBLB0CWm0CLojVpwpmFmxcE/lkvYICgfcGozbBq6rw=="
}
}
},
"methods": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz",

@ -21,6 +21,7 @@
"crypto-js": "^4.0.0",
"element-ui": "^2.13.0",
"iconv-lite": "^0.5.1",
"metaflac-js": "^1.0.5",
"music-metadata-browser": "^2.0.5",
"register-service-worker": "^1.7.1",
"vue": "^2.6.11"

@ -1,4 +1,5 @@
const CryptoJS = require("crypto-js");
const MetaFlac = require('metaflac-js');
const CORE_KEY = CryptoJS.enc.Hex.parse("687a4852416d736f356b496e62617857");
const META_KEY = CryptoJS.enc.Hex.parse("2331346C6A6B5F215C5D2630553C2728");
const MagicHeader = [0x43, 0x54, 0x45, 0x4E, 0x46, 0x44, 0x41, 0x4D];
@ -40,12 +41,23 @@ export async function Decrypt(file, raw_filename, raw_ext) {
if (musicMeta.format === undefined) musicMeta.format = DetectAudioExt(audioData, "mp3");
const imageInfo = await GetWebImage(musicMeta.albumPic);
if (musicMeta.format === "mp3") audioData = await WriteMp3Meta(
audioData, artists, info.title, musicMeta.album, imageInfo.buffer, musicMeta.albumPic);
if (musicMeta.format === "mp3") {
audioData = await WriteMp3Meta(
audioData, artists, info.title, musicMeta.album, imageInfo.buffer, musicMeta.albumPic);
} else if (musicMeta.format === "flac") {
const writer = new MetaFlac(Buffer.from(audioData))
writer.setTag("TITLE=" + info.title);
writer.setTag("ALBUM=" + musicMeta.album);
artists.forEach(artist => writer.setTag("ARTIST=" + artist));
writer.importPictureFromBuffer(Buffer.from(imageInfo.buffer))
audioData = writer.save()
}
console.log(imageInfo)
const mime = AudioMimeType[musicMeta.format];
const musicData = new Blob([audioData], {type: mime});
return {
let x = {
status: true,
title: info.title,
artist: info.artist,
@ -55,6 +67,8 @@ export async function Decrypt(file, raw_filename, raw_ext) {
file: URL.createObjectURL(musicData),
mime: mime
};
console.log(x)
return x;
}

@ -7,6 +7,9 @@ import {
GetWebImage,
RequestJsonp
} from "./util";
const MetaFlac = require('metaflac-js');
import {QmcMaskCreate58, QmcMaskDetectMflac, QmcMaskDetectMgg, QmcMaskGetDefault} from "./qmcMask";
import {fromByteArray as Base64Encode, toByteArray as Base64Decode} from 'base64-js'
@ -85,6 +88,11 @@ export async function Decrypt(file, raw_filename, raw_ext) {
writer.addTag();
musicDecoded = writer.arrayBuffer
musicBlob = new Blob([musicDecoded], {type: mime});
} else if (ext === 'flac') {
const writer = new MetaFlac(Buffer.from(musicDecoded))
writer.importPictureFromBuffer(Buffer.from(imageInfo.buffer))
musicDecoded = writer.save()
musicBlob = new Blob([musicDecoded], {type: mime});
}
}
}

@ -91,7 +91,7 @@ export async function GetWebImage(pic_url) {
return {"buffer": null, "url": "", "type": ""}
}
export async function WriteMp3Meta(audioData, artistList, title, album, pictureData = null, pictureDesc = "Cover") {
export function WriteMp3Meta(audioData, artistList, title, album, pictureData = null, pictureDesc = "Cover") {
const writer = new ID3Writer(audioData);
writer.setFrame("TPE1", artistList)
.setFrame("TIT2", title)

Loading…
Cancel
Save