1
0
forked from um/web

Merge pull request #112 from flosacca/master

Fix #100 by @flosacca
This commit is contained in:
MengYX 2020-11-23 21:34:58 +08:00 committed by GitHub
commit bf0df4e68d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 3 deletions

View File

@ -55,10 +55,11 @@ export async function Decrypt(file, raw_filename, raw_ext) {
try {
let musicBlob = new Blob([audioData], {type: mime});
const originalMeta = await musicMetadata.parseBlob(musicBlob);
console.log(originalMeta)
let shouldWrite = !originalMeta.common.album && !originalMeta.common.artists && !originalMeta.common.title
if (musicMeta.format === "mp3") {
audioData = await WriteMp3Meta(
audioData, artists, info.title, musicMeta.album, imageInfo.buffer, musicMeta.albumPic, !shouldWrite)
audioData, artists, info.title, musicMeta.album, imageInfo.buffer, musicMeta.albumPic, shouldWrite ? null : originalMeta)
} else if (musicMeta.format === "flac") {
const writer = new MetaFlac(Buffer.from(audioData))
if (shouldWrite) {

View File

@ -93,9 +93,25 @@ export async function GetWebImage(pic_url) {
return {"buffer": null, "src": pic_url, "url": "", "type": ""}
}
export async function WriteMp3Meta(audioData, artistList, title, album, pictureData = null, pictureDesc = "Cover", cover_only = true) {
export async function WriteMp3Meta(audioData, artistList, title, album, pictureData = null, pictureDesc = "Cover", originalMeta = null) {
const writer = new ID3Writer(audioData);
if (!cover_only) writer.setFrame("TPE1", artistList).setFrame("TIT2", title).setFrame("TALB", album);
if (originalMeta !== null) {
artistList = originalMeta.common.artists || artistList
title = originalMeta.common.title || title
album = originalMeta.common.album || album
const frames = originalMeta.native['ID3v2.4'] || originalMeta.native['ID3v2.3'] || originalMeta.native['ID3v2.2'] || []
frames.forEach(frame => {
if (frame.id !== 'TPE1' && frame.id !== 'TIT2' && frame.id !== 'TALB') {
try {
writer.setFrame(frame.id, frame.value)
} catch (e) {
}
}
})
}
writer.setFrame('TPE1', artistList)
.setFrame('TIT2', title)
.setFrame('TALB', album);
if (pictureData !== null) {
writer.setFrame('APIC', {
type: 3,