Browse Source

Merge pull request #112 from flosacca/master

Fix #100 by @flosacca
20230320
MengYX 4 years ago
committed by GitHub
parent
commit
bf0df4e68d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      src/decrypt/ncm.js
  2. 20
      src/decrypt/util.js

3
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) {

20
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,

Loading…
Cancel
Save