From 07994d38d5285fa947711a951a223d9b72050fda Mon Sep 17 00:00:00 2001 From: advplyr Date: Sat, 18 Sep 2021 11:13:05 -0500 Subject: [PATCH] Add volume number parsing to scanner --- client/components/AudioPlayer.vue | 1 - client/store/user.js | 2 -- server/objects/Book.js | 2 +- server/objects/Stream.js | 2 -- server/utils/scandir.js | 33 +++++++++++++++++++++++++++++-- 5 files changed, 32 insertions(+), 8 deletions(-) diff --git a/client/components/AudioPlayer.vue b/client/components/AudioPlayer.vue index 1a8cf911..9317c9b4 100644 --- a/client/components/AudioPlayer.vue +++ b/client/components/AudioPlayer.vue @@ -315,7 +315,6 @@ export default { this.bufferTrackWidth = bufferlen }, timeupdate() { - // console.log('Time update', this.audioEl.currentTime) if (!this.$refs.playedTrack) { console.error('Invalid no played track ref') return diff --git a/client/store/user.js b/client/store/user.js index 1500bee4..bf5db1e6 100644 --- a/client/store/user.js +++ b/client/store/user.js @@ -60,10 +60,8 @@ export const mutations = { state.user = user if (user) { if (user.token) localStorage.setItem('token', user.token) - console.log('setUser', user.username) } else { localStorage.removeItem('token') - console.warn('setUser cleared') } }, setSettings(state, settings) { diff --git a/server/objects/Book.js b/server/objects/Book.js index a3ab06af..7b44659a 100644 --- a/server/objects/Book.js +++ b/server/objects/Book.js @@ -151,7 +151,7 @@ class Book { // If audiobook directory path was changed, check and update properties set from dirnames // May be worthwhile checking if these were manually updated and not override manual updates syncPathsUpdated(audiobookData) { - var keysToSync = ['author', 'title', 'series', 'publishYear'] + var keysToSync = ['author', 'title', 'series', 'publishYear', 'volumeNumber'] var syncPayload = {} keysToSync.forEach((key) => { if (audiobookData[key]) syncPayload[key] = audiobookData[key] diff --git a/server/objects/Stream.js b/server/objects/Stream.js index 39d37c6e..2bb1a6ae 100644 --- a/server/objects/Stream.js +++ b/server/objects/Stream.js @@ -171,13 +171,11 @@ class Stream extends EventEmitter { this.furthestSegmentCreated = lastSegment } - // console.log('SORT', [...this.segmentsCreated].slice(0, 200).join(', '), segments.slice(0, 200).join(', ')) segments.forEach((seg) => { if (!current_chunk.length || last_seg_in_chunk + 1 === seg) { last_seg_in_chunk = seg current_chunk.push(seg) } else { - // console.log('Last Seg is not equal to - 1', last_seg_in_chunk, seg) if (current_chunk.length === 1) chunks.push(current_chunk[0]) else chunks.push(`${current_chunk[0]}-${current_chunk[current_chunk.length - 1]}`) last_seg_in_chunk = seg diff --git a/server/utils/scandir.js b/server/utils/scandir.js index 6ac283bc..e7dea53d 100644 --- a/server/utils/scandir.js +++ b/server/utils/scandir.js @@ -155,10 +155,8 @@ function getAudiobookDataFromDir(abRootPath, dir, parseSubtitle = false) { // If there are at least 2 more directories, next furthest will be the series if (splitDir.length > 1) series = splitDir.pop() if (splitDir.length > 0) author = splitDir.pop() - // There could be many more directories, but only the top 3 are used for naming /author/series/title/ - var publishYear = null // If Title is of format 1999 - Title, then use 1999 as publish year var publishYearMatch = title.match(/^([0-9]{4}) - (.+)/) @@ -169,7 +167,37 @@ function getAudiobookDataFromDir(abRootPath, dir, parseSubtitle = false) { } } + // If in a series directory check for volume number match + /* 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 + */ + var volumeNumber = null + if (series) { + var volumeMatch = title.match(/(-(?: ?))?\b((?:Book|Vol.?|Volume) \b(\d{1,3}))((?: ?)-)?/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] + } + title = title.replace(replaceChunk, '').trim() + } + } + // Subtitle can be parsed from the title if user enabled + // Subtitle is everything after " - " var subtitle = null if (parseSubtitle && title.includes(' - ')) { var splitOnSubtitle = title.split(' - ') @@ -182,6 +210,7 @@ function getAudiobookDataFromDir(abRootPath, dir, parseSubtitle = false) { title, subtitle, series, + volumeNumber, publishYear, path: dir, // relative audiobook path i.e. /Author Name/Book Name/.. fullPath: Path.join(abRootPath, dir) // i.e. /audiobook/Author Name/Book Name/..