Fix marking episodes wanted due to parsing malformed non-anime release name as an anime season pack.

Change disallow anime regex matches for non-anime shows.
Change add unit test for invalid (numbered) show releases (non-anime show with anime numbering).
Change speed optimization, compile static name parser regexes once, instead of for every NameParser instance.
Change remove redundant create regexs log messages removing <10% log spam.
This commit is contained in:
Prinz23 2018-04-24 15:30:33 +01:00 committed by JackDandy
parent 208ddfb42a
commit f8fd89baeb
3 changed files with 54 additions and 12 deletions

View file

@ -6,6 +6,9 @@
* Remove TorrentBytes provider
* Change remove redundant log messages for releases never to be cached removing <30% log spam
* Change remove redundant log messages for items not found in cache removing <10% log spam
* Fix marking episodes wanted due to parsing malformed non-anime release name as an anime season pack
* Change speed optimization, compile static name parser regexes once, instead of for every NameParser instance
* Change remove redundant create regexs log messages removing <10% log spam
### 0.15.13 (2018-04-18 13:50:00 UTC)

View file

@ -54,24 +54,22 @@ class NameParser(object):
self.indexer_lookup = indexer_lookup
if self.showObj and not self.showObj.is_anime:
self._compile_regexes(self.NORMAL_REGEX)
self.compiled_regexes = compiled_regexes[self.NORMAL_REGEX]
elif self.showObj and self.showObj.is_anime:
self._compile_regexes(self.ANIME_REGEX)
self.compiled_regexes = compiled_regexes[self.ANIME_REGEX]
else:
self._compile_regexes(self.ALL_REGEX)
self.compiled_regexes = compiled_regexes[self.ALL_REGEX]
def _compile_regexes(self, regex_mode):
if self.ANIME_REGEX == regex_mode:
logger.log(u'Using ANIME regexs', logger.DEBUG)
@classmethod
def compile_regexes(cls, regex_mode):
if cls.ANIME_REGEX == regex_mode:
uncompiled_regex = [regexes.anime_regexes]
elif self.NORMAL_REGEX == regex_mode:
logger.log(u'Using NORMAL regexs', logger.DEBUG)
elif cls.NORMAL_REGEX == regex_mode:
uncompiled_regex = [regexes.normal_regexes]
else:
logger.log(u'Using ALL regexes', logger.DEBUG)
uncompiled_regex = [regexes.normal_regexes, regexes.anime_regexes]
self.compiled_regexes = {0: [], 1: []}
cls.compiled_regexes = {0: [], 1: []}
index = 0
for regexItem in uncompiled_regex:
for cur_pattern_num, (cur_pattern_name, cur_pattern) in enumerate(regexItem):
@ -80,9 +78,11 @@ class NameParser(object):
except re.error as errormsg:
logger.log(u'WARNING: Invalid episode_pattern, %s. %s' % (errormsg, cur_pattern))
else:
self.compiled_regexes[index].append([cur_pattern_num, cur_pattern_name, cur_regex])
cls.compiled_regexes[index].append([cur_pattern_num, cur_pattern_name, cur_regex])
index += 1
return cls.compiled_regexes
@staticmethod
def clean_series_name(series_name):
"""Cleans up series name by removing any . and _
@ -144,6 +144,15 @@ class NameParser(object):
result.score += 1
if 'anime' in cur_regex_name and not (self.showObj and self.showObj.is_anime):
p_show = helpers.get_show(result.series_name, True)
if p_show and self.showObj and p_show.indexerid != self.showObj.indexerid:
p_show = None
if not p_show and self.showObj:
p_show = self.showObj
if p_show and not p_show.is_anime:
continue
if 'series_num' in named_groups and match.group('series_num'):
result.score += 1
@ -558,6 +567,11 @@ class NameParser(object):
return final_result
compiled_regexes = {NameParser.NORMAL_REGEX: NameParser.compile_regexes(NameParser.NORMAL_REGEX),
NameParser.ANIME_REGEX: NameParser.compile_regexes(NameParser.ANIME_REGEX),
NameParser.ALL_REGEX: NameParser.compile_regexes(NameParser.ALL_REGEX)}
class ParseResult(object):
def __init__(self,
original_name,

View file

@ -9,6 +9,7 @@ sys.path.insert(1, os.path.abspath('..'))
sys.path.insert(1, os.path.abspath('../lib'))
from sickbeard.name_parser import parser
from sickbeard import name_cache
import sickbeard
@ -352,6 +353,25 @@ unicode_test_cases = [
failure_cases = ['7sins-jfcs01e09-720p-bluray-x264']
invalid_cases = [('The.Show.Name.111E14.1080p.WEB.x264-GROUP', 'the show name', 11, False)]
class InvalidCases(test.SickbeardTestDBCase):
def _test_invalid(self, name, show, indexerid, is_anime):
sickbeard.showList.append(TVShow(name=name, indexerid=indexerid, is_anime=is_anime))
name_cache.addNameToCache(show, indexerid)
invalidexception = False
try:
parse_result = parser.NameParser(True).parse(name)
except (parser.InvalidNameException, parser.InvalidShowException):
invalidexception = True
self.assertEqual(invalidexception, True)
def test_invalid(self):
for (name, show, indexerid, is_anime) in invalid_cases:
self._test_invalid(name, show, indexerid, is_anime)
class UnicodeTests(test.SickbeardTestDBCase):
@ -593,8 +613,10 @@ class BasicTests(test.SickbeardTestDBCase):
class TVShow(object):
def __init__(self, is_anime=False):
def __init__(self, is_anime=False, name='', indexerid=0):
self.is_anime = is_anime
self.name = name
self.indexerid = indexerid
if __name__ == '__main__':
@ -612,3 +634,6 @@ if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(FailureCaseTests)
unittest.TextTestRunner(verbosity=2).run(suite)
suite = unittest.TestLoader().loadTestsFromTestCase(InvalidCases)
unittest.TextTestRunner(verbosity=2).run(suite)