1
0
mirror of https://github.com/moparisthebest/SickRage synced 2024-11-13 21:05:11 -05:00

NameParser now trys to obtain a show object first to use in determining the correct regex set to use when parsing release names

This commit is contained in:
echel0n 2014-06-19 17:26:36 -07:00
parent 784b8d7179
commit 4ef88961b5

View File

@ -37,19 +37,8 @@ class NameParser(object):
def __init__(self, file_name=True, showObj=None, epObj=None, useIndexers=False, convert=False): def __init__(self, file_name=True, showObj=None, epObj=None, useIndexers=False, convert=False):
regexMode = self.ALL_REGEX
if showObj and showObj.is_anime:
regexMode = self.ANIME_REGEX
elif showObj and showObj.is_sports:
regexMode = self.SPORTS_REGEX
elif showObj and not showObj.is_anime and not showObj.is_sports:
regexMode = self.NORMAL_REGEX
self.file_name = file_name self.file_name = file_name
self.regexMode = regexMode self.showList = sickbeard.showList or []
self.compiled_regexes = {}
self._compile_regexes(self.regexMode)
self.showList = sickbeard.showList
self.useIndexers = useIndexers self.useIndexers = useIndexers
self.showObj = showObj self.showObj = showObj
self.epObj = epObj self.epObj = epObj
@ -205,8 +194,9 @@ class NameParser(object):
result.release_group = match.group('release_group') result.release_group = match.group('release_group')
result.score += 1 result.score += 1
cur_show = helpers.get_show_by_name(result.series_name, useIndexer=self.useIndexers) if not self.showObj:
if not cur_show: self.showObj = helpers.get_show_by_name(result.series_name, useIndexer=self.useIndexers)
if self.showObj: if self.showObj:
if self.showObj.air_by_date and result.air_date: if self.showObj.air_by_date and result.air_date:
result.score += 1 result.score += 1
@ -214,17 +204,11 @@ class NameParser(object):
result.score += 1 result.score += 1
elif self.showObj.anime and len(result.ab_episode_numbers): elif self.showObj.anime and len(result.ab_episode_numbers):
result.score += 1 result.score += 1
else:
matches.append(result) matches.append(result)
continue continue
if self.showObj and self.showObj.indexerid != cur_show.indexerid: result.show = self.showObj
logger.log(
u"I expected an episode of the show " + self.showObj.name + " but the parser thinks its the show " + cur_show.name + ". I will continue thinking its " + self.showObj.name,
logger.WARNING)
continue
result.show = cur_show
if self.convert: if self.convert:
result = result.convert() result = result.convert()
@ -309,6 +293,25 @@ class NameParser(object):
if cached: if cached:
return cached return cached
if not self.showObj:
for show in self.showList:
if not show.name.lower() in name.lower():
continue
self.showObj = show
break
regexMode = self.ALL_REGEX
if self.showObj and self.showObj.is_anime:
regexMode = self.ANIME_REGEX
elif self.showObj and self.showObj.is_sports:
regexMode = self.SPORTS_REGEX
elif self.showObj and not self.showObj.is_anime and not self.showObj.is_sports:
regexMode = self.NORMAL_REGEX
self.compiled_regexes = {}
self._compile_regexes(regexMode)
# break it into parts if there are any (dirname, file name, extension) # break it into parts if there are any (dirname, file name, extension)
dir_name, file_name = os.path.split(name) dir_name, file_name = os.path.split(name)
ext_match = re.match('(.*)\.\w{3,4}$', file_name) ext_match = re.match('(.*)\.\w{3,4}$', file_name)