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
102 changes: 102 additions & 0 deletions src/__tests__/russianLists.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
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;
}

// Russian trackers list the episodes or seasons a release has, with gaps:
// "серии 1-4, 6-10" is episodes 1-4 and 6-10.
describe('parseTorrentTitle - Russian episode and season lists', () => {
test('Игра престолов / Game of Thrones (2016) HDTV [H.264/1080p] (сезон 6, серии 1-4, 6-10 из 10) BaibaKo (обновляемая)', () => {
const result = parseTorrentTitle(
'Игра престолов / Game of Thrones (2016) HDTV [H.264/1080p] (сезон 6, серии 1-4, 6-10 из 10) BaibaKo (обновляемая)'
);
expect(result.seasons).toEqual([6]);
expect(result.episodes).toEqual([...intRange(1, 4), ...intRange(6, 10)]);
});

test('Новые пацаны / New kids / New kids on the block / Сезон: 3 / Серии: 1-3,5,8-10,12-13,16,18 из 19 (Стеффен Хаарс / Steffen Haars)', () => {
const result = parseTorrentTitle(
'Новые пацаны / New kids / New kids on the block / Сезон: 3 / Серии: 1-3,5,8-10,12-13,16,18 из 19 (Стеффен Хаарс / Steffen Haars)'
);
expect(result.seasons).toEqual([3]);
expect(result.episodes).toEqual([1, 2, 3, 5, 8, 9, 10, 12, 13, 16, 18]);
});

test('Гриффины / Family Guy [15x01-13, 15-17, 19, 20 из 20] (2016-2017) HDTVRip-AVC | Filiza', () => {
const result = parseTorrentTitle(
'Гриффины / Family Guy [15x01-13, 15-17, 19, 20 из 20] (2016-2017) HDTVRip-AVC | Filiza'
);
expect(result.seasons).toEqual([15]);
expect(result.episodes).toEqual([...intRange(1, 13), 15, 16, 17, 19, 20]);
});

test('Династии / Dynasties / Сезон 2 / Серии 1,3-6 из 6 (Лидия Бэйнс, Саймон Блэкни) [2020, Документальный, HDTVRip 1080p]', () => {
const result = parseTorrentTitle(
'Династии / Dynasties / Сезон 2 / Серии 1,3-6 из 6 (Лидия Бэйнс, Саймон Блэкни) [2020, Документальный, HDTVRip 1080p]'
);
expect(result.seasons).toEqual([2]);
expect(result.episodes).toEqual([1, 3, 4, 5, 6]);
});

test('a list does not run into the resolution', () => {
const result = parseTorrentTitle('Сериал (сезон 1, серии 1-12, 1080p)');
expect(result.episodes).toEqual(intRange(1, 12));
});

test('Игра престолов (1-2, 4-7 сезоны: 1-57 серии из 57) / Game of Thrones / 2011-2017 / ПМ (FOX) / HDTVRip', () => {
const result = parseTorrentTitle(
'Игра престолов (1-2, 4-7 сезоны: 1-57 серии из 57) / Game of Thrones / 2011-2017 / ПМ (FOX) / HDTVRip'
);
expect(result.seasons).toEqual([1, 2, 4, 5, 6, 7]);
expect(result.episodes).toEqual(intRange(1, 57));
expect(result.title).toBe('Игра престолов');
});

test('Южный парк / South Park / 9,10,11,12 сезоны / WEB-DLRip/BDRip / Озвучка MTV', () => {
const result = parseTorrentTitle(
'Южный парк / South Park / 9,10,11,12 сезоны / WEB-DLRip/BDRip / Озвучка MTV'
);
expect(result.seasons).toEqual([9, 10, 11, 12]);
});

test('Компьютершики (Сезоны 1 и 2) / The IT Crowd (Graham Linehan) [2006-2007, Великобритания, Комедия, DVD5 (сжатый)]', () => {
const result = parseTorrentTitle(
'Компьютершики (Сезоны 1 и 2) / The IT Crowd (Graham Linehan) [2006-2007, Великобритания, Комедия, DVD5 (сжатый)]'
);
expect(result.seasons).toEqual([1, 2]);
expect(result.title).toBe('The IT Crowd');
});

test('Компьютершики / The IT Crowd Series 1 & 2 & 3 Complete (Graham Linehan) [2006, Великобритания, Комедия, DVDRip]', () => {
const result = parseTorrentTitle(
'Компьютершики / The IT Crowd Series 1 & 2 & 3 Complete (Graham Linehan) [2006, Великобритания, Комедия, DVDRip]'
);
expect(result.seasons).toEqual([1, 2, 3]);
});

test('Клан Сопрано (Семья Сопрано) / The Sopranos (Все 6 Сезонов, Озвучка) (1999-2007) DVDRip', () => {
const result = parseTorrentTitle(
'Клан Сопрано (Семья Сопрано) / The Sopranos (Все 6 Сезонов, Озвучка) (1999-2007) DVDRip'
);
expect(result.seasons).toEqual(intRange(1, 6));
});
test('Игра Престолов / Game of Thrones (2013) BDRemux [1080p] [Сезон 3, 10 серий из 10]', () => {
const result = parseTorrentTitle(
'Игра Престолов / Game of Thrones (2013) BDRemux [1080p] [Сезон 3, 10 серий из 10]'
);
expect(result.seasons).toEqual([3]);
});

test('Приключения Шерлока Холмса / The Adventures of Sherlock Holmes (Сезон 1, 6 серия) (John Hawkesworth) [1984, Великобритания, детектив, DVDRip]', () => {
const result = parseTorrentTitle(
'Приключения Шерлока Холмса / The Adventures of Sherlock Holmes (Сезон 1, 6 серия) (John Hawkesworth) [1984, Великобритания, детектив, DVDRip]'
);
expect(result.seasons).toEqual([1]);
expect(result.episodes).toEqual([6]);
});
});
38 changes: 36 additions & 2 deletions src/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import {
toValueSetWithTransform,
toValueSetMultiWithTransform,
toIntArray,
toIntRangeTill
toIntRangeTill,
toIntList
} from './transforms.js';
import {
validateAnd,
Expand Down Expand Up @@ -1357,9 +1358,20 @@ export const handlers: Handler[] = [
{
field: 'seasons',
pattern:
/(?:(?:\bthe\W)?\bcomplete\W)?(?:seasons?|[Сс]езон[иы]?|sezon|temporadas?|stagioni)[. ]?[-:]?[. ]?[(\[]?((?:\d{1,2} ?(?:[,/\\&]+ ?)+)+\d{1,2}\b)[)\]]?/i,
/(?:(?:\bthe\W)?\bcomplete\W)?(?:seasons?|series|[Сс]езон[иы]?|sezon|temporadas?|stagioni)[. ]?[-:]?[. ]?[(\[]?((?:\d{1,2} ?(?:[,/\\&]+ ?)+)+\d{1,2}\b)(?![. ]*(?:сери|эпизод))[)\]]?/i,
transform: toIntRange()
},
{
field: 'seasons',
// "Сезоны 1 и 2"; the name continues after it
pattern:
/[Сс]езоны?:?[. ]?(\d{1,2}(?: и \d{1,2})+)(?![. ]*(?:сери|эпизод))/,
transform: (title, m, result) => {
m.value = String(m.value).replace(/ и /g, ',');
toIntList()(title, m, result);
},
skipFromTitle: true
},
{
field: 'seasons',
pattern:
Expand Down Expand Up @@ -1409,6 +1421,21 @@ export const handlers: Handler[] = [
/\bseason\b[ .-]?(\d{1,2}[ .-]?(?:to|thru|and|\+)[ .-]?\bseason\b[ .-]?\d{1,2})/i,
transform: toIntRange()
},
{
field: 'seasons',
// A list of seasons before the word: "(1-2, 4-7 сезоны: …)", "(1-9, 14 сезоны: …)"
pattern:
/(?<![\dxх-])((?:\d{1,2}(?:[ .]?[-–][ .]?\d{1,2})?[ .]?,[ .]?)+\d{1,2}(?:[ .]?[-–][ .]?\d{1,2})?)[. _]?[Сс]езон(?:ы|ов|а)?(?![а-яё])/i,
transform: toIntList(),
remove: true
},
{
field: 'seasons',
// "Все 6 сезонов": every season up to N
pattern: /[Вв]се[ .](\d{1,2})[ .][Сс]езон(?:а|ов)/,
transform: toIntRangeTill(),
remove: true
},
{
field: 'seasons',
pattern:
Expand Down Expand Up @@ -1584,6 +1611,13 @@ export const handlers: Handler[] = [
/(?:[\W\d]|^)\d+[xх][ .]?[(\[]?(\d{1,3}(?:[ .]?[xх][ .]?\d{1,3})+)(?:\W|$)/i,
transform: toIntRange()
},
{
field: 'episodes',
// A list with gaps: "серии 1-4, 6-10", "Серии: 1-3,5,8-10", "[15x01-13, 15-17, 19]"
pattern:
/(?:[Сс]ери[ияй]|[Ээ]пизоды|episodes|\d{1,2}[xх])[ .:]*[(\[]?(\d{1,4}(?:[ .]?[-–][ .]?\d{1,4})?(?:[ .]?,[ .]?\d{1,4}(?:[ .]?[-–][ .]?\d{1,4})?(?![\d.]|[pi]\b))+)/i,
transform: toIntList()
},
{
field: 'episodes',
pattern:
Expand Down
37 changes: 36 additions & 1 deletion src/transforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,4 +302,39 @@ export function toIntRangeTill(): HandlerTransformer {

m.value = null;
};
}
}

/**
* A comma list of numbers and ranges, possibly with gaps: "1-4, 6-10" ->
* [1,2,3,4,6,7,8,9,10]. Each part must come after the previous one.
*/
export function toIntList(): HandlerTransformer {
return (title: string, m: ParseMeta): void => {
if (typeof m.value !== 'string') {
m.value = null;
return;
}

const nums: number[] = [];
for (const part of m.value.split(',')) {
const bounds = part
.split(/[-–]/)
.map((p) => parseInt(p.trim(), 10))
.filter((n) => !isNaN(n));
if (bounds.length < 1 || bounds.length > 2) {
m.value = null;
return;
}
const start = bounds[0];
const end = bounds.length === 2 ? bounds[1] : bounds[0];
if (end < start || (nums.length > 0 && start <= nums[nums.length - 1])) {
m.value = null;
return;
}
for (let i = start; i <= end; i++) {
nums.push(i);
}
}
m.value = nums.length > 0 ? nums : null;
};
}
Loading