Commit 971e8e28 authored by echel0n's avatar echel0n
Browse files

Misc exception handling fixes for indexers

parent 49aa5e8b
......@@ -32,7 +32,6 @@ from sickrage.core.media.poster import Poster
from sickrage.core.websession import WebSession
from sickrage.indexers import IndexerApi
from sickrage.indexers.config import INDEXER_TVDB
from sickrage.indexers.exceptions import indexer_error
def showImage(show=None, which=None):
......
......@@ -38,7 +38,6 @@ from sickrage.core.nameparser import regexes
from sickrage.core.scene_numbering import get_absolute_number_from_season_and_episode, get_indexer_absolute_numbering, get_indexer_numbering
from sickrage.core.tv.show.helpers import find_show_by_name, find_show, find_show_by_scene_exception
from sickrage.indexers import IndexerApi
from sickrage.indexers.exceptions import indexer_episodenotfound, indexer_error
class NameParser(object):
......
......@@ -37,7 +37,7 @@ from sickrage.core.traktapi import TraktAPI
from sickrage.core.tv.show import TVShow
from sickrage.core.tv.show.helpers import find_show
from sickrage.indexers import IndexerApi
from sickrage.indexers.exceptions import indexer_attributenotfound, indexer_error, indexer_exception
from sickrage.indexers.exceptions import indexer_attributenotfound, indexer_exception
class ShowQueue(SRQueue):
......@@ -519,12 +519,12 @@ class QueueItemUpdate(ShowQueueItem):
try:
sickrage.app.log.debug("Retrieving show info from " + IndexerApi(show_obj.indexer).name + "")
show_obj.load_from_indexer(cache=False)
except indexer_error as e:
sickrage.app.log.warning("Unable to contact " + IndexerApi(show_obj.indexer).name + ", aborting: {}".format(e))
return
except indexer_attributenotfound as e:
sickrage.app.log.warning("Data retrieved from " + IndexerApi(show_obj.indexer).name + " was incomplete, aborting: {}".format(e))
return
except indexer_exception as e:
sickrage.app.log.warning("Unable to contact " + IndexerApi(show_obj.indexer).name + ", aborting: {}".format(e))
return
try:
if not self.indexer_update_only:
......
......@@ -43,7 +43,7 @@ from sickrage.core.helpers import replace_extension, modify_file_timestamp, sani
remove_extension, sanitize_file_name, make_dirs, move_file, delete_empty_folders
from sickrage.core.tv.show.helpers import find_show
from sickrage.indexers import IndexerApi
from sickrage.indexers.exceptions import indexer_seasonnotfound, indexer_error, indexer_episodenotfound
from sickrage.indexers.exceptions import indexer_seasonnotfound, indexer_episodenotfound
from sickrage.notifiers import Notifiers
from sickrage.subtitles import Subtitles
......@@ -429,22 +429,14 @@ class TVEpisode(object):
myEp = indexer_data[season][episode]
else:
myEp = cachedSeason[episode]
except (indexer_error, IOError) as e:
sickrage.app.log.debug("{} threw up an error: {}".format(indexer_name, e))
# if the episode is already valid just log it, if not throw it up
if self.name:
sickrage.app.log.debug("{} timed out but we have enough info from other sources, allowing the error".format(indexer_name))
return False
else:
sickrage.app.log.error("{} timed out, unable to create the episode".format(indexer_name))
return False
except (indexer_episodenotfound, indexer_seasonnotfound):
sickrage.app.log.debug("Unable to find the episode on {}, has it been removed?".format(indexer_name))
# if I'm no longer on the Indexers but I once was then delete myself from the DB
if self.indexer_id != -1:
if self.indexer_id != 0:
self.show.get_episode(season, episode).delete_episode()
raise EpisodeDeletedException
return False
self.indexer_id = try_int(safe_getattr(myEp, 'id'), self.indexer_id)
......
......@@ -46,8 +46,7 @@ from sickrage.core.helpers import list_media_files, is_media_file, try_int, safe
from sickrage.core.nameparser import NameParser, InvalidNameException, InvalidShowException
from sickrage.core.tv.episode import TVEpisode
from sickrage.indexers import IndexerApi
from sickrage.indexers.config import INDEXER_TVRAGE
from sickrage.indexers.exceptions import indexer_attributenotfound
from sickrage.indexers.exceptions import indexer_attributenotfound, indexer_exception
class TVShow(object):
......@@ -572,53 +571,49 @@ class TVShow(object):
self._episodes.clear()
def load_from_indexer(self, cache=True, tvapi=None):
if self.indexer is not INDEXER_TVRAGE:
sickrage.app.log.debug(
str(self.indexer_id) + ": Loading show info from " + IndexerApi(self.indexer).name)
sickrage.app.log.debug(str(self.indexer_id) + ": Loading show info from " + IndexerApi(self.indexer).name)
t = tvapi
if not t:
lINDEXER_API_PARMS = IndexerApi(self.indexer).api_params.copy()
lINDEXER_API_PARMS['cache'] = cache
t = tvapi
if not t:
lINDEXER_API_PARMS = IndexerApi(self.indexer).api_params.copy()
lINDEXER_API_PARMS['cache'] = cache
lINDEXER_API_PARMS['language'] = self.lang or sickrage.app.config.indexer_default_language
lINDEXER_API_PARMS['language'] = self.lang or sickrage.app.config.indexer_default_language
if self.dvdorder != 0:
lINDEXER_API_PARMS['dvdorder'] = True
if self.dvdorder != 0:
lINDEXER_API_PARMS['dvdorder'] = True
t = IndexerApi(self.indexer).indexer(**lINDEXER_API_PARMS)
t = IndexerApi(self.indexer).indexer(**lINDEXER_API_PARMS)
myEp = t[self.indexer_id]
if not myEp:
return
myEp = t[self.indexer_id]
if not myEp:
raise indexer_exception
try:
self.name = myEp['seriesname'].strip()
except AttributeError:
raise indexer_attributenotfound("Found %s, but attribute 'seriesname' was empty." % self.indexer_id)
try:
self.name = myEp['seriesname'].strip()
except AttributeError:
raise indexer_attributenotfound("Found %s, but attribute 'seriesname' was empty." % self.indexer_id)
self.overview = safe_getattr(myEp, 'overview', self.overview)
self.classification = safe_getattr(myEp, 'classification', self.classification)
self.genre = safe_getattr(myEp, 'genre', self.genre)
self.network = safe_getattr(myEp, 'network', self.network)
self.runtime = try_int(safe_getattr(myEp, 'runtime', self.runtime))
self.imdb_id = safe_getattr(myEp, 'imdbid', self.imdb_id)
self.overview = safe_getattr(myEp, 'overview', self.overview)
self.classification = safe_getattr(myEp, 'classification', self.classification)
self.genre = safe_getattr(myEp, 'genre', self.genre)
self.network = safe_getattr(myEp, 'network', self.network)
self.runtime = try_int(safe_getattr(myEp, 'runtime', self.runtime))
self.imdb_id = safe_getattr(myEp, 'imdbid', self.imdb_id)
try:
self.airs = (safe_getattr(myEp, 'airsdayofweek') + " " + safe_getattr(myEp, 'airstime')).strip()
except:
self.airs = ''
try:
self.airs = (safe_getattr(myEp, 'airsdayofweek') + " " + safe_getattr(myEp, 'airstime')).strip()
except:
self.airs = ''
try:
self.startyear = try_int(str(safe_getattr(myEp, 'firstaired') or datetime.date.min).split('-')[0])
except:
self.startyear = 0
try:
self.startyear = try_int(str(safe_getattr(myEp, 'firstaired') or datetime.date.min).split('-')[0])
except:
self.startyear = 0
self.status = safe_getattr(myEp, 'status', self.status)
self.status = safe_getattr(myEp, 'status', self.status)
self.save()
else:
sickrage.app.log.warning(str(self.indexer_id) + ": NOT loading info from " + IndexerApi(self.indexer).name + " as it is temporarily disabled.")
self.save()
def load_episodes_from_indexer(self, cache=True):
scanned_eps = {}
......@@ -638,9 +633,13 @@ class TVShow(object):
# flush episodes from cache so we can reload from database
self.flush_episodes()
for season in t[self.indexer_id]:
indexer_data = t[self.indexer_id]
if not indexer_data:
raise indexer_exception
for season in indexer_data:
scanned_eps[season] = {}
for episode in t[self.indexer_id][season]:
for episode in indexer_data[season]:
# need some examples of wtf episode 0 means to decide if we want it or not
if episode == 0:
continue
......
......@@ -53,8 +53,6 @@ from sickrage.core.tv.show.coming_episodes import ComingEpisodes
from sickrage.core.tv.show.helpers import find_show, get_show_list
from sickrage.core.tv.show.history import History
from sickrage.indexers import IndexerApi
from sickrage.indexers.exceptions import indexer_error, \
indexer_showincomplete, indexer_shownotfound
from sickrage.indexers.helpers import map_indexers
from sickrage.indexers.ui import AllShowsUI
from sickrage.subtitles import Subtitles
......
......@@ -20,12 +20,8 @@
# ##############################################################################
from sickrage.indexers.thetvdb.exceptions import tvdb_attributenotfound, tvdb_episodenotfound, tvdb_error, tvdb_exception, \
tvdb_seasonnotfound, tvdb_showincomplete, tvdb_shownotfound
__author__ = "echel0n"
__version__ = "1.0"
from sickrage.indexers.thetvdb.exceptions import tvdb_attributenotfound, tvdb_episodenotfound, tvdb_error, tvdb_exception, tvdb_seasonnotfound, \
tvdb_showincomplete, tvdb_shownotfound
indexerExcepts = ["indexer_exception", "indexer_error", "indexer_userabort", "indexer_shownotfound",
"indexer_showincomplete", "indexer_seasonnotfound", "indexer_episodenotfound",
......
......@@ -30,7 +30,7 @@ import sickrage
from sickrage.core.helpers import chmod_as_parent, replace_extension, try_int
from sickrage.core.websession import WebSession
from sickrage.indexers import IndexerApi
from sickrage.indexers.exceptions import indexer_error, indexer_episodenotfound, indexer_seasonnotfound
from sickrage.indexers.exceptions import indexer_episodenotfound, indexer_seasonnotfound
from sickrage.indexers.helpers import map_indexers
......@@ -606,22 +606,16 @@ class GenericMetadata(object):
sickrage.app.log.warning("Invalid image type " + str(image_type) + ", couldn't find it in the " + IndexerApi(show_obj.indexer).name + " object")
return
try:
# There's gotta be a better way of doing this but we don't wanna
# change the language value elsewhere
lINDEXER_API_PARMS = IndexerApi(show_obj.indexer).api_params.copy()
# There's gotta be a better way of doing this but we don't wanna
# change the language value elsewhere
lINDEXER_API_PARMS = IndexerApi(show_obj.indexer).api_params.copy()
lINDEXER_API_PARMS['language'] = indexer_lang
lINDEXER_API_PARMS['language'] = indexer_lang
if show_obj.dvdorder != 0:
lINDEXER_API_PARMS['dvdorder'] = True
if show_obj.dvdorder != 0:
lINDEXER_API_PARMS['dvdorder'] = True
t = IndexerApi(show_obj.indexer).indexer(**lINDEXER_API_PARMS)
except (indexer_error, IOError) as e:
sickrage.app.log.warning("{}: Unable to look up show on ".format(show_obj.indexer_id) + IndexerApi(
show_obj.indexer).name + ", not downloading images: {}".format(e))
sickrage.app.log.debug("Indexer " + IndexerApi(show_obj.indexer).name + " maybe experiencing some problems. Try again later")
return None
t = IndexerApi(show_obj.indexer).indexer(**lINDEXER_API_PARMS)
is_image_thumb = '_thumb' in image_type
image_types = {
......
......@@ -22,11 +22,10 @@ from xml.etree.ElementTree import Element, ElementTree, SubElement
import sickrage
from sickrage.core.common import dateFormat
from sickrage.core.exceptions import ShowNotFoundException
from sickrage.core.helpers import indent_xml
from sickrage.indexers import IndexerApi
from sickrage.indexers.exceptions import indexer_episodenotfound, \
indexer_error, indexer_seasonnotfound, indexer_shownotfound
indexer_seasonnotfound
from sickrage.metadata import GenericMetadata
......
......@@ -27,11 +27,9 @@ from xml.etree.ElementTree import Element, ElementTree, SubElement
import sickrage
from sickrage.core.common import dateFormat
from sickrage.core.exceptions import ShowNotFoundException
from sickrage.core.helpers import replace_extension, indent_xml, chmod_as_parent
from sickrage.indexers import IndexerApi
from sickrage.indexers.exceptions import indexer_episodenotfound, \
indexer_error, indexer_seasonnotfound, indexer_shownotfound
from sickrage.indexers.exceptions import indexer_episodenotfound, indexer_seasonnotfound
from sickrage.metadata.mediabrowser import MediaBrowserMetadata
......
......@@ -28,11 +28,9 @@ from xml.etree.ElementTree import Element, ElementTree, SubElement
import sickrage
from sickrage.core.common import dateFormat
from sickrage.core.exceptions import ShowNotFoundException
from sickrage.core.helpers import replace_extension, indent_xml
from sickrage.indexers import IndexerApi
from sickrage.indexers.exceptions import indexer_episodenotfound, \
indexer_error, indexer_seasonnotfound, indexer_shownotfound
from sickrage.indexers.exceptions import indexer_episodenotfound, indexer_seasonnotfound
from sickrage.metadata import GenericMetadata
......
......@@ -25,11 +25,9 @@ import datetime
import os
import sickrage
from sickrage.core.exceptions import ShowNotFoundException
from sickrage.core.helpers import chmod_as_parent
from sickrage.indexers import IndexerApi
from sickrage.indexers.exceptions import indexer_episodenotfound, \
indexer_error, indexer_seasonnotfound, indexer_shownotfound
from sickrage.indexers.exceptions import indexer_episodenotfound, indexer_seasonnotfound
from sickrage.metadata import GenericMetadata
......
......@@ -28,11 +28,9 @@ from xml.etree.ElementTree import Element, ElementTree, SubElement
import sickrage
from sickrage.core.common import dateFormat
from sickrage.core.exceptions import ShowNotFoundException
from sickrage.core.helpers import replace_extension, indent_xml
from sickrage.indexers import IndexerApi
from sickrage.indexers.exceptions import indexer_episodenotfound, \
indexer_error, indexer_seasonnotfound, indexer_shownotfound
from sickrage.indexers.exceptions import indexer_episodenotfound, indexer_seasonnotfound
from sickrage.metadata import GenericMetadata
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment