From f24ea6a07b1fa97d7f936261be4965092fa91c3c Mon Sep 17 00:00:00 2001 From: flosacca Date: Sat, 21 Nov 2020 07:03:57 +0800 Subject: [PATCH] Fix #100 --- src/decrypt/ncm.js | 3 ++- src/decrypt/util.js | 20 ++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/decrypt/ncm.js b/src/decrypt/ncm.js index 0ccbb21..18b7d57 100644 --- a/src/decrypt/ncm.js +++ b/src/decrypt/ncm.js @@ -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) { diff --git a/src/decrypt/util.js b/src/decrypt/util.js index 2e4cdf1..f77944b 100644 --- a/src/decrypt/util.js +++ b/src/decrypt/util.js @@ -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,