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

// Uploaders mix Latin and Cyrillic look-alikes: "Cезон" starts with a Latin C,
// "720р" ends with a Cyrillic р.
describe('parseTorrentTitle - Cyrillic and Latin look-alike letters', () => {
test('Королевство / Kingdeom [1 cезон] (2019) WEBRip 1080p | IdeaFilm', () => {
const result = parseTorrentTitle(
'Королевство / Kingdeom [1 cезон] (2019) WEBRip 1080p | IdeaFilm'
);
expect(result.seasons).toEqual([1]);
expect(result.episodes).toBeUndefined();
});

test('Как я встретил вашу маму / How I Met Your Mother [Cезон 1-7, Серия 1-160 из 160] (2005-2011) DVDRip', () => {
const result = parseTorrentTitle(
'Как я встретил вашу маму / How I Met Your Mother [Cезон 1-7, Серия 1-160 из 160] (2005-2011) DVDRip'
);
expect(result.seasons).toEqual([1, 2, 3, 4, 5, 6, 7]);
expect(result.title).toBe('How I Met Your Mother');
});

test('Ходячие мертвецы / The Walking Dead [7 сезон] (2016) HDTVRip 720р | Sunshine Studio', () => {
const result = parseTorrentTitle(
'Ходячие мертвецы / The Walking Dead [7 сезон] (2016) HDTVRip 720р | Sunshine Studio'
);
expect(result.seasons).toEqual([7]);
expect(result.episodes).toBeUndefined();
expect(result.resolution).toBe('720p');
});

test('Бруклин 9-9 / Brooklyn Nine-Nine [4 сезон] (2016-2017) WEB-DL 1080р | NewStudio', () => {
const result = parseTorrentTitle(
'Бруклин 9-9 / Brooklyn Nine-Nine [4 сезон] (2016-2017) WEB-DL 1080р | NewStudio'
);
expect(result.seasons).toEqual([4]);
expect(result.episodes).toBeUndefined();
expect(result.resolution).toBe('1080p');
});
test('a price in roubles is not a resolution', () => {
const result = parseTorrentTitle('Фильм (2020) цена 500р');
expect(result.resolution).toBeUndefined();
});
});
13 changes: 13 additions & 0 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ const grams = new GramSet();
/** Whitespace that `\s+` -> " " would actually change: a run, or a non-space. */
const needsWhitespaceCollapse = /\s\s|[^\S ]/;

/**
* Latin letters typed in place of their Cyrillic look-alikes, which no handler
* can see: a Latin "C" in "Сезон" and a Cyrillic "р" in a resolution, "720р".
*/
const lookalikes = /[Cc]езон|(?:480|576|720|1080|2160)р(?![а-яё])/;
const latinCInSeason = /([Cc])(?=езон)/g;
const cyrillicPInResolution = /(?<!\d)(480|576|720|1080|2160)р(?![а-яё])/g;

const OPEN_SQUARE_BRACKET = 91;

/**
Expand Down Expand Up @@ -71,6 +79,11 @@ export function parse(
if (title.indexOf('_') !== -1) {
title = title.replace(underscoresRegex, ' ');
}
if (lookalikes.test(title)) {
title = title
.replace(latinCInSeason, (c) => (c === 'C' ? 'С' : 'с'))
.replace(cyrillicPInResolution, '$1p');
}

let endOfTitle = title.length;
// Index just past the episode marker in the (mutating) working string;
Expand Down
Loading