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
54 changes: 54 additions & 0 deletions src/__tests__/studio2x2.test.ts
Original file line number Diff line number Diff line change
@@ -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]);
});
});
30 changes: 22 additions & 8 deletions src/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
Loading