mirror of
https://github.com/SickGear/SickGear.git
synced 2025-01-05 17:43:37 +00:00
Improved code for better performance of application memory and cpu usage.
This commit is contained in:
parent
6a8bef76c9
commit
09476224c5
6 changed files with 46 additions and 106 deletions
|
@ -66,15 +66,9 @@ 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_event_date), logger.DEBUG)
|
||||
|
||||
show_id = self._get_show_id(parsed.series_name)
|
||||
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)
|
||||
self._show_obj = parsed.show
|
||||
if self._show_obj is None:
|
||||
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)",
|
||||
|
@ -90,24 +84,4 @@ class FailedProcessor(object):
|
|||
def _log(self, message, level=logger.MESSAGE):
|
||||
"""Log to regular logfile and save for return for PP script log"""
|
||||
logger.log(message, level)
|
||||
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
|
||||
|
||||
self.log += message + "\n"
|
|
@ -126,7 +126,9 @@ class NameParser(object):
|
|||
result.episode_numbers = [ep_num]
|
||||
|
||||
if 'sports_event_id' in named_groups:
|
||||
result.sports_event_id = int(match.group('sports_event_id'))
|
||||
sports_event_id = match.group('sports_event_id')
|
||||
if sports_event_id:
|
||||
result.sports_event_id = int(match.group('sports_event_id'))
|
||||
|
||||
if 'sports_event_name' in named_groups:
|
||||
result.sports_event_name = match.group('sports_event_name')
|
||||
|
|
|
@ -133,7 +133,7 @@ def splitResult(result):
|
|||
# parse the name
|
||||
try:
|
||||
np = NameParser(False)
|
||||
parse_result = np.parse(newNZB)
|
||||
parse_result = np.parse(newNZB).convert()
|
||||
except InvalidNameException:
|
||||
logger.log(u"Unable to parse the filename " + newNZB + " into a valid episode", logger.WARNING)
|
||||
return False
|
||||
|
|
|
@ -105,6 +105,12 @@ class ProperFinder():
|
|||
logger.log(u"Unable to parse the filename " + curProper.name + " into a valid episode", logger.DEBUG)
|
||||
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:
|
||||
logger.log(
|
||||
u"Ignoring " + curProper.name + " because it's for a full season rather than specific episode",
|
||||
|
@ -178,20 +184,20 @@ class ProperFinder():
|
|||
continue
|
||||
|
||||
# if we have an air-by-date show then get the real season/episode numbers
|
||||
if curProper.season == -1 and curProper.indexerid:
|
||||
indexer_lang = showObj.lang
|
||||
lINDEXER_API_PARMS = sickbeard.indexerApi(showObj.indexer).api_params.copy()
|
||||
if indexer_lang and not indexer_lang == 'en':
|
||||
lINDEXER_API_PARMS['language'] = indexer_lang
|
||||
if curProper.season == -1 and curProper.indexerid and curProper.indexer:
|
||||
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 = 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:
|
||||
t = sickbeard.indexerApi(showObj.indexer).indexer(**lINDEXER_API_PARMS)
|
||||
|
||||
epObj = t[curProper.indexerid].airedOn(curProper.episode)[0]
|
||||
|
||||
curProper.season = int(epObj["seasonnumber"])
|
||||
curProper.episodes = [int(epObj["episodenumber"])]
|
||||
except sickbeard.indexer_episodenotfound:
|
||||
if sql_result:
|
||||
curProper.season = int(sql_result[0][0])
|
||||
curProper.episodes = [int(sql_result[0][1])]
|
||||
else:
|
||||
logger.log(u"Unable to find episode with date " + str(
|
||||
curProper.episode) + " for show " + parse_result.series_name + ", skipping", logger.WARNING)
|
||||
continue
|
||||
|
|
|
@ -47,11 +47,17 @@ def filterBadReleases(name):
|
|||
|
||||
try:
|
||||
fp = NameParser()
|
||||
fp.parse(name)
|
||||
parse_result = fp.parse(name)
|
||||
except InvalidNameException:
|
||||
logger.log(u"Unable to parse the filename " + name + " into a valid episode", logger.WARNING)
|
||||
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 sickbeard.IGNORE_WORDS:
|
||||
resultFilters.extend(sickbeard.IGNORE_WORDS.split(','))
|
||||
|
|
|
@ -312,45 +312,6 @@ class TVShow(object):
|
|||
parse_result = 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)
|
||||
try:
|
||||
curEpisode = self.makeEpFromFile(ek.ek(os.path.join, self._location, mediaFile))
|
||||
|
@ -562,32 +523,23 @@ class TVShow(object):
|
|||
rootEp = None
|
||||
|
||||
# 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 parse_result.air_by_date:
|
||||
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])
|
||||
|
||||
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:
|
||||
epObj = t[self.indexerid].airedOn(parse_result.air_date)[0]
|
||||
|
||||
season = int(epObj["seasonnumber"])
|
||||
episodes = [int(epObj["episodenumber"])]
|
||||
except sickbeard.indexer_episodenotfound:
|
||||
if sql_result:
|
||||
season = int(sql_result[0][0])
|
||||
episodes = [int(sql_result[0][1])]
|
||||
else:
|
||||
logger.log(u"Unable to find episode with date " + str(
|
||||
parse_result.air_date) + " for show " + self.name + ", skipping", logger.WARNING)
|
||||
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:
|
||||
|
||||
|
|
Loading…
Reference in a new issue