1
0
mirror of https://github.com/moparisthebest/SickRage synced 2024-12-04 15:12:23 -05:00

Fix for air-by-date and sports shows issues with parsing results.

This commit is contained in:
echel0n 2014-08-22 00:21:37 -07:00
parent 328597411e
commit be17ed122b
7 changed files with 17 additions and 117 deletions

View File

@ -63,7 +63,6 @@ class FailedProcessor(object):
logger.log(u" - " + str(parsed.extra_info), logger.DEBUG)
logger.log(u" - " + str(parsed.release_group), logger.DEBUG)
logger.log(u" - " + str(parsed.air_date), logger.DEBUG)
logger.log(u" - " + str(parsed.sports_air_date), logger.DEBUG)
segment = {parsed.season_number: []}
for episode in parsed.episode_numbers:

View File

@ -33,8 +33,7 @@ from dateutil import parser
class NameParser(object):
ALL_REGEX = 0
NORMAL_REGEX = 1
SPORTS_REGEX = 2
ANIME_REGEX = 3
ANIME_REGEX = 2
def __init__(self, file_name=True, showObj=None, tryIndexers=False, convert=False,
naming_pattern=False):
@ -45,12 +44,10 @@ class NameParser(object):
self.convert = convert
self.naming_pattern = naming_pattern
if self.showObj and not self.showObj.is_anime and not self.showObj.is_sports:
if self.showObj and not self.showObj.is_anime:
self._compile_regexes(self.NORMAL_REGEX)
elif self.showObj and self.showObj.is_anime:
self._compile_regexes(self.ANIME_REGEX)
elif self.showObj and self.showObj.is_sports:
self._compile_regexes(self.SPORTS_REGEX)
else:
self._compile_regexes(self.ALL_REGEX)
@ -79,10 +76,7 @@ class NameParser(object):
return series_name.strip()
def _compile_regexes(self, regexMode):
if regexMode == self.SPORTS_REGEX:
logger.log(u"Using SPORTS regexs", logger.DEBUG)
uncompiled_regex = [regexes.sports_regexs]
elif regexMode == self.ANIME_REGEX:
if regexMode == self.ANIME_REGEX:
logger.log(u"Using ANIME regexs", logger.DEBUG)
uncompiled_regex = [regexes.anime_regexes, regexes.normal_regexes]
elif regexMode == self.NORMAL_REGEX:
@ -90,7 +84,7 @@ class NameParser(object):
uncompiled_regex = [regexes.normal_regexes]
else:
logger.log(u"Using ALL regexes", logger.DEBUG)
uncompiled_regex = [regexes.normal_regexes, regexes.sports_regexs, regexes.anime_regexes]
uncompiled_regex = [regexes.normal_regexes, regexes.anime_regexes]
self.compiled_regexes = []
for regexItem in uncompiled_regex:
@ -153,34 +147,10 @@ class NameParser(object):
result.ab_episode_numbers = [ep_ab_num]
result.score += 1
if 'sports_event_id' in named_groups:
sports_event_id = match.group('sports_event_id')
if sports_event_id:
result.sports_event_id = int(match.group('sports_event_id'))
result.score += 1
if 'sports_event_name' in named_groups:
result.sports_event_name = match.group('sports_event_name')
if result.sports_event_name:
result.sports_event_name = self.clean_series_name(result.sports_event_name)
result.score += 1
if 'sports_air_date' in named_groups:
sports_air_date = match.group('sports_air_date')
if 'air_date' in named_groups:
air_date = match.group('air_date')
try:
result.sports_air_date = parser.parse(sports_air_date, fuzzy=True).date()
result.score += 1
except:
continue
if 'air_year' in named_groups and 'air_month' in named_groups and 'air_day' in named_groups:
year = int(match.group('air_year'))
month = int(match.group('air_month'))
day = int(match.group('air_day'))
try:
dtStr = '%s-%s-%s' % (year, month, day)
result.air_date = datetime.datetime.strptime(dtStr, "%Y-%m-%d").date()
result.air_date = parser.parse(air_date, fuzzy=True).date()
result.score += 1
except:
continue
@ -241,12 +211,8 @@ class NameParser(object):
new_absolute_numbers = []
# if we have an air-by-date show then get the real season/episode numbers
if bestResult.is_air_by_date or bestResult.is_sports:
try:
airdate = bestResult.air_date.toordinal()
except:
airdate = bestResult.sports_air_date.toordinal()
if bestResult.is_air_by_date:
airdate = bestResult.air_date.toordinal()
myDB = db.DBConnection()
sql_result = myDB.select(
"SELECT season, episode FROM tv_episodes WHERE showid = ? and indexer = ? and airdate = ?",
@ -265,10 +231,7 @@ class NameParser(object):
t = sickbeard.indexerApi(bestResult.show.indexer).indexer(**lINDEXER_API_PARMS)
if bestResult.is_air_by_date:
epObj = t[bestResult.show.indexerid].airedOn(bestResult.air_date)[0]
else:
epObj = t[bestResult.show.indexerid].airedOn(bestResult.sports_air_date)[0]
epObj = t[bestResult.show.indexerid].airedOn(bestResult.air_date)[0]
season_number = int(epObj["seasonnumber"])
episode_numbers = [int(epObj["episodenumber"])]
@ -459,12 +422,7 @@ class NameParser(object):
# anime absolute numbers
final_result.ab_episode_numbers = self._combine_results(file_name_result, dir_name_result, 'ab_episode_numbers')
# sports
final_result.sports_event_id = self._combine_results(file_name_result, dir_name_result, 'sports_event_id')
final_result.sports_event_name = self._combine_results(file_name_result, dir_name_result, 'sports_event_name')
final_result.sports_air_date = self._combine_results(file_name_result, dir_name_result, 'sports_air_date')
if not final_result.air_date and not final_result.sports_air_date:
if not final_result.air_date:
final_result.season_number = self._combine_results(file_name_result, dir_name_result, 'season_number')
final_result.episode_numbers = self._combine_results(file_name_result, dir_name_result, 'episode_numbers')
@ -493,7 +451,7 @@ class NameParser(object):
"Unable to parse " + name.encode(sickbeard.SYS_ENCODING, 'xmlcharrefreplace'))
# if there's no useful info in it then raise an exception
if final_result.season_number == None and not final_result.episode_numbers and final_result.air_date == None and final_result.sports_air_date == None and not final_result.ab_episode_numbers and not final_result.series_name:
if final_result.season_number == None and not final_result.episode_numbers and final_result.air_date == None and not final_result.ab_episode_numbers and not final_result.series_name:
raise InvalidNameException("Unable to parse " + name.encode(sickbeard.SYS_ENCODING, 'xmlcharrefreplace'))
if cache_result:
@ -507,9 +465,6 @@ class ParseResult(object):
def __init__(self,
original_name,
series_name=None,
sports_event_id=None,
sports_event_name=None,
sports_air_date=None,
season_number=None,
episode_numbers=None,
extra_info=None,
@ -546,10 +501,6 @@ class ParseResult(object):
self.air_date = air_date
self.sports_event_id = sports_event_id
self.sports_event_name = sports_event_name
self.sports_air_date = sports_air_date
self.which_regex = []
self.show = show
self.score = score
@ -572,12 +523,6 @@ class ParseResult(object):
return False
if self.air_date != other.air_date:
return False
if self.sports_event_id != other.sports_event_id:
return False
if self.sports_event_name != other.sports_event_name:
return False
if self.sports_air_date != other.sports_air_date:
return False
if self.ab_episode_numbers != other.ab_episode_numbers:
return False
if self.show != other.show:
@ -604,10 +549,6 @@ class ParseResult(object):
if self.is_air_by_date:
to_return += str(self.air_date)
if self.is_sports:
to_return += str(self.sports_event_name)
to_return += str(self.sports_event_id)
to_return += str(self.sports_air_date)
if self.ab_episode_numbers:
to_return += ' [ABS: ' + str(self.ab_episode_numbers) + ']'
if self.version:
@ -617,7 +558,6 @@ class ParseResult(object):
to_return += ' [GROUP: ' + self.release_group + ']'
to_return += ' [ABD: ' + str(self.is_air_by_date) + ']'
to_return += ' [SPORTS: ' + str(self.is_sports) + ']'
to_return += ' [ANIME: ' + str(self.is_anime) + ']'
to_return += ' [whichReg: ' + str(self.which_regex) + ']'
@ -629,12 +569,6 @@ class ParseResult(object):
return True
return False
@property
def is_sports(self):
if self.season_number == None and len(self.episode_numbers) == 0 and self.sports_air_date:
return True
return False
@property
def is_anime(self):
if len(self.ab_episode_numbers):

View File

@ -88,9 +88,7 @@ normal_regexes = [
# Show Name - 2010-11-23 - Ep Name
'''
^((?P<series_name>.+?)[. _-]+)? # Show_Name and separator
(?P<air_year>\d{4})[. _-]+ # 2010 and separator
(?P<air_month>\d{2})[. _-]+ # 11 and separator
(?P<air_day>\d{2}) # 23 and separator
(?P<air_date>(\d{4}[. _-]+\d{1,2}[. _-]+\d{1,2})|(\d{1,2}\w{2}[. _-]+\w+[. _-]+\d{4})|(\w+[. _-]+\d{1,2}\w{2}[. _-]+\d{4}))
[. _-]*((?P<extra_info>.+?) # Source_Quality_Etc-
((?<![. _-])(?<!WEB) # Make sure this is really the release group
-(?P<release_group>[^- ]+([. _-]\[.*\])?))?)?$ # Group
@ -187,29 +185,6 @@ normal_regexes = [
'''),
]
sports_regexs = [
('sports_standard',
# Sports.Name.2010.11.23.Source.Quality.Etc-Group
# Sports.Name.23rd.Nov.2010.Source.Quality.Etc-Group
'''
^(?P<series_name>(UEFA|MLB|ESPN|WWE|MMA|UFC|TNA|EPL|NASCAR|NBA|NFL|NHL|NRL|PGA|SUPER LEAGUE|FORMULA|FIFA|NETBALL|MOTOGP))[. _-]+
(?P<sports_air_date>(\d{4}[. _-]+\d{1,2}[. _-]+\d{1,2})|(\d{1,2}\w{2}[. _-]+\w+[. _-]+\d{4})|(\w+[. _-]+\d{1,2}\w{2}[. _-]+\d{4}))[. _-]+
((?P<extra_info>.+?)((?<![. _-])(?<!WEB)-(?P<release_group>[^- ]+))?)?$
'''
),
('sports_bare',
# Sports.Name.2010.11.23.Source.Quality.Etc-Group
# Sports.Name.23rd.Nov.2010.Source.Quality.Etc-Group
'''
^(?P<series_name>.+?)\W+
(?P<sports_air_date>(\d{4}[. _-]+\d{1,2}[. _-]+\d{1,2})|(\d{1,2}\w{2}[. _-]+\w+[. _-]+\d{4})|(\w+[. _-]+\d{1,2}\w{2}[. _-]+\d{4}))[. _-]+
((?P<extra_info>.+?)((?<![. _-])(?<!WEB)
-(?P<release_group>[^- ]+([. _-]\[.*\])?))?)?$
'''
),
]
anime_regexes = [
('anime_ultimate',
"""

View File

@ -192,14 +192,10 @@ def validate_name(pattern, multi=None, anime_type=None, file_only=False, abd=Fal
logger.log("The name " + new_name + " parsed into " + str(result), logger.DEBUG)
if abd:
if abd or sports:
if result.air_date != ep.airdate:
logger.log(u"Air date incorrect in parsed episode, pattern isn't valid", logger.DEBUG)
return False
elif sports:
if result.sports_air_date != ep.airdate:
logger.log(u"Sports event date incorrect in parsed episode, pattern isn't valid", logger.DEBUG)
return False
elif anime_type != 3:
if len(result.ab_episode_numbers) and result.ab_episode_numbers != [x.absolute_number for x in [ep] + ep.relatedEps]:
logger.log(u"Absolute numbering incorrect in parsed episode, pattern isn't valid", logger.DEBUG)
@ -226,7 +222,7 @@ def generate_sample_ep(multi=None, abd=False, sports=False, anime_type=None):
ep._release_name = 'Show.Name.2011.03.09.HDTV.XviD-RLSGROUP'
ep.show.air_by_date = 1
elif sports:
ep._release_name = 'Show.Name.100.Fighter.vs.Fighter.2011.03.09.HDTV.XviD-RLSGROUP'
ep._release_name = 'Show.Name.2011.03.09.HDTV.XviD-RLSGROUP'
ep.show.sports = 1
else:
if anime_type != 3:

View File

@ -487,9 +487,6 @@ class PostProcessor(object):
if parse_result.is_air_by_date:
season = -1
episodes = [parse_result.air_date]
elif parse_result.is_sports:
season = -1
episodes = [parse_result.sports_air_date]
else:
season = parse_result.season_number
episodes = parse_result.episode_numbers

View File

@ -334,13 +334,13 @@ class GenericProvider:
actual_season = season
actual_episodes = parse_result.episode_numbers
else:
if not (parse_result.is_air_by_date or parse_result.is_sports):
if not (parse_result.is_air_by_date):
logger.log(
u"This is supposed to be a date search but the result " + title + " didn't parse as one, skipping it",
logger.DEBUG)
addCacheEntry = True
else:
airdate = parse_result.air_date.toordinal() if parse_result.air_date else parse_result.sports_air_date.toordinal()
airdate = parse_result.air_date.toordinal()
myDB = db.DBConnection()
sql_results = myDB.select(
"SELECT season, episode FROM tv_episodes WHERE showid = ? AND airdate = ?",

View File

@ -239,7 +239,6 @@ class BasicTests(test.SickbeardTestDBCase):
if DEBUG or verbose:
print 'air_by_date:', test_result.is_air_by_date, 'air_date:', test_result.air_date
print 'sports:', test_result.is_sports, 'sports_air_date:', test_result.sports_air_date
print 'anime:', test_result.is_anime, 'ab_episode_numbers:', test_result.ab_episode_numbers
print test_result
print result