Add: Support for multiple authors separated by & #160

This commit is contained in:
advplyr 2021-10-31 14:59:39 -05:00
parent 94f47b855b
commit e073577574
2 changed files with 19 additions and 10 deletions

View File

@ -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": {

View File

@ -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))
})
}