From e073577574bd22daf6332c4232c3f48c5bfe47c3 Mon Sep 17 00:00:00 2001 From: advplyr Date: Sun, 31 Oct 2021 14:59:39 -0500 Subject: [PATCH] Add: Support for multiple authors separated by & #160 --- package.json | 3 ++- server/utils/parseAuthors.js | 26 +++++++++++++++++--------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index c8d439e5..9ddfcbe6 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,8 @@ "client": "cd client && npm install && npm run generate", "prod": "npm run client && npm install && node prod.js", "build-win": "pkg -t node12-win-x64 -o ./dist/win/audiobookshelf .", - "build-linux": "build/linuxpackager" + "build-linux": "build/linuxpackager", + "docker": "docker buildx build -t advplyr/audiobookshelf --platform linux/amd64,linux/arm64 --push ." }, "bin": "prod.js", "pkg": { diff --git a/server/utils/parseAuthors.js b/server/utils/parseAuthors.js index 1d326254..21029b36 100644 --- a/server/utils/parseAuthors.js +++ b/server/utils/parseAuthors.js @@ -24,34 +24,42 @@ function checkIsALastName(name) { module.exports = (author) => { if (!author) return null - var splitByComma = author.split(', ') + + var splitAuthors = [] + // Example &LF: Friedman, Milton & Friedman, Rose + if (author.includes('&')) { + author.split('&').forEach((asa) => splitAuthors = splitAuthors.concat(asa.split(','))) + } else { + splitAuthors = author.split(',') + } + if (splitAuthors.length) splitAuthors = splitAuthors.map(a => a.trim()) var authors = [] // 1 author FIRST LAST - if (splitByComma.length === 1) { + if (splitAuthors.length === 1) { authors.push(parseName(author)) } else { - var firstChunkIsALastName = checkIsALastName(splitByComma[0]) - var isEvenNum = splitByComma.length % 2 === 0 + var firstChunkIsALastName = checkIsALastName(splitAuthors[0]) + var isEvenNum = splitAuthors.length % 2 === 0 if (!isEvenNum && firstChunkIsALastName) { // console.error('Multi-author LAST,FIRST entry has a straggler (could be roman numerals or a suffix), ignore it', splitByComma[splitByComma.length - 1]) - splitByComma = splitByComma.slice(0, splitByComma.length - 1) + splitAuthors = splitAuthors.slice(0, splitAuthors.length - 1) } if (firstChunkIsALastName) { - var numAuthors = splitByComma.length / 2 + var numAuthors = splitAuthors.length / 2 for (let i = 0; i < numAuthors; i++) { - var last = splitByComma.shift() - var first = splitByComma.shift() + var last = splitAuthors.shift() + var first = splitAuthors.shift() authors.push({ first_name: first, last_name: last }) } } else { - splitByComma.forEach((segment) => { + splitAuthors.forEach((segment) => { authors.push(parseName(segment)) }) }