From eef6305bbad589e2bfbce07954d31929a22732b2 Mon Sep 17 00:00:00 2001 From: Aidar Garikhanov Date: Wed, 7 Oct 2026 01:09:38 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20read=20Latin=20"C"=20in=20"=D0=A1=D0=B5?= =?UTF-8?q?=D0=B7=D0=BE=D0=BD"=20and=20Cyrillic=20"=D1=80"=20in=20"720?= =?UTF-8?q?=D1=80"=20as=20their=20look-alikes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Claude Opus 5.5 --- src/__tests__/cyrillicLatinLookalikes.test.ts | 43 +++++++++++++++++++ src/parser.ts | 13 ++++++ 2 files changed, 56 insertions(+) create mode 100644 src/__tests__/cyrillicLatinLookalikes.test.ts diff --git a/src/__tests__/cyrillicLatinLookalikes.test.ts b/src/__tests__/cyrillicLatinLookalikes.test.ts new file mode 100644 index 0000000..269f09d --- /dev/null +++ b/src/__tests__/cyrillicLatinLookalikes.test.ts @@ -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(); + }); +}); diff --git a/src/parser.ts b/src/parser.ts index 47514b5..5d02240 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -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 = /(? (c === 'C' ? 'С' : 'с')) + .replace(cyrillicPInResolution, '$1p'); + } let endOfTitle = title.length; // Index just past the episode marker in the (mutating) working string;