From 95f301b34dc78119fc7111344b5c4c85d8325c71 Mon Sep 17 00:00:00 2001 From: Aidar Garikhanov Date: Wed, 7 Oct 2026 01:12:10 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20parse=20Russian=20ordinal=20season=20wor?= =?UTF-8?q?ds=20("=D0=B2=D1=82=D0=BE=D1=80=D0=BE=D0=B9=20=D1=81=D0=B5?= =?UTF-8?q?=D0=B7=D0=BE=D0=BD",=20"=D0=BF=D0=B5=D1=80=D0=B2=D1=8B=D0=B9,?= =?UTF-8?q?=20=D0=B2=D1=82=D0=BE=D1=80=D0=BE=D0=B9=20=D1=81=D0=B5=D0=B7?= =?UTF-8?q?=D0=BE=D0=BD=D1=8B")?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Claude Opus 5.5 --- src/__tests__/russianOrdinalSeason.test.ts | 49 ++++++++++++++++++++++ src/handlers.ts | 27 ++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 src/__tests__/russianOrdinalSeason.test.ts diff --git a/src/__tests__/russianOrdinalSeason.test.ts b/src/__tests__/russianOrdinalSeason.test.ts new file mode 100644 index 0000000..433997f --- /dev/null +++ b/src/__tests__/russianOrdinalSeason.test.ts @@ -0,0 +1,49 @@ +import { parseTorrentTitle } from '../index'; + +function intRange(start: number, end: number): number[] { + const result: number[] = []; + for (let i = start; i <= end; i++) { + result.push(i); + } + return result; +} + +// The season number can be written as an ordinal word: "(второй сезон)". +describe('parseTorrentTitle - Russian ordinal season words', () => { + test('Code Geass: Lelouch of the Rebellion R2 / Код Гиас: Восставший Лелуш (второй сезон) (25 из 25) Complete [720p]', () => { + const result = parseTorrentTitle( + 'Code Geass: Lelouch of the Rebellion R2 / Код Гиас: Восставший Лелуш (второй сезон) (25 из 25) Complete [720p]' + ); + expect(result.seasons).toEqual([2]); + expect(result.episodes).toEqual(intRange(1, 25)); + }); + + test('Ginga Eiyuu Densetsu: Die Neue These - Gekitotsu / Легенда о героях Галактики (третий сезон) (12 из 12) Complete [1080p]', () => { + const result = parseTorrentTitle( + 'Ginga Eiyuu Densetsu: Die Neue These - Gekitotsu / Легенда о героях Галактики (третий сезон) (12 из 12) Complete [1080p]' + ); + expect(result.seasons).toEqual([3]); + }); + + test('Драконий жемчуг Зет (Второй Сезон) / Dragon Ball Z [TV] [001-125 из 291] [RUS(int),JAP] [1989]', () => { + const result = parseTorrentTitle( + 'Драконий жемчуг Зет (Второй Сезон) / Dragon Ball Z [TV] [001-125 из 291] [RUS(int),JAP] [1989]' + ); + expect(result.seasons).toEqual([2]); + expect(result.title).toBe('Dragon Ball Z'); + }); + + test('Code Geass Hangyaku no Lelouch | Code Geass - Lelouch of the Rebellion | Код Гиас: Восставший Лелуш (первый, второй сезоны) [2006, TV, 50 эп.] BDRip 1080p', () => { + const result = parseTorrentTitle( + 'Code Geass Hangyaku no Lelouch | Code Geass - Lelouch of the Rebellion | Код Гиас: Восставший Лелуш (первый, второй сезоны) [2006, TV, 50 эп.] BDRip 1080p' + ); + expect(result.seasons).toEqual([1, 2]); + }); + + test('"ТВ-N, первый сезон" keeps the TV season', () => { + const result = parseTorrentTitle( + 'Tensei Shitara Slime Datta Ken (2021) / О моем перерождении в слизь [ТВ-2, первый сезон] (12 из 12) Complete [1080p]' + ); + expect(result.seasons).toEqual([2]); + }); +}); diff --git a/src/handlers.ts b/src/handlers.ts index ad5f255..9791e97 100644 --- a/src/handlers.ts +++ b/src/handlers.ts @@ -1473,6 +1473,33 @@ export const handlers: Handler[] = [ /(?:(?:\bthe\W)?\bcomplete\W)?(?:\W|^)(\d{1,2})[. ]?(?:st|nd|rd|th)[. ]*season/i, transform: toIntArray() }, + { + field: 'seasons', + // A season number in words: "(второй сезон)", "(первый, второй сезоны)" + pattern: + /(? { + const stems = [ + 'перв', + 'втор', + 'трет', + 'четв', + 'пят', + 'шест', + 'седьм', + 'восьм', + 'девят', + 'десят' + ]; + m.value = String(m.value) + .toLowerCase() + .split(/, ?| и /) + .map((word) => stems.findIndex((stem) => word.startsWith(stem)) + 1); + }, + remove: true, + // a season marker inside the name, not its end + skipFromTitle: true + }, { field: 'seasons', pattern: /(?:\D|^)(\d{1,2})[Xxх]\d{1,3}(?:\D|$)/,