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
49 changes: 49 additions & 0 deletions src/__tests__/russianOrdinalSeason.test.ts
Original file line number Diff line number Diff line change
@@ -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]);
});
});
27 changes: 27 additions & 0 deletions src/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
/(?<![а-яё]|(?:ТВ|TV)-\d{1,2}, ?)((?:перв|втор|трет|четв[её]рт|пят|шест|седьм|восьм|девят|десят)(?:ый|ой|ий)(?:(?:, ?| и )(?:перв|втор|трет|четв[её]рт|пят|шест|седьм|восьм|девят|десят)(?:ый|ой|ий))*) сезоны?(?![а-яё])/i,
transform: (title, m) => {
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|$)/,
Expand Down
Loading