From 4be004290ddc3240a3aea8207021b3ab701bd1a7 Mon Sep 17 00:00:00 2001 From: advplyr Date: Thu, 25 Nov 2021 19:23:22 -0600 Subject: [PATCH] Add:Alternative ID3 tags --- server/objects/AudioFile.js | 1 - server/objects/Book.js | 19 ++++++++++++++----- server/utils/prober.js | 2 +- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/server/objects/AudioFile.js b/server/objects/AudioFile.js index b448d217..6c2c0333 100644 --- a/server/objects/AudioFile.js +++ b/server/objects/AudioFile.js @@ -296,7 +296,6 @@ class AudioFile { if (!this.metadata || !this.metadata.isEqual(scannedAudioFile.metadata)) { this.metadata = scannedAudioFile.metadata hasUpdated = true - // console.log('metadata updated for audio file') } } else if (key === 'chapters') { if (this.syncChapters(newjson.chapters || [])) { diff --git a/server/objects/Book.js b/server/objects/Book.js index 97e6bb3f..bd168611 100644 --- a/server/objects/Book.js +++ b/server/objects/Book.js @@ -322,10 +322,12 @@ class Book { }, { tag: 'tagAlbum', + altTag: 'tagTitle', key: 'title', }, { tag: 'tagArtist', + altTag: 'tagAlbumArtist', key: 'author' }, { @@ -343,16 +345,23 @@ class Book { ] var updatePayload = {} + // Metadata is only mapped to the book if it is empty MetadataMapArray.forEach((mapping) => { - if (audioFileMetadata[mapping.tag]) { + var value = audioFileMetadata[mapping.tag] + var tagToUse = mapping.tag + if (!value && mapping.altTag) { + value = audioFileMetadata[mapping.altTag] + tagToUse = mapping.altTag + } + if (value) { // Genres can contain multiple if (mapping.key === 'genres' && (!this[mapping.key].length || !this[mapping.key] || overrideExistingDetails)) { - updatePayload[mapping.key] = this.parseGenresTag(audioFileMetadata[mapping.tag]) - // Logger.debug(`[Book] Mapping metadata to key ${mapping.tag} => ${mapping.key}: ${updatePayload[mapping.key].join(',')}`) + updatePayload[mapping.key] = this.parseGenresTag(audioFileMetadata[tagToUse]) + // Logger.debug(`[Book] Mapping metadata to key ${tagToUse} => ${mapping.key}: ${updatePayload[mapping.key].join(',')}`) } else if (!this[mapping.key] || overrideExistingDetails) { - updatePayload[mapping.key] = audioFileMetadata[mapping.tag] - // Logger.debug(`[Book] Mapping metadata to key ${mapping.tag} => ${mapping.key}: ${updatePayload[mapping.key]}`) + updatePayload[mapping.key] = audioFileMetadata[tagToUse] + // Logger.debug(`[Book] Mapping metadata to key ${tagToUse} => ${mapping.key}: ${updatePayload[mapping.key]}`) } } }) diff --git a/server/utils/prober.js b/server/utils/prober.js index 7d53611b..974eca07 100644 --- a/server/utils/prober.js +++ b/server/utils/prober.js @@ -153,7 +153,7 @@ function parseTags(format, verbose) { file_tag_track: tryGrabTags(format, 'track', 'trck', 'trk'), file_tag_album: tryGrabTags(format, 'album', 'talb', 'tal'), file_tag_artist: tryGrabTags(format, 'artist', 'tpe1', 'tp1'), - file_tag_albumartist: tryGrabTags(format, 'albumartist', 'tpe2'), + file_tag_albumartist: tryGrabTags(format, 'albumartist', 'album_artist', 'tpe2'), file_tag_date: tryGrabTags(format, 'date', 'tyer', 'tye'), file_tag_composer: tryGrabTags(format, 'composer', 'tcom', 'tcm'), file_tag_publisher: tryGrabTags(format, 'publisher', 'tpub', 'tpb'),