Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Much improved support for years parsing #30

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
7 changes: 6 additions & 1 deletion PTN/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,20 @@ 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

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:
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:
Expand Down
2 changes: 1 addition & 1 deletion PTN/patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -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|'
Expand Down
6 changes: 5 additions & 1 deletion tests/files/input.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,9 @@
"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]",
"2012.2009.BluRay.1080p.x264.YIFY.mp4",
"Death Race 2000 (1975) [1080p] [BluRay] [YTS.MX]"
]
16 changes: 16 additions & 0 deletions tests/files/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -511,5 +511,21 @@
{
"title": "The Secret Life of Pets",
"audio": "AAC-LC"
},
{
"year": 2020,
"title": "Onward"
},
{
"year": 1968,
"title": "2001: A Space Odyssey"
},
{
"year": 2009,
"title": "2012"
},
{
"year": 1975,
"title": "Death Race 2000"
}
]