def test_exact_name(self): """SeriesParser: test exact/strict name parsing""" s = SeriesParser() s.name = "test" s.data = "Test.Foobar.S01E02.720p-FlexGet" s.parse() assert s.valid, "normal failed" s = SeriesParser() s.strict_name = True s.name = "test" s.data = "Test.A.S01E02.720p-FlexGet" s.parse() assert not s.valid, "strict A failed" s = SeriesParser() s.strict_name = True s.name = "Test AB" s.data = "Test.AB.S01E02.720p-FlexGet" s.parse() assert s.valid, "strict AB failed" s = SeriesParser() s.strict_name = True s.name = "Red Tomato" s.data = "Red Tomato (US) S01E02 720p-FlexGet" s.parse() assert not s.valid, "Red Tomato (US) should not match Red Tomato in exact mode"
def test_exact_name(self): """SeriesParser: test exact/strict name parsing""" s = SeriesParser() s.name = 'test' s.data = 'Test.Foobar.S01E02.720p-FlexGet' s.parse() assert s.valid, 'normal failed' s = SeriesParser() s.strict_name = True s.name = 'test' s.data = 'Test.A.S01E02.720p-FlexGet' s.parse() assert not s.valid, 'strict A failed' s = SeriesParser() s.strict_name = True s.name = 'Test AB' s.data = 'Test.AB.S01E02.720p-FlexGet' s.parse() assert s.valid, 'strict AB failed' s = SeriesParser() s.strict_name = True s.name = 'Red Tomato' s.data = 'Red Tomato (US) S01E02 720p-FlexGet' s.parse() assert not s.valid, 'Red Tomato (US) should not match Red Tomato in exact mode'
def test_sound_as_ep(self): """SeriesParser: test that sound infos are not picked as ep""" for sound in SeriesParser.sounds: s = SeriesParser() s.name = 'FooBar' s.data = 'FooBar %s XViD-FlexGet' % sound assert_raises(ParseWarning, s.parse)
def test_quality_as_ep(self): """SeriesParser: test that qualities are not picked as ep""" from flexget.utils import qualities for quality in qualities.all_components(): s = SeriesParser(name='FooBar', identified_by='ep') s.data = 'FooBar %s XviD-FlexGet' % quality.name assert_raises(ParseWarning, s.parse)
def test_quality_as_ep(self): """SeriesParser: test that qualities are not picked as ep""" from flexget.utils import qualities for quality in qualities.all_components(): s = SeriesParser(name='FooBar') s.data = 'FooBar %s XviD-FlexGet' % quality.name assert_raises(ParseWarning, s.parse)
def test_quality_as_ep(self): """SeriesParser: test that qualities are not picked as ep""" from flexget.utils import qualities for quality in qualities.registry.keys(): s = SeriesParser(name='FooBar', identified_by='ep') s.data = 'FooBar %s XviD-FlexGet' % quality assert_raises(ParseWarning, s.parse)
def test_group_dashes(self): """SeriesParser: group name around extra dashes""" s = SeriesParser() s.name = 'Test' s.data = 'Test.S01E01-FooBar-Group' s.allow_groups = ['xxxx', 'group'] s.parse() assert s.group == 'group', 'did not get group with extra dashes'
def test_from_groups(self): """SeriesParser: test from groups""" s = SeriesParser() s.name = 'Test' s.data = 'Test.S01E01-Group' s.allow_groups = ['xxxx', 'group'] s.parse() assert s.group == 'group', 'did not get group'
def test_from_groups(self): """SeriesParser: test from groups""" s = SeriesParser() s.name = "Test" s.data = "Test.S01E01-Group" s.allow_groups = ["xxxx", "group"] s.parse() assert s.group == "group", "did not get group"
def test_idiotic_invalid(self): """SeriesParser: idiotic confused by invalid""" s = SeriesParser(name='test', identified_by='ep') s.data = 'Test.Revealed.WS.PDTV.XviD-aAF.5190458.TPB.torrent' assert_raises(ParseWarning, s.parse) assert not s.season == 5, 'confused, got season' assert not s.season == 4, 'confused, got season' assert not s.episode == 19, 'confused, got episode' assert not s.episode == 58, 'confused, got episode'
def test_idiotic_invalid(self): """SeriesParser: idiotic confused by invalid""" s = SeriesParser(name="test", identified_by="ep") s.data = "Test.Revealed.WS.PDTV.XviD-aAF.5190458.TPB.torrent" assert_raises(ParseWarning, s.parse) assert not s.season == 5, "confused, got season" assert not s.season == 4, "confused, got season" assert not s.episode == 19, "confused, got episode" assert not s.episode == 58, "confused, got episode"
def test_ignore_seasonpacks(self): """SeriesParser: ignoring season packs""" """ s = SeriesParser(name='The Foo') s.data = 'The.Foo.S04.1080p.FlexGet.5.1' assert_raises(ParseWarning, s.parse) """ s = SeriesParser(name='Something') s.data = 'Something S02 Pack 720p WEB-DL-FlexGet' assert_raises(ParseWarning, s.parse) s = SeriesParser(name='The Foo') s.data = 'The Foo S05 720p BluRay DTS x264-FlexGet' assert_raises(ParseWarning, s.parse) s = SeriesParser(name='The Foo', identified_by='ep') s.data = 'The Foo S05 720p BluRay DTS x264-FlexGet' assert_raises(ParseWarning, s.parse)
def test_ep_as_quality(self): """SeriesParser: test that eps are not picked as qualities""" from flexget.utils import qualities s = SeriesParser(name='FooBar') for quality1 in qualities.all_components(): # Attempt to create an episode number out of quality mock_ep1 = filter(unicode.isdigit, quality1.name) if not mock_ep1: continue for quality2 in qualities.all_components(): mock_ep2 = filter(unicode.isdigit, quality2.name) if not mock_ep2: continue # 720i, 1080i, etc. are failing because # e.g the 720 in 720i can always be taken to mean 720p, # which is a higher priority quality. # Moreover, 1080 as an ep number is always failing because # sequence regexps support at most 3 digits at the moment. # Luckily, all of these cases are discarded by the following, # which also discards the failing cases when episode number # (e.g. 720) is greater or equal than quality number (e.g. 480p). # There's nothing that can be done with those failing cases with the # current # "grab leftmost occurrence of highest quality-like thing" algorithm. if int(mock_ep1) >= int(mock_ep2): continue s.data = 'FooBar - %s %s-FlexGet' % (mock_ep1, quality2.name) s.parse() assert s.episode == int(mock_ep1), "confused episode %s with quality %s" % \ (mock_ep1, quality2.name) # Also test with reversed relative order of episode and quality s.data = '[%s] FooBar - %s [FlexGet]' % (quality2.name, mock_ep1) s.parse() assert s.episode == int(mock_ep1), "confused episode %s with quality %s" % \ (mock_ep1, quality2.name)
def guess_series(self, title, allow_seasonless=False, quality=None): """Returns a valid series parser if this `title` appears to be a series""" parser = SeriesParser(identified_by='auto', allow_seasonless=allow_seasonless) # We need to replace certain characters with spaces to make sure episode parsing works right # We don't remove anything, as the match positions should line up with the original title clean_title = re.sub('[_.,\[\]\(\):]', ' ', title) if parser.parse_unwanted(clean_title): return match = parser.parse_date(clean_title) if match: parser.identified_by = 'date' else: match = parser.parse_episode(clean_title) if match and parser.parse_unwanted(clean_title): return parser.identified_by = 'ep' if not match: return if match['match'].start() > 1: # We start using the original title here, so we can properly ignore unwanted prefixes. # Look for unwanted prefixes to find out where the series title starts start = 0 prefix = re.match('|'.join(parser.ignore_prefixes), title) if prefix: start = prefix.end() # If an episode id is found, assume everything before it is series name name = title[start:match['match'].start()] # Remove possible episode title from series name (anything after a ' - ') name = name.split(' - ')[0] # Replace some special characters with spaces name = re.sub('[\._\(\) ]+', ' ', name).strip(' -') # Normalize capitalization to title case name = capwords(name) # If we didn't get a series name, return if not name: return parser.name = name parser.data = title try: parser.parse(data=title, quality=quality) except ParseWarning as pw: log.debug('ParseWarning: %s' % pw.value) if parser.valid: return parser
def test_invalid_data(self): """SeriesParser: invalid data""" s = SeriesParser() s.name = 'Something Interesting' s.data = 1
def test_invalid_name(self): """SeriesParser: invalid name""" s = SeriesParser() s.name = 1 s.data = 'Something'
def test_name_with_number(self): """SeriesParser: test number in a name""" s = SeriesParser() s.name = 'Storage 13' s.data = 'Storage 13 no ep number' assert_raises(ParseWarning, s.parse)