From 67523095d69e47646e6aa2f4031dba72e1f42229 Mon Sep 17 00:00:00 2001 From: Cassie Esposito Date: Thu, 19 May 2022 19:42:45 -0700 Subject: [PATCH 1/4] Narrators successfully isolated from path. Next steps: parse multiple narrators and save to disk --- server/utils/scandir.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/server/utils/scandir.js b/server/utils/scandir.js index 3bcfbc35..7e11f0eb 100644 --- a/server/utils/scandir.js +++ b/server/utils/scandir.js @@ -4,6 +4,7 @@ const Logger = require('../Logger') const { recurseFiles, getFileTimestampsWithIno } = require('./fileUtils') const globals = require('./globals') const LibraryFile = require('../objects/files/LibraryFile') +const { response } = require('express') function isMediaFile(mediaType, ext) { // if (!path) return false @@ -212,7 +213,8 @@ function getBookDataFromDir(folderPath, relPath, parseSubtitle = false) { var splitDir = relPath.split('/') // Audio files will always be in the directory named for the title - var title = splitDir.pop() + var [title, narrators] = getTitleAndNarrator(splitDir.pop()) + var series = null var author = null // If there are at least 2 more directories, next furthest will be the series @@ -265,7 +267,7 @@ function getBookDataFromDir(folderPath, relPath, parseSubtitle = false) { // If Title is of format 1999 OR (1999) - Title, then use 1999 as publish year var publishYearMatch = title.match(/^(\(?[0-9]{4}\)?) - (.+)/) if (publishYearMatch && publishYearMatch.length > 2 && publishYearMatch[1]) { - // Strip parentheses + // Strip parentheses if (publishYearMatch[1].startsWith('(') && publishYearMatch[1].endsWith(')')) { publishYearMatch[1] = publishYearMatch[1].slice(1, -1) } @@ -298,6 +300,12 @@ function getBookDataFromDir(folderPath, relPath, parseSubtitle = false) { } } +function getTitleAndNarrator(folder) { + let pattern = /^(?.*)\[(?<narrators>.*)\] *$/ + let match = folder.match(pattern) + return match ? [match.groups.title.trimEnd(), match.groups.narrators] : [folder, null] +} + function getPodcastDataFromDir(folderPath, relPath) { relPath = relPath.replace(/\\/g, '/') var splitDir = relPath.split('/') @@ -356,4 +364,4 @@ async function getLibraryItemFileData(libraryMediaType, folder, libraryItemPath, } return libraryItem } -module.exports.getLibraryItemFileData = getLibraryItemFileData \ No newline at end of file +module.exports.getLibraryItemFileData = getLibraryItemFileData From 23904d57adffd1b4994ad54967053a722c4e4b0a Mon Sep 17 00:00:00 2001 From: Cassie Esposito <dev@timevault.org> Date: Thu, 19 May 2022 20:43:17 -0700 Subject: [PATCH 2/4] Narrator data is sucessfully saved from folder name. --- server/objects/metadata/BookMetadata.js | 4 ++-- server/utils/scandir.js | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/server/objects/metadata/BookMetadata.js b/server/objects/metadata/BookMetadata.js index 59204777..99be71f6 100644 --- a/server/objects/metadata/BookMetadata.js +++ b/server/objects/metadata/BookMetadata.js @@ -194,7 +194,7 @@ class BookMetadata { setData(scanMediaData = {}) { this.title = scanMediaData.title || null this.subtitle = scanMediaData.subtitle || null - this.narrators = [] + this.narrators = this.parseNarratorsTag(scanMediaData.narrators) this.publishedYear = scanMediaData.publishedYear || null this.description = scanMediaData.description || null this.isbn = scanMediaData.isbn || null @@ -356,4 +356,4 @@ class BookMetadata { return null } } -module.exports = BookMetadata \ No newline at end of file +module.exports = BookMetadata diff --git a/server/utils/scandir.js b/server/utils/scandir.js index 7e11f0eb..726183c9 100644 --- a/server/utils/scandir.js +++ b/server/utils/scandir.js @@ -215,6 +215,9 @@ function getBookDataFromDir(folderPath, relPath, parseSubtitle = false) { // Audio files will always be in the directory named for the title var [title, narrators] = getTitleAndNarrator(splitDir.pop()) + const parseNameString = require('./parseNameString') + console.log(`\n\n\n${JSON.stringify(parseNameString.parse(narrators), 0, 2)}\n\n\n`) + var series = null var author = null // If there are at least 2 more directories, next furthest will be the series @@ -294,6 +297,7 @@ function getBookDataFromDir(folderPath, relPath, parseSubtitle = false) { series, sequence: volumeNumber, publishedYear, + narrators, }, relPath: relPath, // relative audiobook path i.e. /Author Name/Book Name/.. path: Path.posix.join(folderPath, relPath) // i.e. /audiobook/Author Name/Book Name/.. From 6ff66370fea06be4e8793615f9a60b4d35a8d7cc Mon Sep 17 00:00:00 2001 From: Cassie Esposito <dev@timevault.org> Date: Thu, 19 May 2022 21:07:04 -0700 Subject: [PATCH 3/4] Use {} instead of [] for narrators tag. Removed logging left over from debugging. --- server/utils/scandir.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/server/utils/scandir.js b/server/utils/scandir.js index 726183c9..faeab015 100644 --- a/server/utils/scandir.js +++ b/server/utils/scandir.js @@ -215,9 +215,6 @@ function getBookDataFromDir(folderPath, relPath, parseSubtitle = false) { // Audio files will always be in the directory named for the title var [title, narrators] = getTitleAndNarrator(splitDir.pop()) - const parseNameString = require('./parseNameString') - console.log(`\n\n\n${JSON.stringify(parseNameString.parse(narrators), 0, 2)}\n\n\n`) - var series = null var author = null // If there are at least 2 more directories, next furthest will be the series @@ -305,7 +302,7 @@ function getBookDataFromDir(folderPath, relPath, parseSubtitle = false) { } function getTitleAndNarrator(folder) { - let pattern = /^(?<title>.*)\[(?<narrators>.*)\] *$/ + let pattern = /^(?<title>.*)\{(?<narrators>.*)\} *$/ let match = folder.match(pattern) return match ? [match.groups.title.trimEnd(), match.groups.narrators] : [folder, null] } From 169b637720b4b4a71061b75f8c4319f71ab36a32 Mon Sep 17 00:00:00 2001 From: Cassie Esposito <dev@timevault.org> Date: Sat, 21 May 2022 08:06:06 -0700 Subject: [PATCH 4/4] Removed dependency erroniously added by IDE --- server/utils/scandir.js | 1 - 1 file changed, 1 deletion(-) diff --git a/server/utils/scandir.js b/server/utils/scandir.js index faeab015..9d52227a 100644 --- a/server/utils/scandir.js +++ b/server/utils/scandir.js @@ -4,7 +4,6 @@ const Logger = require('../Logger') const { recurseFiles, getFileTimestampsWithIno } = require('./fileUtils') const globals = require('./globals') const LibraryFile = require('../objects/files/LibraryFile') -const { response } = require('express') function isMediaFile(mediaType, ext) { // if (!path) return false