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