1
0
forked from um/web

Add Support for flac meta/cover

This commit is contained in:
MengYX 2020-07-18 19:25:41 +08:00
parent e2d4283003
commit 59d47c755e
No known key found for this signature in database
GPG Key ID: E63F9C7303E8F604
5 changed files with 50 additions and 6 deletions

25
package-lock.json generated
View File

@ -3214,8 +3214,7 @@
"commander": { "commander": {
"version": "2.20.3", "version": "2.20.3",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz",
"integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ=="
"dev": true
}, },
"common-tags": { "common-tags": {
"version": "1.8.0", "version": "1.8.0",
@ -5868,6 +5867,11 @@
"integrity": "sha512-Pgs951kaMm5GXP7MOvxERINe3gsaVjUWFm+UZPSq9xYriQAksyhg0csnS0KXSNRD5NmNdapXEpjxG49+AKh/ug==", "integrity": "sha512-Pgs951kaMm5GXP7MOvxERINe3gsaVjUWFm+UZPSq9xYriQAksyhg0csnS0KXSNRD5NmNdapXEpjxG49+AKh/ug==",
"dev": true "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": { "import-cwd": {
"version": "2.1.0", "version": "2.1.0",
"resolved": "https://registry.npmjs.org/import-cwd/-/import-cwd-2.1.0.tgz", "resolved": "https://registry.npmjs.org/import-cwd/-/import-cwd-2.1.0.tgz",
@ -6793,6 +6797,23 @@
"integrity": "sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==", "integrity": "sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==",
"dev": true "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": { "methods": {
"version": "1.1.2", "version": "1.1.2",
"resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz",

View File

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

View File

@ -1,4 +1,5 @@
const CryptoJS = require("crypto-js"); const CryptoJS = require("crypto-js");
const MetaFlac = require('metaflac-js');
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");
const MagicHeader = [0x43, 0x54, 0x45, 0x4E, 0x46, 0x44, 0x41, 0x4D]; 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"); if (musicMeta.format === undefined) musicMeta.format = DetectAudioExt(audioData, "mp3");
const imageInfo = await GetWebImage(musicMeta.albumPic); const imageInfo = await GetWebImage(musicMeta.albumPic);
if (musicMeta.format === "mp3") audioData = await WriteMp3Meta( if (musicMeta.format === "mp3") {
audioData = await WriteMp3Meta(
audioData, artists, info.title, musicMeta.album, imageInfo.buffer, musicMeta.albumPic); 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 mime = AudioMimeType[musicMeta.format];
const musicData = new Blob([audioData], {type: mime}); const musicData = new Blob([audioData], {type: mime});
return {
let x = {
status: true, status: true,
title: info.title, title: info.title,
artist: info.artist, artist: info.artist,
@ -55,6 +67,8 @@ export async function Decrypt(file, raw_filename, raw_ext) {
file: URL.createObjectURL(musicData), file: URL.createObjectURL(musicData),
mime: mime mime: mime
}; };
console.log(x)
return x;
} }

View File

@ -7,6 +7,9 @@ import {
GetWebImage, GetWebImage,
RequestJsonp RequestJsonp
} from "./util"; } from "./util";
const MetaFlac = require('metaflac-js');
import {QmcMaskCreate58, QmcMaskDetectMflac, QmcMaskDetectMgg, QmcMaskGetDefault} from "./qmcMask"; import {QmcMaskCreate58, QmcMaskDetectMflac, QmcMaskDetectMgg, QmcMaskGetDefault} from "./qmcMask";
import {fromByteArray as Base64Encode, toByteArray as Base64Decode} from 'base64-js' 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(); writer.addTag();
musicDecoded = writer.arrayBuffer musicDecoded = writer.arrayBuffer
musicBlob = new Blob([musicDecoded], {type: mime}); 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});
} }
} }
} }

View File

@ -91,7 +91,7 @@ export async function GetWebImage(pic_url) {
return {"buffer": null, "url": "", "type": ""} 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); const writer = new ID3Writer(audioData);
writer.setFrame("TPE1", artistList) writer.setFrame("TPE1", artistList)
.setFrame("TIT2", title) .setFrame("TIT2", title)