Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions src/__tests__/multiSeasonXRange.test.ts
Original file line number Diff line number Diff line change
@@ -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));
});
});
16 changes: 14 additions & 2 deletions src/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
},
Expand Down Expand Up @@ -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
Expand Down
Loading