From bf96472400b6cf2d0e1bd98ae6b728a2f206de06 Mon Sep 17 00:00:00 2001 From: Dave Chevell Date: Sun, 17 May 2020 10:55:58 +1000 Subject: [PATCH 1/2] Add support for movie years 2020-2099 --- PTN/parse.py | 4 +++- PTN/patterns.py | 2 +- tests/files/input.json | 4 +++- tests/files/output.json | 8 ++++++++ 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/PTN/parse.py b/PTN/parse.py index 688dbe3..884ff87 100644 --- a/PTN/parse.py +++ b/PTN/parse.py @@ -55,7 +55,7 @@ def parse(self, name): self.title_raw = None for key, pattern in patterns: - if key not in ('season', 'episode', 'website'): + if key not in ('season', 'episode', 'website', 'year'): pattern = r'\b%s\b' % pattern clean_name = re.sub('_', ' ', self.torrent['name']) @@ -64,6 +64,8 @@ def parse(self, name): continue index = {} + if key == 'year' and len(match) > 1: + match = [m for m in match if m[0].startswith('(')] or match if isinstance(match[0], tuple): match = list(match[0]) if len(match) > 1: diff --git a/PTN/patterns.py b/PTN/patterns.py index 05261e3..d2843a4 100644 --- a/PTN/patterns.py +++ b/PTN/patterns.py @@ -4,7 +4,7 @@ patterns = [ ('season', '(s?([0-9]{1,2}))[ex]'), ('episode', '([ex]([0-9]{2})(?:[^0-9]|$))'), - ('year', '([\[\(]?((?:19[0-9]|20[01])[0-9])[\]\)]?)'), + ('year', '([\[\(]?((?:19[0-9]|20[0-9])[0-9])[\]\)]?)'), ('resolution', '([0-9]{3,4}p)'), ('quality', ('((?:PPV\.)?[HP]DTV|(?:HD)?CAM|B[DR]Rip|(?:HD-?)?TS|' '(?:PPV )?WEB-?DL(?: DVDRip)?|HDRip|DVDRip|DVDRIP|' diff --git a/tests/files/input.json b/tests/files/input.json index 04a99ba..fb9b30f 100644 --- a/tests/files/input.json +++ b/tests/files/input.json @@ -74,5 +74,7 @@ "Return.To.Snowy.River.1988.iNTERNAL.DVDRip.x264-W4F[PRiME]", "Akira (2016) - UpScaled - 720p - DesiSCR-Rip - Hindi - x264 - AC3 - 5.1 - Mafiaking - M2Tv", "Ben Hur 2016 TELESYNC x264 AC3 MAXPRO", - "The.Secret.Life.of.Pets.2016.HDRiP.AAC-LC.x264-LEGi0N" + "The.Secret.Life.of.Pets.2016.HDRiP.AAC-LC.x264-LEGi0N", + "Onward (2020) [1080p] [WEBRip] [5.1] [YTS.MX]", + "2001: A Space Odyssey (1968) [BluRay] [1080p] [YTS.AM]" ] diff --git a/tests/files/output.json b/tests/files/output.json index b1c9e7d..1b6b841 100644 --- a/tests/files/output.json +++ b/tests/files/output.json @@ -511,5 +511,13 @@ { "title": "The Secret Life of Pets", "audio": "AAC-LC" + }, + { + "year": 2020, + "title": "Onward" + }, + { + "year": 1968, + "title": "2001: A Space Odyssey" } ] From 3de5edfd3774d202dc00cccbc8b9c34a428479d0 Mon Sep 17 00:00:00 2001 From: Dave Chevell Date: Sun, 17 May 2020 11:16:51 +1000 Subject: [PATCH 2/2] Support titles with year in name --- PTN/parse.py | 3 +++ tests/files/input.json | 4 +++- tests/files/output.json | 8 ++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/PTN/parse.py b/PTN/parse.py index 884ff87..2aed07e 100644 --- a/PTN/parse.py +++ b/PTN/parse.py @@ -58,6 +58,9 @@ def parse(self, name): if key not in ('season', 'episode', 'website', 'year'): pattern = r'\b%s\b' % pattern + if key == 'year': + pattern = r'.%s' % pattern + clean_name = re.sub('_', ' ', self.torrent['name']) match = re.findall(pattern, clean_name, re.I) if len(match) == 0: diff --git a/tests/files/input.json b/tests/files/input.json index fb9b30f..83c90d5 100644 --- a/tests/files/input.json +++ b/tests/files/input.json @@ -76,5 +76,7 @@ "Ben Hur 2016 TELESYNC x264 AC3 MAXPRO", "The.Secret.Life.of.Pets.2016.HDRiP.AAC-LC.x264-LEGi0N", "Onward (2020) [1080p] [WEBRip] [5.1] [YTS.MX]", - "2001: A Space Odyssey (1968) [BluRay] [1080p] [YTS.AM]" + "2001: A Space Odyssey (1968) [BluRay] [1080p] [YTS.AM]", + "2012.2009.BluRay.1080p.x264.YIFY.mp4", + "Death Race 2000 (1975) [1080p] [BluRay] [YTS.MX]" ] diff --git a/tests/files/output.json b/tests/files/output.json index 1b6b841..59f9bfc 100644 --- a/tests/files/output.json +++ b/tests/files/output.json @@ -519,5 +519,13 @@ { "year": 1968, "title": "2001: A Space Odyssey" + }, + { + "year": 2009, + "title": "2012" + }, + { + "year": 1975, + "title": "Death Race 2000" } ]