From b9f840246d8eb331349b1406692b6dc3ea73e38b Mon Sep 17 00:00:00 2001
From: zakary <123845855+zakkarry@users.noreply.github.com>
Date: Tue, 12 Sep 2023 16:54:01 -0500
Subject: [PATCH] fix(regex): movie and tv (pack and episode) regex
The following are changes made to improve matching for TV (season pack and episode) as well as movies.
All Regex's
* Replaced literal space (' ') in expressions with \s
MOVIE_REGEX
* Added support for '_' in release name.
SEASON_REGEX
* Added support for '_' in release naming.
* Capture multiple variations (including poorly named) of multiple season packs properly.
* Fixed matching incorrectly when season has more than one digit
EP_REGEX
* Added more variations on multi-episode capturing
**fix/update(regex): change title capture to lazy**
* Modify
capture group to match lazily, reducing the number of step proportional to the length of the release name.
**fix(regex): corrected matching**
* previously required formatting to be S## while not all releases contain the preceding S in multi-season packs.
* Removed the '_' from separator between seasons in multi season packs.
If you run some test cases and find any outliers or mismatching, please comment and note what release naming you used to demonstrate.
---
src/constants.ts | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/constants.ts b/src/constants.ts
index 187c17a57..3f270b312 100644
--- a/src/constants.ts
+++ b/src/constants.ts
@@ -6,11 +6,11 @@ export const PROGRAM_NAME = packageDotJson.name;
export const PROGRAM_VERSION = packageDotJson.version;
export const USER_AGENT = `CrossSeed/${PROGRAM_VERSION}`;
-export const EP_REGEX = /^(?.+)[. ](?S\d+)(?E\d+)/i;
+export const EP_REGEX = /^(?.+?)[\s._](?S\d+)?[_.\s]?(?E\d+(?:[-\s]?E?\d+)?)/i;
export const SEASON_REGEX =
- /^(?.+)[. ](?S\d+)(?:\s?-\s?(?S?\d+))?(?!E\d+)/i;
+ /^(?.+?)[_.\s](?S\d+)(?:[.\-\s]*?(?S?\d+))?(?=[_.\s](?!E\d+))/i;
export const MOVIE_REGEX =
- /^(?.+)[. ][[(]?(?\d{4})[)\]]?(?![pi])/i;
+ /^(?.+?)[._\s][[(]?(?\d{4})[)\]]?(?![pi])/i;
export const VIDEO_EXTENSIONS = [".mkv", ".mp4", ".avi"];