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
39 changes: 39 additions & 0 deletions src/__tests__/russianArcChapters.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { parseTorrentTitle } from '../index';

// Filler-free cuts of long anime count story arcs ("главы"), not episodes or
// seasons: such a pack holds every episode of its arcs.
describe('parseTorrentTitle - Russian "N глав из M" arc counts', () => {
test('Наруто (Без филлеров) (25 глав из 25) / Naruto / 2002-2007 / ЛО (TimaMan) / DVDRip (AVC)', () => {
const result = parseTorrentTitle(
'Наруто (Без филлеров) (25 глав из 25) / Naruto / 2002-2007 / ЛО (TimaMan) / DVDRip (AVC)'
);
expect(result.seasons).toBeUndefined();
expect(result.episodes).toBeUndefined();
expect(result.title).toBe('Naruto');
});

test('Наруто: Ураганные хроники (Без филлеров) (1-18 глав из 45) / Naruto Shippuuden / 2007-2017 / ЛМ (AkariGroup) / WEBRip (720p)', () => {
const result = parseTorrentTitle(
'Наруто: Ураганные хроники (Без филлеров) (1-18 глав из 45) / Naruto Shippuuden / 2007-2017 / ЛМ (AkariGroup) / WEBRip (720p)'
);
expect(result.seasons).toBeUndefined();
expect(result.episodes).toBeUndefined();
expect(result.title).toBe('Naruto Shippuuden');
});

test('Наруто: Ураганные хроники (2 главы из 11) (Без филлеров) / Naruto: Shippuuden / 2007-2008 / HEVC / BDRip (1080p)', () => {
const result = parseTorrentTitle(
'Наруто: Ураганные хроники (2 главы из 11) (Без филлеров) / Naruto: Shippuuden / 2007-2008 / HEVC / BDRip (1080p)'
);
expect(result.seasons).toBeUndefined();
expect(result.episodes).toBeUndefined();
expect(result.title).toBe('Naruto: Shippuuden');
});

test('a chapter in a name is kept: Пламенная бригада пожарных: Вторая глава (ТВ-2)', () => {
const result = parseTorrentTitle(
'Пламенная бригада пожарных: Вторая глава (ТВ-2) / Enen no Shouboutai: Ni no Shou / Fire Force 2nd Season [TV] [24 из 24]'
);
expect(result.seasons).toEqual([2]);
});
});
11 changes: 11 additions & 0 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ function hasValueSet(field: string): boolean {

const letterRegex = /\p{L}/u;

/**
* Russian filler-free cuts count story arcs, not episodes: "(2 главы из 11)",
* "(1-18 глав из 45)". The count says nothing about seasons or episodes, so it
* is dropped before the handlers run.
*/
const arcCount =
/[(\[]\s*(?:\d{1,3}\s*-\s*)?\d{1,3}\s*глав[аы]?\s*из\s*\d{1,3}\s*[)\]]\s*/gi;

const globalTwins = new Map<RegExp, RegExp>();
/** A `g` copy of a handler pattern, so a match can be resumed past an index. */
function globalTwin(re: RegExp): RegExp {
Expand All @@ -63,6 +71,9 @@ export function parse(
): ParsedResult {
const result = new Map<string, ParseMeta>();

if (title.indexOf('глав') !== -1) {
title = title.replace(arcCount, '');
}
// The replace rewrites the whole string even when every run is already a
// single space, which is the usual case.
if (needsWhitespaceCollapse.test(title)) {
Expand Down
Loading