mirror of
https://github.com/SickGear/SickGear.git
synced 2024-12-01 00:43:37 +00:00
Fixes for anime regex matching
This commit is contained in:
parent
d42b864ecc
commit
99d129bd41
5 changed files with 51 additions and 20 deletions
|
@ -327,7 +327,7 @@ def searchDBForShow(regShowName, log=False):
|
|||
|
||||
|
||||
def searchIndexerForShowID(regShowName, indexer=None, indexer_id=None, ui=None):
|
||||
showNames = list(set([re.sub('[. -]', ' ', regShowName), regShowName]))
|
||||
showNames = [re.sub('[. -]', ' ', regShowName)]
|
||||
|
||||
# Query Indexers for each search term and build the list of results
|
||||
for i in sickbeard.indexerApi().indexers if not indexer else int(indexer or []):
|
||||
|
@ -680,6 +680,23 @@ def is_anime_in_show_list():
|
|||
def update_anime_support():
|
||||
sickbeard.ANIMESUPPORT = is_anime_in_show_list()
|
||||
|
||||
def get_absolute_number_from_season_and_episode(show, season, episode):
|
||||
myDB = db.DBConnection()
|
||||
sql = "SELECT * FROM tv_episodes WHERE showid = ? and season = ? and episode = ?"
|
||||
sqlResults = myDB.select(sql, [show.indexerid, season, episode])
|
||||
|
||||
if len(sqlResults) == 1:
|
||||
absolute_number = int(sqlResults[0]["absolute_number"])
|
||||
logger.log(
|
||||
"Found absolute_number:" + str(absolute_number) + " by " + str(season) + "x" + str(episode), logger.DEBUG)
|
||||
|
||||
return absolute_number
|
||||
else:
|
||||
logger.log(
|
||||
"No entries for absolute number in show: " + show.name + " found using " + str(season) + "x" + str(episode),logger.DEBUG)
|
||||
|
||||
return None
|
||||
|
||||
def get_all_episodes_from_absolute_number(show, indexer_id, absolute_numbers):
|
||||
if len(absolute_numbers) == 0:
|
||||
raise EpisodeNotFoundByAbsoluteNumberException()
|
||||
|
|
|
@ -93,7 +93,7 @@ class NameParser(object):
|
|||
|
||||
elif regexMode == self.ANIME_REGEX:
|
||||
logger.log(u"Using ANIME regexs", logger.DEBUG)
|
||||
uncompiled_regex = [regexes.anime_regexes, regexes.normal_regexes]
|
||||
uncompiled_regex = [regexes.anime_regexes]
|
||||
|
||||
else:
|
||||
logger.log(u"This is a programing ERROR. Fallback Using NORMAL regexs", logger.ERROR)
|
||||
|
@ -113,13 +113,14 @@ class NameParser(object):
|
|||
if not name:
|
||||
return
|
||||
|
||||
result = ParseResult(name)
|
||||
result = None
|
||||
for (cur_regex_type, cur_regex_name), cur_regex in self.compiled_regexes.items():
|
||||
match = cur_regex.match(name)
|
||||
|
||||
if not match:
|
||||
continue
|
||||
|
||||
result = ParseResult(name)
|
||||
result.which_regex = [cur_regex_name]
|
||||
|
||||
named_groups = match.groupdict().keys()
|
||||
|
@ -146,8 +147,7 @@ class NameParser(object):
|
|||
if 'ep_ab_num' in named_groups:
|
||||
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'):
|
||||
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)
|
||||
else:
|
||||
result.ab_episode_numbers = [ep_ab_num]
|
||||
|
||||
|
@ -206,12 +206,8 @@ class NameParser(object):
|
|||
if not result.show:
|
||||
continue
|
||||
|
||||
# Natch found!
|
||||
break
|
||||
|
||||
|
||||
if self.convert:
|
||||
result = result.convert()
|
||||
if self.convert:
|
||||
result = result.convert()
|
||||
|
||||
return result
|
||||
|
||||
|
@ -385,7 +381,7 @@ class ParseResult(object):
|
|||
self.sports_event_name = sports_event_name
|
||||
self.sports_event_date = sports_event_date
|
||||
|
||||
self.which_regex = None
|
||||
self.which_regex = []
|
||||
self.show = show
|
||||
self.score = score
|
||||
|
||||
|
@ -466,17 +462,23 @@ class ParseResult(object):
|
|||
if self.show.is_anime and len(self.ab_episode_numbers):
|
||||
for epAbsNo in self.ab_episode_numbers:
|
||||
a = scene_numbering.get_indexer_absolute_numbering(self.show.indexerid, self.show.indexer, epAbsNo)
|
||||
(s, e) = helpers.get_all_episodes_from_absolute_number(self.show, None, [a])
|
||||
if a:
|
||||
(s, e) = helpers.get_all_episodes_from_absolute_number(self.show, None, [a])
|
||||
|
||||
new_absolute_numbers.append(a)
|
||||
new_episode_numbers.append(e)
|
||||
new_season_numbers.append(s)
|
||||
new_absolute_numbers.append(a)
|
||||
new_episode_numbers.extend(e)
|
||||
new_season_numbers.append(s)
|
||||
|
||||
elif self.season_number and len(self.episode_numbers):
|
||||
for epNo in self.episode_numbers:
|
||||
(s, e) = scene_numbering.get_indexer_numbering(self.show.indexerid, self.show.indexer,
|
||||
self.season_number,
|
||||
epNo)
|
||||
if self.show.is_anime:
|
||||
a = helpers.get_absolute_number_from_season_and_episode(self.show, s, e)
|
||||
if a:
|
||||
new_absolute_numbers.append(a)
|
||||
|
||||
new_episode_numbers.append(e)
|
||||
new_season_numbers.append(s)
|
||||
|
||||
|
|
|
@ -280,6 +280,16 @@ anime_regexes = {'anime':[
|
|||
.*? # Separator and EOL
|
||||
'''),
|
||||
|
||||
('anime_codec_crc',
|
||||
'''
|
||||
^(?:\[(?P<release_group>.*?)\][ ._-]*)?
|
||||
(?:(?P<series_name>.*?)[ ._-]*)?
|
||||
(?:(?P<ep_ab_num>\d{1,3})[ ._-]*).+?
|
||||
(?:\[(?P<codec>.*?)\][ ._-]*)
|
||||
(?:\[(?P<crc>\w{8})\])?
|
||||
.*?
|
||||
'''),
|
||||
|
||||
('anime_and_normal',
|
||||
# Bleach - s16e03-04 - 313-314
|
||||
# Bleach.s16e03-04.313-314
|
||||
|
@ -360,6 +370,7 @@ anime_regexes = {'anime':[
|
|||
.*?
|
||||
"""
|
||||
),
|
||||
|
||||
('anime_bare',
|
||||
# One Piece - 102
|
||||
# [ACX]_Wolf's_Spirit_001.mkv
|
||||
|
|
|
@ -198,9 +198,6 @@ class TVShow(object):
|
|||
# Load XEM data to DB for show
|
||||
sickbeard.scene_numbering.xem_refresh(self.indexerid, self.indexer, force=forceUpdate)
|
||||
|
||||
if not season in self.episodes:
|
||||
self.episodes[season] = {}
|
||||
|
||||
ep = None
|
||||
|
||||
# if we get an anime get the real season and episode
|
||||
|
@ -225,6 +222,9 @@ class TVShow(object):
|
|||
logger.DEBUG)
|
||||
return None
|
||||
|
||||
if not season in self.episodes:
|
||||
self.episodes[season] = {}
|
||||
|
||||
if not episode in self.episodes[season] or self.episodes[season][episode] == None:
|
||||
if noCreate:
|
||||
return None
|
||||
|
|
|
@ -68,6 +68,8 @@ class XEMBasicTests(test.SickbeardTestDBCase):
|
|||
name = "Game.of.Thrones.S03.720p.HDTV.x264-CtrlHD"
|
||||
release = "Game of Thrones"
|
||||
|
||||
m = re.match('(?P<ep_ab_num>(?>\d{1,3})(?![ip])).+', name)
|
||||
|
||||
escaped_name = re.sub('\\\\[\\s.-]', '\W+', re.escape(release))
|
||||
curRegex = '^' + escaped_name + '\W+(?:(?:S\d[\dE._ -])|(?:\d\d?x)|(?:\d{4}\W\d\d\W\d\d)|(?:(?:part|pt)[\._ -]?(\d|[ivx]))|Season\W+\d+\W+|E\d+\W+|(?:\d{1,3}.+\d{1,}[a-zA-Z]{2}\W+[a-zA-Z]{3,}\W+\d{4}.+))'
|
||||
print(u"Checking if show " + name + " matches " + curRegex)
|
||||
|
@ -76,7 +78,6 @@ class XEMBasicTests(test.SickbeardTestDBCase):
|
|||
if match:
|
||||
print(u"Matched " + curRegex + " to " + name)
|
||||
|
||||
print(parse_result)
|
||||
|
||||
if __name__ == "__main__":
|
||||
print "=================="
|
||||
|
|
Loading…
Reference in a new issue