Skip to content

Commit

Permalink
Add support for multi season
Browse files Browse the repository at this point in the history
The support is for range like S01-S09.
Also new key subtitles. first match is DKsubs.
Added tests for multi season and subtitles.

Fixes divijbindlish#17
Signed-off-by: Roi Dayan <[email protected]>
  • Loading branch information
roidayan committed Aug 13, 2017
1 parent 681d958 commit 9b2757e
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 14 deletions.
22 changes: 18 additions & 4 deletions PTN/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,33 @@ def parse(self, name):
match = list(match[0])
if len(match) > 1:
index['raw'] = 0
index['clean'] = 1
index['clean'] = 0
# for season we might have it in index 1 or index 2
# i.e. "5x09"
for i in range(1, len(match)):
if match[i]:
index['clean'] = i
break
else:
index['raw'] = 0
index['clean'] = 0

if key in types.keys() and types[key] == 'boolean':
if key == 'season' and index['clean'] == 0:
# handle multi season
# i.e. S01-S09
m = re.findall('s([0-9]{2})-s([0-9]{2})', clean_name, re.I)
if m:
clean = list(range(int(m[0][0]), int(m[0][1])+1))
elif key in types.keys() and types[key] == 'boolean':
clean = True
else:
clean = match[index['clean']]
if key in types.keys() and types[key] == 'integer':
clean = int(clean)

if key == 'group':
if re.search(patterns[5][1], clean, re.I) \
or re.search(patterns[4][1], clean):
if (re.search(patterns[5][1], clean, re.I) or
re.search(patterns[4][1], clean)):
continue # Codec and quality.
if re.match('[^ ]+ [^ ]+ .+', clean):
key = 'episodeName'
Expand All @@ -102,6 +115,7 @@ def parse(self, name):
clean = re.sub('\.', ' ', clean)
clean = re.sub('_', ' ', clean)
clean = re.sub('([\[\(_]|- )$', '', clean).strip()
clean = clean.strip(' _-')

self._part('title', [], raw, clean)

Expand Down
11 changes: 7 additions & 4 deletions PTN/patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
# -*- coding: utf-8 -*-

patterns = [
('season', '(s?([0-9]{1,2}))[ex]'),
('episode', '([ex]([0-9]{2})(?:[^0-9]|$))'),
('season', '[\. ]((?:Complete.)?s[0-9]{2}-s[0-9]{2}|'
's([0-9]{1,2})(?:e[0-9]{2})?|'
'([0-9]{1,2})x[0-9]{2})(?:[\. ]|$)'),
('episode', '((?:[ex]|ep)([0-9]{2})(?:[^0-9]|$))'),
('year', '([\[\(]?((?:19[0-9]|20[01])[0-9])[\]\)]?)'),
('resolution', '([0-9]{3,4}p)'),
('resolution', '([0-9]{3,4}p|1280x720)'),
('quality', ('((?:PPV\.)?[HP]DTV|(?:HD)?CAM|B[DR]Rip|(?:HD-?)?TS|'
'(?:PPV )?WEB-?DL(?: DVDRip)?|HDRip|DVDRip|DVDRIP|'
'(?:PPV )?WEB-?DL(?: DVDRip)?|HDRip|HDTVRip|DVDRip|DVDRIP|'
'CamRip|W[EB]BRip|BluRay|DvDScr|hdtv|telesync)')),
('codec', '(xvid|[hx]\.?26[45])'),
('audio', ('(MP3|DD5\.?1|Dual[\- ]Audio|LiNE|DTS|'
Expand All @@ -23,6 +25,7 @@
('widescreen', 'WS'),
('website', '^(\[ ?([^\]]+?) ?\])'),
('language', '(rus\.eng|ita\.eng)'),
('subtitles', '(DKsubs)'),
('sbs', '(?:Half-)?SBS'),
('unrated', 'UNRATED'),
('size', '(\d+(?:\.\d+)?(?:GB|MB))'),
Expand Down
7 changes: 6 additions & 1 deletion tests/files/input.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,10 @@
"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",
"The.X-Files.S01.Retail.DKsubs.720p.BluRay.x264-RAPiDCOWS",
"The.X-Files.S01-S03.DKsubs.1080p.BluRay.HEVC.x265",
"The.X-Files.Complete.S01-S09.1080p.BluRay.x264-GECKOS",
"The.Flash.2014.S03.720p.HDTV.x264-Scene",
"Boku.Unmei.no.Hito.desu.Ep07.Chi_Jap.HDTVrip.1280X720-ZhuixinFan.mp4"
]
42 changes: 41 additions & 1 deletion tests/files/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@
},
{
"title": "Akira",
"excess": "UpScaled, DesiSCR-Rip, Hindi, 5.1, Mafiaking"
"excess": ["UpScaled", "DesiSCR-Rip", "Hindi", "5.1", "Mafiaking"]
},
{
"title": "Ben Hur",
Expand All @@ -511,5 +511,45 @@
{
"title": "The Secret Life of Pets",
"audio": "AAC-LC"
},
{
"title": "The X-Files",
"season": 1,
"subtitles": "DKsubs",
"resolution": "720p",
"quality": "BluRay",
"codec": "x264",
"group": "RAPiDCOWS"
},
{
"title": "The X-Files",
"season": [1, 2, 3],
"resolution": "1080p",
"quality": "BluRay",
"codec": "x265"
},
{
"title": "The X-Files",
"season": [1, 2, 3, 4, 5, 6, 7, 8, 9],
"resolution": "1080p",
"quality": "BluRay",
"codec": "x264",
"group": "GECKOS"
},
{
"title": "The Flash",
"year": 2014,
"season": 3,
"resolution": "720p",
"quality": "HDTV",
"codec": "x264",
"group": "Scene"
},
{
"title": "Boku Unmei no Hito desu",
"episode": 7,
"quality": "HDTVrip",
"resolution": "1280X720",
"container": "mp4"
}
]
5 changes: 1 addition & 4 deletions tests/test_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ def test_parser(self):
self.assertNotIn(key, result)
else:
self.assertIn(key, result)
result1 = result[key]
if key == 'excess' and type(result1) == list:
result1 = ', '.join(result1)
self.assertEqual(result1, expected_result[key])
self.assertEqual(result[key], expected_result[key])


if __name__ == '__main__':
Expand Down

0 comments on commit 9b2757e

Please sign in to comment.