mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-01-19 20:39:32 +01:00
Cleaned function getPublishedYear
This commit is contained in:
parent
13d21e90f8
commit
f1f02b185e
@ -293,18 +293,14 @@ function getSubtitle(title) {
|
|||||||
|
|
||||||
function getPublishedYear(title) {
|
function getPublishedYear(title) {
|
||||||
var publishedYear = null
|
var publishedYear = null
|
||||||
// If Title is of format 1999 OR (1999) - Title, then use 1999 as publish year
|
|
||||||
var publishYearMatch = title.match(/^(\(?[0-9]{4}\)?) - (.+)/)
|
pattern = /^\(?([0-9]{4})\)? - (.+)/ //Matches #### - title or (####) - title
|
||||||
if (publishYearMatch && publishYearMatch.length > 2 && publishYearMatch[1]) {
|
var match = title.match(pattern)
|
||||||
// Strip parentheses
|
if (match) {
|
||||||
if (publishYearMatch[1].startsWith('(') && publishYearMatch[1].endsWith(')')) {
|
publishedYear = match[1]
|
||||||
publishYearMatch[1] = publishYearMatch[1].slice(1, -1)
|
title = match[2]
|
||||||
}
|
|
||||||
if (!isNaN(publishYearMatch[1])) {
|
|
||||||
publishedYear = publishYearMatch[1]
|
|
||||||
title = publishYearMatch[2]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return [title, publishedYear]
|
return [title, publishedYear]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user