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 #17
Signed-off-by: Roi Dayan <[email protected]>
  • Loading branch information
roidayan committed Aug 11, 2017
1 parent 681d958 commit 651c08e
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 11 deletions.
21 changes: 17 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 Down
3 changes: 2 additions & 1 deletion PTN/patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-

patterns = [
('season', '(s?([0-9]{1,2}))[ex]'),
('season', '((?:Complete.)?s[0-9]{2}-s[0-9]{2}|s([0-9]{1,2})|([0-9]{1,2})x[0-9]{2})'),
('episode', '([ex]([0-9]{2})(?:[^0-9]|$))'),
('year', '([\[\(]?((?:19[0-9]|20[01])[0-9])[\]\)]?)'),
('resolution', '([0-9]{3,4}p)'),
Expand All @@ -23,6 +23,7 @@
('widescreen', 'WS'),
('website', '^(\[ ?([^\]]+?) ?\])'),
('language', '(rus\.eng|ita\.eng)'),
('subtitles', '(DKsubs)'),
('sbs', '(?:Half-)?SBS'),
('unrated', 'UNRATED'),
('size', '(\d+(?:\.\d+)?(?:GB|MB))'),
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",
"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"
]
35 changes: 34 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,38 @@
{
"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"
}
]
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 651c08e

Please sign in to comment.