diff --git a/src/__tests__/studio2x2.test.ts b/src/__tests__/studio2x2.test.ts new file mode 100644 index 0000000..52a2fa1 --- /dev/null +++ b/src/__tests__/studio2x2.test.ts @@ -0,0 +1,54 @@ +import { parseTorrentTitle } from '../index'; + +// "2x2" is a Russian TV channel and dubbing studio, listed with the voice-overs +// of a release. It is not season 2 episode 2. +describe('parseTorrentTitle - "2x2" dubbing studio', () => { + test('Наруто: Ураганные хроники (1-500 серии из 500) / Naruto Shippuuden / 2007-2017 / ПМ (2x2) / IPTVRip (720p)', () => { + const result = parseTorrentTitle( + 'Наруто: Ураганные хроники (1-500 серии из 500) / Naruto Shippuuden / 2007-2017 / ПМ (2x2) / IPTVRip (720p)' + ); + expect(result.seasons).toBeUndefined(); + expect(result.episodes?.length).toBe(500); + }); + + test('Симпсоны / The Simpsons [S27] (2015-2016) WEBRip-HEVC 1080p | 2x2', () => { + const result = parseTorrentTitle( + 'Симпсоны / The Simpsons [S27] (2015-2016) WEBRip-HEVC 1080p | 2x2' + ); + expect(result.seasons).toEqual([27]); + expect(result.episodes).toBeUndefined(); + }); + + test('Американский папаша / American Dad! [S01-16] (2005-2020) WEB-DL-HEVC 1080p | 2x2, Filiza, Jaskier, TVShows', () => { + const result = parseTorrentTitle( + 'Американский папаша / American Dad! [S01-16] (2005-2020) WEB-DL-HEVC 1080p | 2x2, Filiza, Jaskier, TVShows' + ); + expect(result.seasons?.length).toBe(16); + expect(result.episodes).toBeUndefined(); + }); + + test('Симпсоны / The Simpsons [S18] (2006) WEBRip-HEVC 720p | 2х2', () => { + const result = parseTorrentTitle( + 'Симпсоны / The Simpsons [S18] (2006) WEBRip-HEVC 720p | 2х2' + ); + expect(result.seasons).toEqual([18]); + expect(result.episodes).toBeUndefined(); + }); + + test('padded "2x02" is still season 2 episode 2', () => { + const result = parseTorrentTitle('Show.Name.2x02.HDTV.XviD'); + expect(result.seasons).toEqual([2]); + expect(result.episodes).toEqual([2]); + }); + test('Seinfeld 2x2 The Pony Remark.avi: without Cyrillic "2x2" is season 2 episode 2', () => { + const result = parseTorrentTitle('Seinfeld 2x2 The Pony Remark.avi'); + expect(result.seasons).toEqual([2]); + expect(result.episodes).toEqual([2]); + }); + + test('Lost.2x2.HDTV.XviD', () => { + const result = parseTorrentTitle('Lost.2x2.HDTV.XviD'); + expect(result.seasons).toEqual([2]); + expect(result.episodes).toEqual([2]); + }); +}); diff --git a/src/handlers.ts b/src/handlers.ts index ad5f255..d1ae6af 100644 --- a/src/handlers.ts +++ b/src/handlers.ts @@ -44,6 +44,14 @@ import { removeFromValue } from './processors.js'; * * Start porting from line 284 of handlers.go */ +// "2x2" is a Russian TV channel and dubbing studio ("ПМ (2x2)", "kubik&ko, 2x2"): +// in a name with Cyrillic letters an unpadded "2x2" is not season 2 episode 2 +const studio2x2Match = /^\D?2[. ]?[Xxх][. ]?2(?:\D|$)/; +const cyrillicLetter = /[а-яё]/i; +const isStudio2x2 = (input: string, idxs: number[]): boolean => + studio2x2Match.test(input.substring(idxs[0], idxs[1])) && + cyrillicLetter.test(input); + export const handlers: Handler[] = [ // Title handlers (lines 285-292 in handlers.go) { @@ -1478,10 +1486,13 @@ export const handlers: Handler[] = [ pattern: /(?:\D|^)(\d{1,2})[Xxх]\d{1,3}(?:\D|$)/, validateMatch: (input: string, idxs: number[]): boolean => { // Reject matches that begin inside a decimal figure (e.g. the ".0x3" of "2.0x3") - return !( - input[idxs[0]] === '.' && - idxs[0] > 0 && - /\d/.test(input[idxs[0] - 1]) + // and the Russian dubbing studio "2x2" ("ПМ (2x2)") + return ( + !( + input[idxs[0]] === '.' && + idxs[0] > 0 && + /\d/.test(input[idxs[0] - 1]) + ) && !isStudio2x2(input, idxs) ); }, transform: toIntArray() @@ -1791,10 +1802,13 @@ export const handlers: Handler[] = [ pattern: /(?:\D|^)\d{1,2}[. ]?[Xxх][. ]?(\d{1,3})(?:[abc]|v0?[1-4]|\D|$)/i, validateMatch: (input: string, idxs: number[]): boolean => { // Reject matches that begin inside a decimal figure (e.g. the ".0x3" of "2.0x3") - return !( - input[idxs[0]] === '.' && - idxs[0] > 0 && - /\d/.test(input[idxs[0] - 1]) + // and the Russian dubbing studio "2x2" ("ПМ (2x2)") + return ( + !( + input[idxs[0]] === '.' && + idxs[0] > 0 && + /\d/.test(input[idxs[0] - 1]) + ) && !isStudio2x2(input, idxs) ); }, transform: toIntArray()