diff --git a/src/__tests__/russianArcChapters.test.ts b/src/__tests__/russianArcChapters.test.ts new file mode 100644 index 0000000..26f340b --- /dev/null +++ b/src/__tests__/russianArcChapters.test.ts @@ -0,0 +1,39 @@ +import { parseTorrentTitle } from '../index'; + +// Filler-free cuts of long anime count story arcs ("главы"), not episodes or +// seasons: such a pack holds every episode of its arcs. +describe('parseTorrentTitle - Russian "N глав из M" arc counts', () => { + test('Наруто (Без филлеров) (25 глав из 25) / Naruto / 2002-2007 / ЛО (TimaMan) / DVDRip (AVC)', () => { + const result = parseTorrentTitle( + 'Наруто (Без филлеров) (25 глав из 25) / Naruto / 2002-2007 / ЛО (TimaMan) / DVDRip (AVC)' + ); + expect(result.seasons).toBeUndefined(); + expect(result.episodes).toBeUndefined(); + expect(result.title).toBe('Naruto'); + }); + + test('Наруто: Ураганные хроники (Без филлеров) (1-18 глав из 45) / Naruto Shippuuden / 2007-2017 / ЛМ (AkariGroup) / WEBRip (720p)', () => { + const result = parseTorrentTitle( + 'Наруто: Ураганные хроники (Без филлеров) (1-18 глав из 45) / Naruto Shippuuden / 2007-2017 / ЛМ (AkariGroup) / WEBRip (720p)' + ); + expect(result.seasons).toBeUndefined(); + expect(result.episodes).toBeUndefined(); + expect(result.title).toBe('Naruto Shippuuden'); + }); + + test('Наруто: Ураганные хроники (2 главы из 11) (Без филлеров) / Naruto: Shippuuden / 2007-2008 / HEVC / BDRip (1080p)', () => { + const result = parseTorrentTitle( + 'Наруто: Ураганные хроники (2 главы из 11) (Без филлеров) / Naruto: Shippuuden / 2007-2008 / HEVC / BDRip (1080p)' + ); + expect(result.seasons).toBeUndefined(); + expect(result.episodes).toBeUndefined(); + expect(result.title).toBe('Naruto: Shippuuden'); + }); + + test('a chapter in a name is kept: Пламенная бригада пожарных: Вторая глава (ТВ-2)', () => { + const result = parseTorrentTitle( + 'Пламенная бригада пожарных: Вторая глава (ТВ-2) / Enen no Shouboutai: Ni no Shou / Fire Force 2nd Season [TV] [24 из 24]' + ); + expect(result.seasons).toEqual([2]); + }); +}); diff --git a/src/parser.ts b/src/parser.ts index 47514b5..b8ffe69 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -42,6 +42,14 @@ function hasValueSet(field: string): boolean { const letterRegex = /\p{L}/u; +/** + * Russian filler-free cuts count story arcs, not episodes: "(2 главы из 11)", + * "(1-18 глав из 45)". The count says nothing about seasons or episodes, so it + * is dropped before the handlers run. + */ +const arcCount = + /[(\[]\s*(?:\d{1,3}\s*-\s*)?\d{1,3}\s*глав[аы]?\s*из\s*\d{1,3}\s*[)\]]\s*/gi; + const globalTwins = new Map(); /** A `g` copy of a handler pattern, so a match can be resumed past an index. */ function globalTwin(re: RegExp): RegExp { @@ -63,6 +71,9 @@ export function parse( ): ParsedResult { const result = new Map(); + if (title.indexOf('глав') !== -1) { + title = title.replace(arcCount, ''); + } // The replace rewrites the whole string even when every run is already a // single space, which is the usual case. if (needsWhitespaceCollapse.test(title)) {