From 657d4dd7054dff003bd862da3ab4835fbfb28811 Mon Sep 17 00:00:00 2001 From: advplyr Date: Wed, 21 Dec 2022 07:13:28 -0600 Subject: [PATCH] Update:Trim whitespace from audio file meta tag values #1305 --- server/objects/metadata/BookMetadata.js | 15 ++++++++++----- server/objects/metadata/PodcastMetadata.js | 8 ++++---- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/server/objects/metadata/BookMetadata.js b/server/objects/metadata/BookMetadata.js index 22a28d87..22be0421 100644 --- a/server/objects/metadata/BookMetadata.js +++ b/server/objects/metadata/BookMetadata.js @@ -295,16 +295,21 @@ class BookMetadata { } ] - var updatePayload = {} + const updatePayload = {} // Metadata is only mapped to the book if it is empty MetadataMapArray.forEach((mapping) => { - var value = audioFileMetaTags[mapping.tag] - var tagToUse = mapping.tag + let value = audioFileMetaTags[mapping.tag] + // let tagToUse = mapping.tag if (!value && mapping.altTag) { value = audioFileMetaTags[mapping.altTag] - tagToUse = mapping.altTag + // tagToUse = mapping.altTag } + + if (value && typeof value === 'string') { // Trim whitespace + value = value.trim() + } + if (value) { if (mapping.key === 'narrators' && (!this.narrators.length || overrideExistingDetails)) { updatePayload.narrators = this.parseNarratorsTag(value) @@ -313,7 +318,7 @@ class BookMetadata { } else if (mapping.key === 'genres' && (!this.genres.length || overrideExistingDetails)) { updatePayload.genres = this.parseGenresTag(value) } else if (mapping.key === 'series' && (!this.series.length || overrideExistingDetails)) { - var sequenceTag = audioFileMetaTags.tagSeriesPart || null + const sequenceTag = audioFileMetaTags.tagSeriesPart || null updatePayload.series = this.parseSeriesTag(value, sequenceTag) } else if (!this[mapping.key] || overrideExistingDetails) { updatePayload[mapping.key] = value diff --git a/server/objects/metadata/PodcastMetadata.js b/server/objects/metadata/PodcastMetadata.js index 3de2fe33..85e2c52d 100644 --- a/server/objects/metadata/PodcastMetadata.js +++ b/server/objects/metadata/PodcastMetadata.js @@ -88,8 +88,8 @@ class PodcastMetadata { } searchQuery(query) { // Returns key if match is found - var keysToCheck = ['title', 'author', 'itunesId', 'itunesArtistId'] - for (var key of keysToCheck) { + const keysToCheck = ['title', 'author', 'itunesId', 'itunesArtistId'] + for (const key of keysToCheck) { if (this[key] && cleanStringForSearch(String(this[key])).includes(query)) { return { matchKey: key, @@ -118,8 +118,8 @@ class PodcastMetadata { } update(payload) { - var json = this.toJSON() - var hasUpdates = false + const json = this.toJSON() + let hasUpdates = false for (const key in json) { if (payload[key] !== undefined) { if (!areEquivalent(payload[key], json[key])) {