From 7101703e8fe60ac349cf758233f6be8d49074c92 Mon Sep 17 00:00:00 2001 From: Aidar Garikhanov Date: Fri, 27 Nov 2026 02:47:00 +0300 Subject: [PATCH 1/2] fix: do not read the "16x9" aspect ratio as season 16 episode 9 Co-authored-by: Claude Fable 5.2 --- src/__tests__/aspectRatio.test.ts | 135 ++++++++++++++++++++++++++++++ src/handlers.ts | 21 +++++ 2 files changed, 156 insertions(+) create mode 100644 src/__tests__/aspectRatio.test.ts diff --git a/src/__tests__/aspectRatio.test.ts b/src/__tests__/aspectRatio.test.ts new file mode 100644 index 0000000..5145453 --- /dev/null +++ b/src/__tests__/aspectRatio.test.ts @@ -0,0 +1,135 @@ +import { parseTorrentTitle } from '../index'; + +// "16x9" and "4x3" listed after the resolution or the source of a release are +// the aspect ratio of the video. They are not a season and an episode. +describe('parseTorrentTitle - aspect ratio', () => { + test('Сумерки. Сага. Рассвет: Часть 2 / The Twilight Saga: Breaking Dawn - Part 2 (Билл Кондон / Bill Condon) [2012, США, фэнтези, драма, мелодрама, приключения, BDRip 1080p, 16x9] Dub + UKR + Original + Sub Rus + Original Eng', () => { + const result = parseTorrentTitle( + 'Сумерки. Сага. Рассвет: Часть 2 / The Twilight Saga: Breaking Dawn - Part 2 (Билл Кондон / Bill Condon) [2012, США, фэнтези, драма, мелодрама, приключения, BDRip 1080p, 16x9] Dub + UKR + Original + Sub Rus + Original Eng' + ); + expect(result.seasons).toBeUndefined(); + expect(result.episodes).toBeUndefined(); + expect(result.title).toBe('The Twilight Saga: Breaking Dawn - Part 2'); + expect(result.year).toBe('2012'); + expect(result.resolution).toBe('1080p'); + expect(result.quality).toBe('BDRip'); + }); + + test('Сияние / The Shining (Стэнли Кубрик / Stanley Kubrick) [1980, США, мистика, DVDRemux] [FULLSCREEN / 4X3 / ПОЛНОЕ ИЗДАНИЕ] 18X AVO, MVO, DVO, Dub + Sub Eng, Rus, Ukr + Original Eng', () => { + const result = parseTorrentTitle( + 'Сияние / The Shining (Стэнли Кубрик / Stanley Kubrick) [1980, США, мистика, DVDRemux] [FULLSCREEN / 4X3 / ПОЛНОЕ ИЗДАНИЕ] 18X AVO, MVO, DVO, Dub + Sub Eng, Rus, Ukr + Original Eng' + ); + expect(result.seasons).toBeUndefined(); + expect(result.episodes).toBeUndefined(); + expect(result.title).toBe('The Shining'); + expect(result.year).toBe('1980'); + }); + + test('Movie.2012.BDRip.1080p.16x9.x264', () => { + const result = parseTorrentTitle('Movie.2012.BDRip.1080p.16x9.x264'); + expect(result.seasons).toBeUndefined(); + expect(result.episodes).toBeUndefined(); + expect(result.title).toBe('Movie'); + expect(result.resolution).toBe('1080p'); + expect(result.quality).toBe('BDRip'); + expect(result.codec).toBe('x264'); + }); + + test('Movie 2012 DVDRip WS 16х9: Cyrillic "х"', () => { + const result = parseTorrentTitle('Movie 2012 DVDRip WS 16х9'); + expect(result.title).toBe('Movie'); + expect(result.seasons).toBeUndefined(); + expect(result.episodes).toBeUndefined(); + expect(result.quality).toBe('DVDRip'); + }); + + test('Movie.2012.INTERNAL.BDRip.1080p.16x9.x264', () => { + const result = parseTorrentTitle( + 'Movie.2012.INTERNAL.BDRip.1080p.16x9.x264' + ); + expect(result.seasons).toBeUndefined(); + expect(result.episodes).toBeUndefined(); + expect(result.title).toBe('Movie'); + expect(result.resolution).toBe('1080p'); + }); + + test('Movie 2012 HFR 2160p 16x9', () => { + const result = parseTorrentTitle('Movie 2012 HFR 2160p 16x9'); + expect(result.seasons).toBeUndefined(); + expect(result.episodes).toBeUndefined(); + expect(result.title).toBe('Movie'); + expect(result.resolution).toBe('4k'); + }); + + test('Movie 2012 Remux 16x9', () => { + const result = parseTorrentTitle('Movie 2012 Remux 16x9'); + expect(result.seasons).toBeUndefined(); + expect(result.episodes).toBeUndefined(); + expect(result.title).toBe('Movie'); + }); + + test('Фильм / Movie [2010, США, VHSRip, 4x3] AVO', () => { + const result = parseTorrentTitle( + 'Фильм / Movie [2010, США, VHSRip, 4x3] AVO' + ); + expect(result.seasons).toBeUndefined(); + expect(result.episodes).toBeUndefined(); + expect(result.title).toBe('Movie'); + expect(result.year).toBe('2010'); + }); + + test('Show.S04.720p.HDTV.16x9: the season is kept, no episode', () => { + const result = parseTorrentTitle('Show.S04.720p.HDTV.16x9'); + expect(result.seasons).toEqual([4]); + expect(result.episodes).toBeUndefined(); + }); + + test('Doctor Who (2005) BluRay 720p 4x3 Daleks in Manhattan: "4x3" outside a list of tags is season 4 episode 3', () => { + const result = parseTorrentTitle( + 'Doctor Who (2005) BluRay 720p 4x3 Daleks in Manhattan' + ); + expect(result.title).toBe('Doctor Who'); + expect(result.seasons).toEqual([4]); + expect(result.episodes).toEqual([3]); + expect(result.episodeTitle).toBe('Daleks in Manhattan'); + }); + + test('Show 720p 4x3', () => { + const result = parseTorrentTitle('Show 720p 4x3'); + expect(result.seasons).toEqual([4]); + expect(result.episodes).toEqual([3]); + }); + + test('Show.S02E05.720p.HDTV.16x9.x264: the episode is kept', () => { + const result = parseTorrentTitle('Show.S02E05.720p.HDTV.16x9.x264'); + expect(result.seasons).toEqual([2]); + expect(result.episodes).toEqual([5]); + }); + + test('Greys.Anatomy.16x09.HDTV.x264: padded "16x09" is still season 16 episode 9', () => { + const result = parseTorrentTitle('Greys.Anatomy.16x09.HDTV.x264'); + expect(result.seasons).toEqual([16]); + expect(result.episodes).toEqual([9]); + }); + + test('Show 16x9 Episode Title 720p HDTV: before the tags "16x9" is season 16 episode 9', () => { + const result = parseTorrentTitle('Show 16x9 Episode Title 720p HDTV'); + expect(result.title).toBe('Show'); + expect(result.seasons).toEqual([16]); + expect(result.episodes).toEqual([9]); + expect(result.resolution).toBe('720p'); + }); + + test('The Trip 4x3 HDTV x264: before the tags "4x3" is season 4 episode 3', () => { + const result = parseTorrentTitle('The Trip 4x3 HDTV x264'); + expect(result.title).toBe('The Trip'); + expect(result.seasons).toEqual([4]); + expect(result.episodes).toEqual([3]); + }); + + test('Show.4x03.720p.HDTV: padded "4x03" is season 4 episode 3', () => { + const result = parseTorrentTitle('Show.4x03.720p.HDTV'); + expect(result.seasons).toEqual([4]); + expect(result.episodes).toEqual([3]); + }); +}); diff --git a/src/handlers.ts b/src/handlers.ts index ad5f255..1206d90 100644 --- a/src/handlers.ts +++ b/src/handlers.ts @@ -61,6 +61,27 @@ export const handlers: Handler[] = [ pattern: /413 Days/i, remove: true }, + // Aspect ratio after a resolution or source tag ("BDRip 1080p, 16x9"), removed + // so it is not read as a season and an episode. "4x3" is a likely episode, so + // it also has to sit in a list of tags ("[FullScreen 4x3]", "DVDRip, 4x3") + { + field: 'title', + pattern: /(?:\D|^)(16[Xxх]9|4[Xxх]3)(?:\D|$)/, + validateMatch: (input: string, idxs: number[]): boolean => { + const before = input.substring(0, idxs[2]); + return ( + /(?:\b\d{3,4}[pi]|(?:BD|DVD|HD|WEB|TV|SAT|VHS)-?Rip|Remux|\bDVD-?\d?|Blu-?Ray|WEB-?DL|HDTV|\bWS|(?:Wide|Full) ?Screen)\b/i.test( + before + ) && + (input[idxs[2]] !== '4' || + /[,/[(] *$/.test(before) || + /^ *[\]),/]/.test(input.substring(idxs[3]))) + ); + }, + keepMatching: true, + remove: true, + matchGroup: 1 + }, // PPV handlers (lines 294-300 in handlers.go) { From 71dd2c9cd4d036ebd0fc3e6d3571b8f361f91dfd Mon Sep 17 00:00:00 2001 From: Aidar Garikhanov Date: Fri, 27 Nov 2026 03:28:35 +0300 Subject: [PATCH 2/2] fix: only read "16x9" as an aspect ratio inside a tag list Co-authored-by: Claude Fable 5.2 --- src/__tests__/aspectRatio.test.ts | 72 +++++++++++++++++++++++++------ src/handlers.ts | 11 +++-- 2 files changed, 63 insertions(+), 20 deletions(-) diff --git a/src/__tests__/aspectRatio.test.ts b/src/__tests__/aspectRatio.test.ts index 5145453..81247f0 100644 --- a/src/__tests__/aspectRatio.test.ts +++ b/src/__tests__/aspectRatio.test.ts @@ -1,7 +1,7 @@ import { parseTorrentTitle } from '../index'; -// "16x9" and "4x3" listed after the resolution or the source of a release are -// the aspect ratio of the video. They are not a season and an episode. +// "16x9" and "4x3" in a list of tags after the resolution or the source of a +// release are the aspect ratio of the video. They are not a season and an episode. describe('parseTorrentTitle - aspect ratio', () => { test('Сумерки. Сага. Рассвет: Часть 2 / The Twilight Saga: Breaking Dawn - Part 2 (Билл Кондон / Bill Condon) [2012, США, фэнтези, драма, мелодрама, приключения, BDRip 1080p, 16x9] Dub + UKR + Original + Sub Rus + Original Eng', () => { const result = parseTorrentTitle( @@ -25,8 +25,8 @@ describe('parseTorrentTitle - aspect ratio', () => { expect(result.year).toBe('1980'); }); - test('Movie.2012.BDRip.1080p.16x9.x264', () => { - const result = parseTorrentTitle('Movie.2012.BDRip.1080p.16x9.x264'); + test('Movie (2012) [BDRip 1080p, 16x9] x264', () => { + const result = parseTorrentTitle('Movie (2012) [BDRip 1080p, 16x9] x264'); expect(result.seasons).toBeUndefined(); expect(result.episodes).toBeUndefined(); expect(result.title).toBe('Movie'); @@ -35,17 +35,17 @@ describe('parseTorrentTitle - aspect ratio', () => { expect(result.codec).toBe('x264'); }); - test('Movie 2012 DVDRip WS 16х9: Cyrillic "х"', () => { - const result = parseTorrentTitle('Movie 2012 DVDRip WS 16х9'); + test('Movie 2012 [DVDRip, WS 16х9]: Cyrillic "х"', () => { + const result = parseTorrentTitle('Movie 2012 [DVDRip, WS 16х9]'); expect(result.title).toBe('Movie'); expect(result.seasons).toBeUndefined(); expect(result.episodes).toBeUndefined(); expect(result.quality).toBe('DVDRip'); }); - test('Movie.2012.INTERNAL.BDRip.1080p.16x9.x264', () => { + test('Movie.2012.INTERNAL.BDRip.x264 [1080p, 16x9]', () => { const result = parseTorrentTitle( - 'Movie.2012.INTERNAL.BDRip.1080p.16x9.x264' + 'Movie.2012.INTERNAL.BDRip.x264 [1080p, 16x9]' ); expect(result.seasons).toBeUndefined(); expect(result.episodes).toBeUndefined(); @@ -53,16 +53,31 @@ describe('parseTorrentTitle - aspect ratio', () => { expect(result.resolution).toBe('1080p'); }); - test('Movie 2012 HFR 2160p 16x9', () => { - const result = parseTorrentTitle('Movie 2012 HFR 2160p 16x9'); + test('Movie 2012 HFR [2160p, 16x9]', () => { + const result = parseTorrentTitle('Movie 2012 HFR [2160p, 16x9]'); expect(result.seasons).toBeUndefined(); expect(result.episodes).toBeUndefined(); expect(result.title).toBe('Movie'); expect(result.resolution).toBe('4k'); }); - test('Movie 2012 Remux 16x9', () => { - const result = parseTorrentTitle('Movie 2012 Remux 16x9'); + test('Movie 2012 [Remux, 16x9]', () => { + const result = parseTorrentTitle('Movie 2012 [Remux, 16x9]'); + expect(result.seasons).toBeUndefined(); + expect(result.episodes).toBeUndefined(); + expect(result.title).toBe('Movie'); + }); + + test('Movie (2012) [BDRip 1080p, 16Х9]: capital Cyrillic "Х"', () => { + const result = parseTorrentTitle('Movie (2012) [BDRip 1080p, 16Х9]'); + expect(result.seasons).toBeUndefined(); + expect(result.episodes).toBeUndefined(); + expect(result.title).toBe('Movie'); + expect(result.resolution).toBe('1080p'); + }); + + test('Movie [BDRip 1080p, 16x9 anamorph]', () => { + const result = parseTorrentTitle('Movie [BDRip 1080p, 16x9 anamorph]'); expect(result.seasons).toBeUndefined(); expect(result.episodes).toBeUndefined(); expect(result.title).toBe('Movie'); @@ -78,8 +93,8 @@ describe('parseTorrentTitle - aspect ratio', () => { expect(result.year).toBe('2010'); }); - test('Show.S04.720p.HDTV.16x9: the season is kept, no episode', () => { - const result = parseTorrentTitle('Show.S04.720p.HDTV.16x9'); + test('Show.S04.[720p, HDTV, 16x9]: the season is kept, no episode', () => { + const result = parseTorrentTitle('Show.S04.[720p, HDTV, 16x9]'); expect(result.seasons).toEqual([4]); expect(result.episodes).toBeUndefined(); }); @@ -106,6 +121,35 @@ describe('parseTorrentTitle - aspect ratio', () => { expect(result.episodes).toEqual([5]); }); + test('[HDTV] Show 16x9: outside a list of tags "16x9" is season 16 episode 9', () => { + const result = parseTorrentTitle('[HDTV] Show 16x9'); + expect(result.title).toBe('Show'); + expect(result.seasons).toEqual([16]); + expect(result.episodes).toEqual([9]); + }); + + test('Los Simpson HDTV 16x9', () => { + const result = parseTorrentTitle('Los Simpson HDTV 16x9'); + expect(result.title).toBe('Los Simpson'); + expect(result.seasons).toEqual([16]); + expect(result.episodes).toEqual([9]); + }); + + test('Show.Name.720p.HDTV.16x9.Episode.Title', () => { + const result = parseTorrentTitle('Show.Name.720p.HDTV.16x9.Episode.Title'); + expect(result.title).toBe('Show Name'); + expect(result.seasons).toEqual([16]); + expect(result.episodes).toEqual([9]); + expect(result.episodeTitle).toBe('Episode Title'); + }); + + test('The Simpsons [16x9] HDTV: with no tag before it "16x9" is season 16 episode 9', () => { + const result = parseTorrentTitle('The Simpsons [16x9] HDTV'); + expect(result.title).toBe('The Simpsons'); + expect(result.seasons).toEqual([16]); + expect(result.episodes).toEqual([9]); + }); + test('Greys.Anatomy.16x09.HDTV.x264: padded "16x09" is still season 16 episode 9', () => { const result = parseTorrentTitle('Greys.Anatomy.16x09.HDTV.x264'); expect(result.seasons).toEqual([16]); diff --git a/src/handlers.ts b/src/handlers.ts index 1206d90..d1d221d 100644 --- a/src/handlers.ts +++ b/src/handlers.ts @@ -61,20 +61,19 @@ export const handlers: Handler[] = [ pattern: /413 Days/i, remove: true }, - // Aspect ratio after a resolution or source tag ("BDRip 1080p, 16x9"), removed - // so it is not read as a season and an episode. "4x3" is a likely episode, so - // it also has to sit in a list of tags ("[FullScreen 4x3]", "DVDRip, 4x3") + // Aspect ratio in a list of tags after a resolution or source tag + // ("[BDRip 1080p, 16x9]", "DVDRip] [FullScreen 4x3]"), removed so it is not + // read as a season and an episode { field: 'title', - pattern: /(?:\D|^)(16[Xxх]9|4[Xxх]3)(?:\D|$)/, + pattern: /(?:\D|^)(16[XxХх]9|4[XxХх]3)(?:\D|$)/, validateMatch: (input: string, idxs: number[]): boolean => { const before = input.substring(0, idxs[2]); return ( /(?:\b\d{3,4}[pi]|(?:BD|DVD|HD|WEB|TV|SAT|VHS)-?Rip|Remux|\bDVD-?\d?|Blu-?Ray|WEB-?DL|HDTV|\bWS|(?:Wide|Full) ?Screen)\b/i.test( before ) && - (input[idxs[2]] !== '4' || - /[,/[(] *$/.test(before) || + (/[,/[(] *$/.test(before) || /^ *[\]),/]/.test(input.substring(idxs[3]))) ); },