Skip to content

Commit

Permalink
Merge pull request divijbindlish#6 from roidayan/next
Browse files Browse the repository at this point in the history
Updates to PTN
  • Loading branch information
divijbindlish authored Sep 3, 2016
2 parents 90cfaab + 03daa21 commit f79517e
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 19 deletions.
9 changes: 3 additions & 6 deletions PTN/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,7 @@ def parse(self, name):
pattern = r'\b%s\b' % pattern

clean_name = re.sub('_', ' ', self.torrent['name'])

if key == 'codec':
match = re.findall(pattern, clean_name, re.I)
else:
match = re.findall(pattern, clean_name)
match = re.findall(pattern, clean_name, re.I)
if len(match) == 0:
continue

Expand Down Expand Up @@ -110,13 +106,14 @@ def parse(self, name):
self._part('title', [], raw, clean)

# Start process for end
clean = re.sub('(^[-\. ]+)|([-\. ]+$)', '', self.excess_raw)
clean = re.sub('(^[-\. ()]+)|([-\. ]+$)', '', self.excess_raw)
clean = re.sub('[\(\)\/]', ' ', clean)
match = re.split('\.\.+| +', clean)
if len(match) > 0 and isinstance(match[0], tuple):
match = list(match[0])

clean = [item for item in filter(bool, match)]
clean = [item for item in filter(lambda a: a != '-', clean)]
if len(clean) != 0:
group_pattern = clean[-1] + self.group_raw
if self.torrent['name'].find(group_pattern) == \
Expand Down
18 changes: 9 additions & 9 deletions PTN/patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
# -*- coding: utf-8 -*-

patterns = [
('season', '([Ss]?([0-9]{1,2}))[Eex]'),
('episode', '([Eex]([0-9]{2})(?:[^0-9]|$))'),
('season', '(s?([0-9]{1,2}))[ex]'),
('episode', '([ex]([0-9]{2})(?:[^0-9]|$))'),
('year', '([\[\(]?((?:19[0-9]|20[01])[0-9])[\]\)]?)'),
('resolution', '([0-9]{3,4}p)'),
('quality', ('((?:PPV\.)?[HP]DTV|(?:HD)?CAM|B[rR]Rip|TS|(?:PPV '
')?WEB-?DL(?: DVDRip)?|H[dD]Rip|DVDRip|DVDRiP|DVDR'
'IP|CamRip|W[EB]B[rR]ip|[Bb]lu[Rr]ay|DvDScr|hdtv)')),
('codec', 'xvid|x264|h\.?264'),
('audio', ('MP3|DD5\.?1|Dual[\- ]Audio|LiNE|DTS|AAC(?:\.?2\.0)'
'?|AC3(?:\.5\.1)?')),
('quality', ('((?:PPV\.)?[HP]DTV|(?:HD)?CAM|B[DR]Rip|TS|(?:PPV '
')?WEB-?DL(?: DVDRip)?|HDRip|DVDRip|DVDR'
'IP|CamRip|W[EB]BRip|BluRay|DvDScr|hdtv)')),
('codec', '(xvid|[hx]\.?26[45])'),
('audio', ('(MP3|DD5\.?1|Dual[\- ]Audio|LiNE|H?DTS|AAC(?:\.?2\.0)'
'?|AC3(?:\.5\.1)?)')),
('group', '(- ?([^-]+(?:-={[^-]+-?$)?))$'),
('region', 'R[0-9]'),
('extended', 'EXTENDED'),
('extended', '(EXTENDED(:?.CUT)?)'),
('hardcoded', 'HC'),
('proper', 'PROPER'),
('repack', 'REPACK'),
Expand Down
9 changes: 7 additions & 2 deletions tests/files/input.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"The Big Bang Theory S08E06 HDTV XviD-LOL [eztv]",
"22 Jump Street (2014) 720p BrRip x264 - YIFY",
"Hercules.2014.EXTENDED.1080p.WEB-DL.DD5.1.H264-RARBG",
"Hercules.2014.EXTENDED.HDRip.XViD-juggs[ETRG]",
"Hercules.2014.Extended.Cut.HDRip.XViD-juggs[ETRG]",
"Hercules (2014) WEBDL DVDRip XviD-MAX",
"WWE Hell in a Cell 2014 PPV WEB-DL x264-WD -={SPARROW}=-",
"UFC.179.PPV.HDTV.x264-Ebi[rartv]",
Expand Down Expand Up @@ -64,5 +64,10 @@
"[ www.Speed.cd ] -Sons.of.Anarchy.S07E07.720p.HDTV.X264-DIMENSION",
"Community.s02e20.rus.eng.720p.Kybik.v.Kybe",
"The.Jungle.Book.3D.2016.1080p.BRRip.SBS.x264.AAC-ETRG",
"Ant-Man.2015.3D.1080p.BRRip.Half-SBS.x264.AAC-m2g"
"Ant-Man.2015.3D.1080p.BRRip.Half-SBS.x264.AAC-m2g",
"Ice.Age.Collision.Course.2016.READNFO.720p.HDRIP.X264.AC3.TiTAN",
"Red.Sonja.Queen.Of.Plagues.2016.BDRip.x264-W4F[PRiME]",
"The Purge: Election Year (2016) HC - 720p HDRiP - 900MB - ShAaNi",
"War Dogs (2016) HDTS 600MB - NBY",
"The Hateful Eight (2015) 720p BluRay - x265 HEVC - 999MB - ShAaN"
]
22 changes: 22 additions & 0 deletions tests/files/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"resolution": "1080p",
"quality": "BrRip",
"codec": "H264",
"excess": "",
"title": "Hercules"
},
{
Expand Down Expand Up @@ -48,6 +49,7 @@
"quality": "HDRip",
"codec": "XViD",
"extended": true,
"excess": "",
"title": "Hercules"
},
{
Expand Down Expand Up @@ -465,5 +467,25 @@
{
"title": "Ant-Man",
"sbs": "Half-SBS"
},
{
"title": "Ice Age Collision Course",
"quality": "HDRIP"
},
{
"title": "Red Sonja Queen Of Plagues",
"quality": "BDRip"
},
{
"title": "The Purge: Election Year",
"excess": "900MB"
},
{
"title": "War Dogs",
"audio": "HDTS"
},
{
"title": "The Hateful Eight",
"codec": "x265"
}
]
8 changes: 6 additions & 2 deletions tests/test_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ def test_parser(self):
print("Test: " + torrent)
result = PTN.parse(torrent)
for key in expected_result:
self.assertIn(key, result)
self.assertEqual(result[key], expected_result[key])
if not expected_result[key]:
self.assertNotIn(key, result)
else:
self.assertIn(key, result)
self.assertEqual(result[key], expected_result[key])


if __name__ == '__main__':
unittest.main()

0 comments on commit f79517e

Please sign in to comment.