From fcfda748b76c7a8008656e19db87033a9d8a90ec Mon Sep 17 00:00:00 2001 From: Aidar Garikhanov Date: Wed, 7 Oct 2026 01:11:16 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20parse=20"[01-04x01-75=20=D0=B8=D0=B7=208?= =?UTF-8?q?7]"=20and=20"[S01-02x01-78]"=20as=20a=20season=20range?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Claude Opus 5.5 --- src/__tests__/multiSeasonXRange.test.ts | 53 +++++++++++++++++++++++++ src/handlers.ts | 16 +++++++- 2 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 src/__tests__/multiSeasonXRange.test.ts diff --git a/src/__tests__/multiSeasonXRange.test.ts b/src/__tests__/multiSeasonXRange.test.ts new file mode 100644 index 0000000..c2b15ec --- /dev/null +++ b/src/__tests__/multiSeasonXRange.test.ts @@ -0,0 +1,53 @@ +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; +} + +// Rutor writes a multi-season pack as "[01-04x01-75 из 87]": seasons 1-4, +// episodes 1-75 counted through the seasons. +describe('parseTorrentTitle - "[A-BxC-D]" multi-season packs', () => { + test('Атака титанов / Вторжение титанов / Shingeki no Kyojin [01-04x01-75 из 87] (2013-2021) WEBRip 720p | StudioBand', () => { + const result = parseTorrentTitle( + 'Атака титанов / Вторжение титанов / Shingeki no Kyojin [01-04x01-75 из 87] (2013-2021) WEBRip 720p | StudioBand' + ); + expect(result.seasons).toEqual([1, 2, 3, 4]); + expect(result.episodes).toEqual(intRange(1, 75)); + }); + + test("Друзья ангелов / Angel's Friends [S01-02x01-78 из 104] (2009-2010) DVDRip от New-Team | D, P", () => { + const result = parseTorrentTitle( + "Друзья ангелов / Angel's Friends [S01-02x01-78 из 104] (2009-2010) DVDRip от New-Team | D, P" + ); + expect(result.seasons).toEqual([1, 2]); + expect(result.episodes).toEqual(intRange(1, 78)); + }); + + test('Универ [03-05x101-225] (2009-2010) SATRip от iolegv-RuUu & ANDROZZZ (BigFANGroup)', () => { + const result = parseTorrentTitle( + 'Универ [03-05x101-225] (2009-2010) SATRip от iolegv-RuUu & ANDROZZZ (BigFANGroup)' + ); + expect(result.seasons).toEqual([3, 4, 5]); + expect(result.episodes).toEqual(intRange(101, 225)); + }); + + test('Пацаны / The Boys [01-04x01-26 из 32] (2019-2024) WEB-DLRip | Кубик в кубе', () => { + const result = parseTorrentTitle( + 'Пацаны / The Boys [01-04x01-26 из 32] (2019-2024) WEB-DLRip | Кубик в кубе' + ); + expect(result.seasons).toEqual([1, 2, 3, 4]); + expect(result.title).toBe('The Boys'); + }); + + test('a single season stays single', () => { + const result = parseTorrentTitle( + 'Игра престолов [01x01-10 из 10] (2011) BDRip 1080p' + ); + expect(result.seasons).toEqual([1]); + expect(result.episodes).toEqual(intRange(1, 10)); + }); +}); diff --git a/src/handlers.ts b/src/handlers.ts index ad5f255..edd28e0 100644 --- a/src/handlers.ts +++ b/src/handlers.ts @@ -1329,6 +1329,12 @@ export const handlers: Handler[] = [ }, // Batch 7: Seasons handlers (lines 1727-1868 in handlers.go) + { + field: 'seasons', + // A season range before the episodes: "[01-04x01-75 из 87]", "[S01-02x01-78]" + pattern: /[\[(]S?(\d{1,2}[ .]?-[ .]?S?\d{1,2})[ .]?[xх][ .]?\d{1,4}/i, + transform: toIntRange() + }, { field: 'seasons', pattern: @@ -1457,7 +1463,11 @@ export const handlers: Handler[] = [ field: 'seasons', pattern: /(?:(?:\bthe\W)?\bcomplete)?(?:\W|^)so?([01]?[0-5]?[1-9])(?:[\Wex]|\d{2}\b)/i, - validateMatch: validateNotStartSpaced(), + validateMatch: validateAnd( + validateNotStartSpaced(), + // the start of a season range "[S01-02x01-78]" + validateLookahead('\\d{1,2}[ .]?[xх]', 'i', false) + ), transform: toIntArray(), keepMatching: true }, @@ -1536,7 +1546,9 @@ export const handlers: Handler[] = [ /(?:(?:\bthe\W)?\bcomplete)?(?:[a-z])?\bs(\d{1,3})(?:[\Wex]|\d{2}\b|$)/i, validateMatch: validateAnd( validateNotMatch(/(?:[a-z])\bs\d{1,3}/i), - validateNotStartSpaced() + validateNotStartSpaced(), + // the start of a season range "[S01-02x01-78]" + validateLookahead('\\d{1,2}[ .]?[xх]', 'i', false) ), transform: toIntArray(), keepMatching: true