mirror of
https://github.com/SickGear/SickGear.git
synced 2025-03-15 09:07:43 +00:00
Fixed naming issues for episode naming patterns.
Name parser now score's all its possible matches and stores them to a list then once finished performing its matches it'll pick the highest scoring match and return it.
This commit is contained in:
parent
0e989fe90f
commit
7047cf020e
1 changed files with 36 additions and 14 deletions
|
@ -113,6 +113,7 @@ class NameParser(object):
|
||||||
if not name:
|
if not name:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
matches = []
|
||||||
result = None
|
result = None
|
||||||
for (cur_regex_type, cur_regex_name), cur_regex in self.compiled_regexes.items():
|
for (cur_regex_type, cur_regex_name), cur_regex in self.compiled_regexes.items():
|
||||||
match = cur_regex.match(name)
|
match = cur_regex.match(name)
|
||||||
|
@ -122,50 +123,62 @@ class NameParser(object):
|
||||||
|
|
||||||
result = ParseResult(name)
|
result = ParseResult(name)
|
||||||
result.which_regex = [cur_regex_name]
|
result.which_regex = [cur_regex_name]
|
||||||
|
result.score = 0
|
||||||
|
|
||||||
named_groups = match.groupdict().keys()
|
named_groups = match.groupdict().keys()
|
||||||
|
|
||||||
if 'series_name' in named_groups:
|
if 'series_name' in named_groups:
|
||||||
result.series_name = match.group('series_name')
|
result.series_name = match.group('series_name')
|
||||||
if result.series_name:
|
if not result.series_name:
|
||||||
result.series_name = self.clean_series_name(result.series_name)
|
continue
|
||||||
else:continue
|
|
||||||
|
result.series_name = self.clean_series_name(result.series_name)
|
||||||
|
result.score += 1
|
||||||
|
|
||||||
if 'season_num' in named_groups:
|
if 'season_num' in named_groups:
|
||||||
tmp_season = int(match.group('season_num'))
|
tmp_season = int(match.group('season_num'))
|
||||||
if cur_regex_name == 'bare' and tmp_season in (19, 20):
|
if cur_regex_name == 'bare' and tmp_season in (19, 20):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
result.season_number = tmp_season
|
result.season_number = tmp_season
|
||||||
|
result.score += 1
|
||||||
|
|
||||||
if 'ep_num' in named_groups:
|
if 'ep_num' in named_groups:
|
||||||
ep_num = self._convert_number(match.group('ep_num'))
|
ep_num = self._convert_number(match.group('ep_num'))
|
||||||
if 'extra_ep_num' in named_groups and match.group('extra_ep_num'):
|
if 'extra_ep_num' in named_groups and match.group('extra_ep_num'):
|
||||||
result.episode_numbers = range(ep_num, self._convert_number(match.group('extra_ep_num')) + 1)
|
result.episode_numbers = range(ep_num, self._convert_number(match.group('extra_ep_num')) + 1)
|
||||||
|
result.score += 1
|
||||||
else:
|
else:
|
||||||
result.episode_numbers = [ep_num]
|
result.episode_numbers = [ep_num]
|
||||||
|
result.score += 1
|
||||||
|
|
||||||
if 'ep_ab_num' in named_groups:
|
if 'ep_ab_num' in named_groups:
|
||||||
ep_ab_num = self._convert_number(match.group('ep_ab_num'))
|
ep_ab_num = self._convert_number(match.group('ep_ab_num'))
|
||||||
if 'extra_ab_ep_num' in named_groups and match.group('extra_ab_ep_num'):
|
if 'extra_ab_ep_num' in named_groups and match.group('extra_ab_ep_num'):
|
||||||
result.ab_episode_numbers = range(ep_ab_num, self._convert_number(match.group('extra_ab_ep_num')) + 1)
|
result.ab_episode_numbers = range(ep_ab_num, self._convert_number(match.group('extra_ab_ep_num')) + 1)
|
||||||
|
result.score += 1
|
||||||
else:
|
else:
|
||||||
result.ab_episode_numbers = [ep_ab_num]
|
result.ab_episode_numbers = [ep_ab_num]
|
||||||
|
result.score += 1
|
||||||
|
|
||||||
if 'sports_event_id' in named_groups:
|
if 'sports_event_id' in named_groups:
|
||||||
sports_event_id = match.group('sports_event_id')
|
sports_event_id = match.group('sports_event_id')
|
||||||
if sports_event_id:
|
if sports_event_id:
|
||||||
result.sports_event_id = int(match.group('sports_event_id'))
|
result.sports_event_id = int(match.group('sports_event_id'))
|
||||||
|
result.score += 1
|
||||||
|
|
||||||
if 'sports_event_name' in named_groups:
|
if 'sports_event_name' in named_groups:
|
||||||
result.sports_event_name = match.group('sports_event_name')
|
result.sports_event_name = match.group('sports_event_name')
|
||||||
if result.sports_event_name:
|
if result.sports_event_name:
|
||||||
result.sports_event_name = self.clean_series_name(result.sports_event_name)
|
result.sports_event_name = self.clean_series_name(result.sports_event_name)
|
||||||
|
result.score += 1
|
||||||
|
|
||||||
if 'sports_event_date' in named_groups:
|
if 'sports_event_date' in named_groups:
|
||||||
sports_event_date = match.group('sports_event_date')
|
sports_event_date = match.group('sports_event_date')
|
||||||
if sports_event_date:
|
if sports_event_date:
|
||||||
try:
|
try:
|
||||||
result.sports_event_date = parser.parse(sports_event_date, fuzzy=True).date()
|
result.sports_event_date = parser.parse(sports_event_date, fuzzy=True).date()
|
||||||
|
result.score += 1
|
||||||
except:
|
except:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -177,6 +190,7 @@ class NameParser(object):
|
||||||
try:
|
try:
|
||||||
dtStr = '%s-%s-%s' % (year, month, day)
|
dtStr = '%s-%s-%s' % (year, month, day)
|
||||||
result.air_date = datetime.datetime.strptime(dtStr, "%Y-%m-%d").date()
|
result.air_date = datetime.datetime.strptime(dtStr, "%Y-%m-%d").date()
|
||||||
|
result.score += 1
|
||||||
except:
|
except:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -187,28 +201,36 @@ class NameParser(object):
|
||||||
if tmp_extra_info and cur_regex_name == 'season_only' and re.search(
|
if tmp_extra_info and cur_regex_name == 'season_only' and re.search(
|
||||||
r'([. _-]|^)(special|extra)s?\w*([. _-]|$)', tmp_extra_info, re.I):
|
r'([. _-]|^)(special|extra)s?\w*([. _-]|$)', tmp_extra_info, re.I):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
result.extra_info = tmp_extra_info
|
result.extra_info = tmp_extra_info
|
||||||
|
result.score += 1
|
||||||
|
|
||||||
if 'release_group' in named_groups:
|
if 'release_group' in named_groups:
|
||||||
result.release_group = match.group('release_group')
|
result.release_group = match.group('release_group')
|
||||||
|
result.score += 1
|
||||||
|
|
||||||
cur_show = helpers.get_show_by_name(result.series_name, useIndexer=self.useIndexers)
|
cur_show = helpers.get_show_by_name(result.series_name, useIndexer=self.useIndexers)
|
||||||
if cur_show:
|
if not cur_show:
|
||||||
if self.showObj:
|
matches.append(result)
|
||||||
if self.showObj.indexerid != cur_show.indexerid:
|
|
||||||
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)
|
|
||||||
return
|
|
||||||
|
|
||||||
result.show = cur_show
|
|
||||||
|
|
||||||
if not result.show:
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
if self.showObj and self.showObj.indexerid != cur_show.indexerid:
|
||||||
|
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()
|
||||||
|
|
||||||
|
result.score += 1
|
||||||
|
matches.append(result)
|
||||||
|
|
||||||
|
if len(matches):
|
||||||
|
result = sorted(matches, key=lambda k: k.score, reverse=True)[0]
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def _combine_results(self, first, second, attr):
|
def _combine_results(self, first, second, attr):
|
||||||
|
|
Loading…
Reference in a new issue