From f1f02b185e9fe48cdea36ec076858dbd74f5d9ec Mon Sep 17 00:00:00 2001 From: Cassie Esposito Date: Thu, 19 May 2022 22:55:00 -0700 Subject: [PATCH] Cleaned function getPublishedYear --- server/utils/scandir.js | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/server/utils/scandir.js b/server/utils/scandir.js index 2adbb600..9bb239aa 100644 --- a/server/utils/scandir.js +++ b/server/utils/scandir.js @@ -293,18 +293,14 @@ function getSubtitle(title) { function getPublishedYear(title) { 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}\)?) - (.+)/) - if (publishYearMatch && publishYearMatch.length > 2 && publishYearMatch[1]) { - // Strip parentheses - if (publishYearMatch[1].startsWith('(') && publishYearMatch[1].endsWith(')')) { - publishYearMatch[1] = publishYearMatch[1].slice(1, -1) - } - if (!isNaN(publishYearMatch[1])) { - publishedYear = publishYearMatch[1] - title = publishYearMatch[2] - } + + pattern = /^\(?([0-9]{4})\)? - (.+)/ //Matches #### - title or (####) - title + var match = title.match(pattern) + if (match) { + publishedYear = match[1] + title = match[2] } + return [title, publishedYear] }