diff --git a/server/utils/scandir.js b/server/utils/scandir.js index 59a0c2427..7148ef06a 100644 --- a/server/utils/scandir.js +++ b/server/utils/scandir.js @@ -149,16 +149,16 @@ module.exports.buildLibraryFile = buildLibraryFile function getBookDataFromDir(relPath, parseSubtitle = false) { const splitDir = relPath.split('/') - var folder = splitDir.pop() // Audio files will always be in the directory named for the title - var series = splitDir.length > 1 ? splitDir.pop() : null // If there are at least 2 more directories, next furthest will be the series - var author = splitDir.length > 0 ? splitDir.pop() : null // There could be many more directories, but only the top 3 are used for naming /author/series/title/ + const titleFolder = splitDir.pop() // Audio files will always be in the directory named for the title + const series = splitDir.length > 1 ? splitDir.pop() : null // If there are at least 2 more directories, next furthest will be the series + const author = splitDir.length > 0 ? splitDir.pop() : null // There could be many more directories, but only the top 3 are used for naming /author/series/title/ - // The may contain various other pieces of metadata, these functions extract it. - var [folder, asin] = getASIN(folder) - var [folder, narrators] = getNarrator(folder) - var [folder, sequence] = series ? getSequence(folder) : [folder, null] - var [folder, publishedYear] = getPublishedYear(folder) - var [title, subtitle] = parseSubtitle ? getSubtitle(folder) : [folder, null] + // Each extractor strips one piece of metadata and returns the remaining folder name. + const [afterAsin, asin] = getASIN(titleFolder) + const [afterNarrators, narrators] = getNarrator(afterAsin) + const [afterSequence, sequence] = series ? getSequence(afterNarrators) : [afterNarrators, null] + const [afterYear, publishedYear] = getPublishedYear(afterSequence) + const [title, subtitle] = parseSubtitle ? getSubtitle(afterYear) : [afterYear, null] return { title, @@ -180,8 +180,8 @@ module.exports.getBookDataFromDir = getBookDataFromDir * @returns {[string, string]} [folder, narrator] */ function getNarrator(folder) { - let pattern = /^(?