From 46885fa9541656a6d1e0565477aca291fe9f7afe Mon Sep 17 00:00:00 2001 From: RemixDev Date: Fri, 10 Sep 2021 19:25:37 +0200 Subject: [PATCH] Fixed ID3v1 tagging issue --- deemix/downloader.js | 1 - deemix/tagger.js | 19 ++++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/deemix/downloader.js b/deemix/downloader.js index 092e171..7ed1420 100644 --- a/deemix/downloader.js +++ b/deemix/downloader.js @@ -484,7 +484,6 @@ class Downloader { this.log(itemData, "tagging") if (extension == '.mp3'){ tagID3(writepath, track, this.settings.tags) - if (this.settings.tags.saveID3v1) tagID3v1(writepath, track, this.settings.tags) } else if (extension == '.flac'){ tagFLAC(writepath, track, this.settings.tags) } diff --git a/deemix/tagger.js b/deemix/tagger.js index 2ecbf7a..c1c7d51 100644 --- a/deemix/tagger.js +++ b/deemix/tagger.js @@ -125,7 +125,13 @@ function tagID3(path, track, save){ } tag.addTag() - fs.writeFileSync(path, Buffer.from(tag.arrayBuffer)) + let taggedSongBuffer = Buffer.from(tag.arrayBuffer) + if (taggedSongBuffer.slice(-128,-125).toString() === "TAG") + taggedSongBuffer = taggedSongBuffer.slice(0, -128) + if (save.saveID3v1) + taggedSongBuffer = tagID3v1(taggedSongBuffer, track, save) + + fs.writeFileSync(path, taggedSongBuffer) } function tagFLAC(path, track, save){ @@ -234,7 +240,7 @@ function extAsciiFilter(string){ return output } -function tagID3v1(path, track, save){ +function tagID3v1(taggedSongBuffer, track, save){ const tagBuffer = Buffer.alloc(128) tagBuffer.write('TAG', 0) // Header @@ -277,12 +283,11 @@ function tagID3v1(path, track, save){ } // Save tags - const songBuffer = fs.readFileSync(path) - const buffer = new ArrayBuffer(songBuffer.byteLength + 128) + const buffer = new ArrayBuffer(taggedSongBuffer.byteLength + 128) const bufferWriter = new Uint8Array(buffer) - bufferWriter.set(new Uint8Array(songBuffer), 0) - bufferWriter.set(new Uint8Array(tagBuffer), songBuffer.byteLength) - fs.writeFileSync(path, Buffer.from(buffer)) + bufferWriter.set(new Uint8Array(taggedSongBuffer), 0) + bufferWriter.set(new Uint8Array(tagBuffer), taggedSongBuffer.byteLength) + return Buffer.from(buffer) } module.exports = {