Improved code for better performance of application memory and cpu usage.

This commit is contained in:
echel0n 2014-05-02 03:09:17 -07:00
parent 6a8bef76c9
commit 09476224c5
6 changed files with 46 additions and 106 deletions

View file

@ -66,15 +66,9 @@ class FailedProcessor(object):
logger.log(u" - " + str(parsed.extra_info), logger.DEBUG) logger.log(u" - " + str(parsed.extra_info), logger.DEBUG)
logger.log(u" - " + str(parsed.release_group), 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.air_date), logger.DEBUG)
logger.log(u" - " + str(parsed.sports_event_date), logger.DEBUG)
show_id = self._get_show_id(parsed.series_name) self._show_obj = parsed.show
if show_id is None:
self._log(u"Warning: couldn't find show ID", logger.WARNING)
raise exceptions.FailedProcessingFailed()
self._log(u"Found show_id: " + str(show_id), logger.DEBUG)
self._show_obj = helpers.findCertainShow(sickbeard.showList, show_id)
if self._show_obj is None: if self._show_obj is None:
self._log( self._log(
u"Could not create show object. Either the show hasn't been added to SickBeard, or it's still loading (if SB was restarted recently)", u"Could not create show object. Either the show hasn't been added to SickBeard, or it's still loading (if SB was restarted recently)",
@ -91,23 +85,3 @@ class FailedProcessor(object):
"""Log to regular logfile and save for return for PP script log""" """Log to regular logfile and save for return for PP script log"""
logger.log(message, level) logger.log(message, level)
self.log += message + "\n" self.log += message + "\n"
def _get_show_id(self, series_name):
"""Find and return show ID by searching exceptions, then DB"""
show_names = show_name_helpers.sceneToNormalShowNames(series_name)
logger.log(u"show_names: " + str(show_names), logger.DEBUG)
for show_name in show_names:
exception = scene_exceptions.get_scene_exception_by_name(show_name)
if exception is not None:
return exception
for show_name in show_names:
found_info = helpers.get_show_by_name(show_name)
if found_info is not None:
return (found_info.indexerid)
return None

View file

@ -126,6 +126,8 @@ class NameParser(object):
result.episode_numbers = [ep_num] result.episode_numbers = [ep_num]
if 'sports_event_id' in named_groups: 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.sports_event_id = int(match.group('sports_event_id'))
if 'sports_event_name' in named_groups: if 'sports_event_name' in named_groups:

View file

@ -133,7 +133,7 @@ def splitResult(result):
# parse the name # parse the name
try: try:
np = NameParser(False) np = NameParser(False)
parse_result = np.parse(newNZB) parse_result = np.parse(newNZB).convert()
except InvalidNameException: except InvalidNameException:
logger.log(u"Unable to parse the filename " + newNZB + " into a valid episode", logger.WARNING) logger.log(u"Unable to parse the filename " + newNZB + " into a valid episode", logger.WARNING)
return False return False

View file

@ -105,6 +105,12 @@ class ProperFinder():
logger.log(u"Unable to parse the filename " + curProper.name + " into a valid episode", logger.DEBUG) logger.log(u"Unable to parse the filename " + curProper.name + " into a valid episode", logger.DEBUG)
continue continue
# if we can't find the show then there's nothing we can really do
if not parse_result.show:
logger.log(u"This show isn't in your list, skipping ...",
logger.DEBUG)
continue
if not parse_result.episode_numbers: if not parse_result.episode_numbers:
logger.log( logger.log(
u"Ignoring " + curProper.name + " because it's for a full season rather than specific episode", u"Ignoring " + curProper.name + " because it's for a full season rather than specific episode",
@ -178,20 +184,20 @@ class ProperFinder():
continue continue
# if we have an air-by-date show then get the real season/episode numbers # if we have an air-by-date show then get the real season/episode numbers
if curProper.season == -1 and curProper.indexerid: if curProper.season == -1 and curProper.indexerid and curProper.indexer:
indexer_lang = showObj.lang logger.log(
lINDEXER_API_PARMS = sickbeard.indexerApi(showObj.indexer).api_params.copy() u"Looks like this is an air-by-date or sports show, attempting to convert the date to season/episode",
if indexer_lang and not indexer_lang == 'en': logger.DEBUG)
lINDEXER_API_PARMS['language'] = indexer_lang airdate = curProper.episode.toordinal()
myDB = db.DBConnection()
sql_result = myDB.select(
"SELECT season, episode FROM tv_episodes WHERE showid = ? and indexer = ? and airdate = ?",
[curProper.indexerid, curProper.indexer, airdate])
try: if sql_result:
t = sickbeard.indexerApi(showObj.indexer).indexer(**lINDEXER_API_PARMS) curProper.season = int(sql_result[0][0])
curProper.episodes = [int(sql_result[0][1])]
epObj = t[curProper.indexerid].airedOn(curProper.episode)[0] else:
curProper.season = int(epObj["seasonnumber"])
curProper.episodes = [int(epObj["episodenumber"])]
except sickbeard.indexer_episodenotfound:
logger.log(u"Unable to find episode with date " + str( logger.log(u"Unable to find episode with date " + str(
curProper.episode) + " for show " + parse_result.series_name + ", skipping", logger.WARNING) curProper.episode) + " for show " + parse_result.series_name + ", skipping", logger.WARNING)
continue continue

View file

@ -47,11 +47,17 @@ def filterBadReleases(name):
try: try:
fp = NameParser() fp = NameParser()
fp.parse(name) parse_result = fp.parse(name)
except InvalidNameException: except InvalidNameException:
logger.log(u"Unable to parse the filename " + name + " into a valid episode", logger.WARNING) logger.log(u"Unable to parse the filename " + name + " into a valid episode", logger.WARNING)
return False return False
# if we can't find the show then there's nothing we can really do
if not parse_result.show:
logger.log(u"This show isn't in your list, skipping ...",
logger.DEBUG)
return False
# if any of the bad strings are in the name then say no # if any of the bad strings are in the name then say no
if sickbeard.IGNORE_WORDS: if sickbeard.IGNORE_WORDS:
resultFilters.extend(sickbeard.IGNORE_WORDS.split(',')) resultFilters.extend(sickbeard.IGNORE_WORDS.split(','))

View file

@ -312,45 +312,6 @@ class TVShow(object):
parse_result = None parse_result = None
curEpisode = None curEpisode = None
if sceneConvert:
try:
i = 0
while i < 2:
i+=1
np = NameParser(False)
parse_result = np.parse(mediaFile, True if i > 1 else False)
if helpers.validateShow(self, parse_result.season_number, parse_result.episode_numbers[0]):
ep = TVEpisode(self, parse_result.season_number, parse_result.episode_numbers[0])
proper_path = ep.proper_path()
proper_absolute_path = ek.ek(os.path.join, self._location, proper_path)
src_path = ek.ek(os.path.dirname, mediaFile)
dest_path = ek.ek(os.path.dirname, proper_absolute_path)
orig_extension = mediaFile.rpartition('.')[-1]
new_base_name = ek.ek(os.path.basename, proper_path)
new_file_name = new_base_name + '.' + orig_extension
old_file_name = ek.ek(os.path.basename, mediaFile)
new_mediaFile = os.path.join(dest_path, new_file_name)
if old_file_name == new_file_name or os.path.exists(new_mediaFile):break
if os.path.exists(os.path.join(src_path, old_file_name)):
old_mediaFile = os.path.join(src_path, old_file_name)
elif os.path.exists(os.path.join(dest_path, old_file_name)):
old_mediaFile = os.path.join(dest_path, old_file_name)
else:break
logger.log(u"Scene Converting file %s to %s" % (old_file_name, new_file_name), logger.MESSAGE)
if not os.path.exists(dest_path):
shutil.move(src_path, dest_path)
shutil.move(old_mediaFile, new_mediaFile)
mediaFile = new_mediaFile
# converted
break
except Exception:
continue
logger.log(str(self.indexerid) + u": Creating episode from " + mediaFile, logger.DEBUG) logger.log(str(self.indexerid) + u": Creating episode from " + mediaFile, logger.DEBUG)
try: try:
curEpisode = self.makeEpFromFile(ek.ek(os.path.join, self._location, mediaFile)) curEpisode = self.makeEpFromFile(ek.ek(os.path.join, self._location, mediaFile))
@ -562,32 +523,23 @@ class TVShow(object):
rootEp = None rootEp = None
# if we have an air-by-date show then get the real season/episode numbers # if we have an air-by-date show then get the real season/episode numbers
if parse_result.air_by_date or parse_result.sports:
try:
lINDEXER_API_PARMS = sickbeard.indexerApi(self.indexer).api_params.copy()
if self.lang:
lINDEXER_API_PARMS['language'] = self.lang
if self.dvdorder != 0:
lINDEXER_API_PARMS['dvdorder'] = True
t = sickbeard.indexerApi(self.indexer).indexer(**lINDEXER_API_PARMS)
epObj = None
if parse_result.air_by_date: if parse_result.air_by_date:
epObj = t[self.indexerid].airedOn(parse_result.air_date)[0] logger.log(
u"Looks like this is an air-by-date or sports show, attempting to convert the date to season/episode",
logger.DEBUG)
airdate = parse_result.air_date.toordinal()
myDB = db.DBConnection()
sql_result = myDB.select(
"SELECT season, episode FROM tv_episodes WHERE showid = ? and indexer = ? and airdate = ?",
[self.indexerid, self.indexer, airdate])
season = int(epObj["seasonnumber"]) if sql_result:
episodes = [int(epObj["episodenumber"])] season = int(sql_result[0][0])
except sickbeard.indexer_episodenotfound: episodes = [int(sql_result[0][1])]
else:
logger.log(u"Unable to find episode with date " + str( logger.log(u"Unable to find episode with date " + str(
parse_result.air_date) + " for show " + self.name + ", skipping", logger.WARNING) parse_result.air_date) + " for show " + self.name + ", skipping", logger.WARNING)
return None return None
except sickbeard.indexer_error, e:
logger.log(u"Unable to contact " + sickbeard.indexerApi(self.indexer).name + ": " + ex(e),
logger.WARNING)
return None
for curEpNum in episodes: for curEpNum in episodes: