From c81b12f45989ed5d2d8930e3e288842384cf4762 Mon Sep 17 00:00:00 2001 From: advplyr Date: Sun, 27 Feb 2022 16:52:01 -0600 Subject: [PATCH] Add:Book folder name starting with number and has series folder use as volume number --- server/Db.js | 3 ++- server/objects/Audiobook.js | 5 ++-- server/utils/abmetadataGenerator.js | 6 +++-- server/utils/scandir.js | 40 ++++++++++++++++++----------- 4 files changed, 33 insertions(+), 21 deletions(-) diff --git a/server/Db.js b/server/Db.js index 38a39d76..035ccc9a 100644 --- a/server/Db.js +++ b/server/Db.js @@ -203,7 +203,8 @@ class Db { })) return this.audiobooksDb.insert(audiobooks).then((results) => { - Logger.debug(`[DB] Audiobooks inserted ${results.updated}`) + Logger.debug(`[DB] Audiobooks inserted ${results.inserted}`) + this.audiobooks = this.audiobooks.concat(audiobooks) return true }).catch((error) => { Logger.error(`[DB] Audiobooks insert failed ${error}`) diff --git a/server/objects/Audiobook.js b/server/objects/Audiobook.js index 60f26818..c030b668 100644 --- a/server/objects/Audiobook.js +++ b/server/objects/Audiobook.js @@ -569,9 +569,8 @@ class Audiobook { if (abmetadataText) { var metadataUpdateObject = abmetadataGenerator.parse(abmetadataText) if (metadataUpdateObject && metadataUpdateObject.book) { - Logger.debug(`[Audiobook] Updating book "${this.title}" details from metadata.abs file`, metadataUpdateObject) if (this.update(metadataUpdateObject)) { - Logger.debug(`[Audiobook] Some details were updated from metadata.abs for "${this.title}"`) + Logger.debug(`[Audiobook] Some details were updated from metadata.abs for "${this.title}"`, metadataUpdateObject) hasUpdates = true } } @@ -834,7 +833,7 @@ class Audiobook { if (abmetadataText) { var metadataUpdateObject = abmetadataGenerator.parse(abmetadataText) if (metadataUpdateObject && metadataUpdateObject.book) { - Logger.debug(`[Audiobook] "${this.title}" found book details from metadata.abs file`, metadataUpdateObject) + Logger.debug(`[Audiobook] "${this.title}" found metadata.abs file`) for (const key in metadataUpdateObject.book) { var value = metadataUpdateObject.book[key] if (key && value !== undefined) { diff --git a/server/utils/abmetadataGenerator.js b/server/utils/abmetadataGenerator.js index 8409ab96..b8c9f677 100644 --- a/server/utils/abmetadataGenerator.js +++ b/server/utils/abmetadataGenerator.js @@ -85,8 +85,10 @@ function parseAbMetadataText(text) { bookDetails[key] = keyValue[1].trim() // Genres convert to array of strings - if (key === 'genres' && bookDetails[key]) { - bookDetails[key] = bookDetails[key].split(',').map(genre => genre.trim()) + if (key === 'genres') { + bookDetails[key] = bookDetails[key] ? bookDetails[key].split(',').map(genre => genre.trim()) : [] + } else if (!bookDetails[key]) { // Use null for empty details + bookDetails[key] = null } } } diff --git a/server/utils/scandir.js b/server/utils/scandir.js index d383ffb8..ffbe832f 100644 --- a/server/utils/scandir.js +++ b/server/utils/scandir.js @@ -196,32 +196,42 @@ function getAudiobookDataFromDir(folderPath, dir, parseSubtitle = false) { // If in a series directory check for volume number match - /* ACCEPTS: + /* ACCEPTS Book 2 - Title Here - Subtitle Here Title Here - Subtitle Here - Vol 12 Title Here - volume 9 - Subtitle Here Vol. 3 Title Here - Subtitle Here 1980 - Book 2-Title Here Title Here-Volume 999-Subtitle Here + 2 - Book Title + 100 - Book Title + 0.5 - Book Title */ var volumeNumber = null if (series) { - // New volume regex to match volumes with decimal (OLD: /(-? ?)\b((?:Book|Vol.?|Volume) (\d{1,3}))\b( ?-?)/i) - var volumeMatch = title.match(/(-? ?)\b((?:Book|Vol.?|Volume) (\d{0,3}(?:\.\d{1,2})?))\b( ?-?)/i) - if (volumeMatch && volumeMatch.length > 3 && volumeMatch[2] && volumeMatch[3]) { - volumeNumber = volumeMatch[3] - var replaceChunk = volumeMatch[2] + // Added 1.7.1: If title starts with a # that is 3 digits or less (or w/ 2 decimal), then use as volume number + var volumeMatch = title.match(/^(\d{1,3}(?:\.\d{1,2})?) - ./) + if (volumeMatch && volumeMatch.length > 1) { + volumeNumber = volumeMatch[1] + title = title.replace(`${volumeNumber} - `, '') + } else { + // Match volumes with decimal (OLD: /(-? ?)\b((?:Book|Vol.?|Volume) (\d{1,3}))\b( ?-?)/i) + var volumeMatch = title.match(/(-? ?)\b((?:Book|Vol.?|Volume) (\d{0,3}(?:\.\d{1,2})?))\b( ?-?)/i) + if (volumeMatch && volumeMatch.length > 3 && volumeMatch[2] && volumeMatch[3]) { + volumeNumber = volumeMatch[3] + var replaceChunk = volumeMatch[2] - // "1980 - Book 2-Title Here" - // Group 1 would be "- " - // Group 3 would be "-" - // Only remove the first group - if (volumeMatch[1]) { - replaceChunk = volumeMatch[1] + replaceChunk - } else if (volumeMatch[4]) { - replaceChunk += volumeMatch[4] + // "1980 - Book 2-Title Here" + // Group 1 would be "- " + // Group 3 would be "-" + // Only remove the first group + if (volumeMatch[1]) { + replaceChunk = volumeMatch[1] + replaceChunk + } else if (volumeMatch[4]) { + replaceChunk += volumeMatch[4] + } + title = title.replace(replaceChunk, '').trim() } - title = title.replace(replaceChunk, '').trim() } }