diff --git a/src/helpers/books/audible/ChapterHelper.ts b/src/helpers/books/audible/ChapterHelper.ts index 8eda0509..680f00e4 100644 --- a/src/helpers/books/audible/ChapterHelper.ts +++ b/src/helpers/books/audible/ChapterHelper.ts @@ -59,6 +59,8 @@ class ChapterHelper { let chapterTitle = strippedTitle // Check if title is just numbers const isNotNumber = isNaN(Number(strippedTitle)) + // Check if title has an underscore between Chapter and number + const hasUnderscore = strippedTitle.includes('_') if (!isNotNumber && strippedTitle.length <= 3) { // Remove trailing period in some cases const stripPeriod: string = strippedTitle @@ -67,7 +69,11 @@ class ChapterHelper { // Convert back to string for concat const strTitle: string = numTitle.toString() chapterTitle = `${chapterNameLocale} ${strTitle}` - } + } else if (hasUnderscore) { + const splitTitle = strippedTitle.split('_') + const numTitle = splitTitle[1] + chapterTitle = `${chapterNameLocale} ${numTitle}` + } return chapterTitle } diff --git a/tests/helpers/books/audible/ChapterHelper.test.ts b/tests/helpers/books/audible/ChapterHelper.test.ts index 358fd0b3..ff90fc34 100644 --- a/tests/helpers/books/audible/ChapterHelper.test.ts +++ b/tests/helpers/books/audible/ChapterHelper.test.ts @@ -53,6 +53,8 @@ describe('ChapterHelper should', () => { expect(helper.chapterTitleCleanup('Chapter 1.')).toBe('Chapter 1') // Title with just a number is changed expect(helper.chapterTitleCleanup('123')).toBe('Chapter 123') + // Title with an underscore is changed + expect(helper.chapterTitleCleanup('Chapter_1')).toBe('Chapter 1') }) test('sign request', () => {