mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-01-04 04:59:37 +01:00
Cleaned up function getSequence, became more forgiving of whitespace around metadata elements
This commit is contained in:
parent
f1f02b185e
commit
2d8c840ad6
@ -5,6 +5,7 @@ const { recurseFiles, getFileTimestampsWithIno } = require('./fileUtils')
|
|||||||
const globals = require('./globals')
|
const globals = require('./globals')
|
||||||
const LibraryFile = require('../objects/files/LibraryFile')
|
const LibraryFile = require('../objects/files/LibraryFile')
|
||||||
const { response } = require('express')
|
const { response } = require('express')
|
||||||
|
const e = require('express')
|
||||||
|
|
||||||
function isMediaFile(mediaType, ext) {
|
function isMediaFile(mediaType, ext) {
|
||||||
// if (!path) return false
|
// if (!path) return false
|
||||||
@ -218,7 +219,7 @@ function getBookDataFromDir(folderPath, relPath, parseSubtitle = false) {
|
|||||||
|
|
||||||
// The title directory may contain various other pieces of metadata, these functions extract it.
|
// The title directory may contain various other pieces of metadata, these functions extract it.
|
||||||
var [title, narrators] = getNarrator(title)
|
var [title, narrators] = getNarrator(title)
|
||||||
if (series) { var [series, title, sequence] = getSeries(series, title) }
|
if (series) { var [title, sequence] = getSequence(title) }
|
||||||
var [title, publishedYear] = getPublishedYear(title)
|
var [title, publishedYear] = getPublishedYear(title)
|
||||||
if (parseSubtitle) { var [title, subtitle] = getSubtitle(title) } // Subtitle can be parsed from the title if user enabled
|
if (parseSubtitle) { var [title, subtitle] = getSubtitle(title) } // Subtitle can be parsed from the title if user enabled
|
||||||
|
|
||||||
@ -243,58 +244,41 @@ function getNarrator(folder) {
|
|||||||
return match ? [match.groups.title.trimEnd(), match.groups.narrators] : [folder, null]
|
return match ? [match.groups.title.trimEnd(), match.groups.narrators] : [folder, null]
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSeries(series, title) {
|
function getSequence(title) {
|
||||||
// If in a series directory check for volume number match
|
// Valid ways of including a volume number:
|
||||||
/* ACCEPTS
|
// Book 2 - Title Here - Subtitle Here
|
||||||
Book 2 - Title Here - Subtitle Here
|
// Title Here - Subtitle Here - Vol 12
|
||||||
Title Here - Subtitle Here - Vol 12
|
// Title Here - volume 9 - Subtitle Here
|
||||||
Title Here - volume 9 - Subtitle Here
|
// Vol. 3 Title Here - Subtitle Here
|
||||||
Vol. 3 Title Here - Subtitle Here
|
// 1980 - Book 2-Title Here
|
||||||
1980 - Book 2-Title Here
|
// Title Here-Volume 999-Subtitle Here
|
||||||
Title Here-Volume 999-Subtitle Here
|
// 2 - Book Title
|
||||||
2 - Book Title
|
// 100 - Book Title
|
||||||
100 - Book Title
|
// 0.5 - Book Title
|
||||||
0.5 - Book Title
|
|
||||||
*/
|
|
||||||
var volumeNumber = null
|
|
||||||
|
|
||||||
// Added 1.7.1: If title starts with a # that is 3 digits or less (or w/ 2 decimal), then use as volume number
|
// Matches a valid volume string, capturing each section for later processing.
|
||||||
var volumeMatch = title.match(/^(\d{1,3}(?:\.\d{1,2})?) - ./)
|
let pattern = /^(vol\.? |volume |book )?(\d{1,3}(?:\.\d{1,2})?)(.*)/i
|
||||||
if (volumeMatch && volumeMatch.length > 1) {
|
|
||||||
volumeNumber = volumeMatch[1]
|
|
||||||
title = title.replace(`${volumeNumber} - `, '')
|
|
||||||
} else {
|
|
||||||
// Match volumes with decimal (OLD: /(-? ?)\b((?:Book|Vol.?|Volume) (\d{1,3}))\b( ?-?)/i)
|
|
||||||
var volumeMatch = title.match(/(-? ?)\b((?:Book|Vol.?|Volume) (\d{0,3}(?:\.\d{1,2})?))\b( ?-?)/i)
|
|
||||||
if (volumeMatch && volumeMatch.length > 3 && volumeMatch[2] && volumeMatch[3]) {
|
|
||||||
volumeNumber = volumeMatch[3]
|
|
||||||
var replaceChunk = volumeMatch[2]
|
|
||||||
|
|
||||||
// "1980 - Book 2-Title Here"
|
let volumeNumber = null
|
||||||
// Group 1 would be "- "
|
let parts = title.split('-')
|
||||||
// Group 3 would be "-"
|
for (let i = 0; i < parts.length; i++) {
|
||||||
// Only remove the first group
|
let match = parts[i].trim().match(pattern)
|
||||||
if (volumeMatch[1]) {
|
if (match && !(match[3].trim() && !match[1])) { // "101 Dalmations" shouldn't match
|
||||||
replaceChunk = volumeMatch[1] + replaceChunk
|
volumeNumber = match[2]
|
||||||
} else if (volumeMatch[4]) {
|
parts[i] = match[3]
|
||||||
replaceChunk += volumeMatch[4]
|
if (!parts[i].trim()) { parts.splice(i, 1) }
|
||||||
}
|
break
|
||||||
title = title.replace(replaceChunk, '').trim()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return [series, title, volumeNumber]
|
title = parts.join(' - ')
|
||||||
}
|
|
||||||
|
|
||||||
function getSubtitle(title) {
|
return [title, volumeNumber]
|
||||||
// Subtitle is everything after " - "
|
|
||||||
var splitTitle = title.split(' - ')
|
|
||||||
return [splitTitle.shift(), splitTitle.join(' - ')]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPublishedYear(title) {
|
function getPublishedYear(title) {
|
||||||
var publishedYear = null
|
var publishedYear = null
|
||||||
|
|
||||||
pattern = /^\(?([0-9]{4})\)? - (.+)/ //Matches #### - title or (####) - title
|
pattern = /^ *\(?([0-9]{4})\)? *- *(.+)/ //Matches #### - title or (####) - title
|
||||||
var match = title.match(pattern)
|
var match = title.match(pattern)
|
||||||
if (match) {
|
if (match) {
|
||||||
publishedYear = match[1]
|
publishedYear = match[1]
|
||||||
@ -304,6 +288,12 @@ function getPublishedYear(title) {
|
|||||||
return [title, publishedYear]
|
return [title, publishedYear]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getSubtitle(title) {
|
||||||
|
// Subtitle is everything after " - "
|
||||||
|
var splitTitle = title.split(' - ')
|
||||||
|
return [splitTitle.shift().trim(), splitTitle.join(' - ').trim()]
|
||||||
|
}
|
||||||
|
|
||||||
function getPodcastDataFromDir(folderPath, relPath) {
|
function getPodcastDataFromDir(folderPath, relPath) {
|
||||||
relPath = relPath.replace(/\\/g, '/')
|
relPath = relPath.replace(/\\/g, '/')
|
||||||
var splitDir = relPath.split('/')
|
var splitDir = relPath.split('/')
|
||||||
|
Loading…
Reference in New Issue
Block a user