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

Updated fanart api handler to use new v3 api scheme and re-coded metadata function to properly retrieve images including thumbs.

This commit is contained in:
echel0n 2014-12-20 17:29:17 -08:00
parent 785ffdcf2f
commit 46bd8515c2
3 changed files with 28 additions and 30 deletions

View File

@ -41,8 +41,7 @@ __doc__ = """
def values(obj):
return [v for k, v in obj.__dict__.iteritems() if not k.startswith('_')]
BASEURL = 'http://api.fanart.tv/webservice'
BASEURL = 'http://webservice.fanart.tv/v3/%s/%s?api_key=%s'
class FORMAT(object):
JSON = 'JSON'
@ -51,25 +50,27 @@ class FORMAT(object):
class WS(object):
MUSIC = 'artist'
MOVIE = 'movie'
TV = 'series'
MUSIC = 'music'
MOVIE = 'movies'
TV = 'tv'
class TYPE(object):
ALL = 'all'
class TV(object):
ART = 'clearart'
LOGO = 'clearlogo'
CHARACTER = 'characterart'
THUMB = 'tvthumb'
SEASONTHUMB = 'seasonthumb'
BACKGROUND = 'showbackground'
HDLOGO = 'hdtvlogo'
HDART = 'hdclearart'
ART = 'clearart'
THUMB = 'tvthumb'
POSTER = 'tvposter'
BANNER = 'tvbanner'
SEASONTHUMB = 'seasonthumb'
SEASONPOSTER = 'seasonposter'
SEASONBANNER = 'seasonbanner'
class MUSIC(object):
DISC = 'cdart'

View File

@ -22,16 +22,7 @@ class Request(object):
raise RequestFanartError('Not allowed {0}: {1} [{2}]'.format(attribute_name, attribute, ', '.join(choices)))
def __str__(self):
return '/'.join(map(str, [
fanart.BASEURL,
self._ws,
self._apikey,
self._id,
fanart.FORMAT.JSON,
self._type,
self._sort,
self._limit,
]))
return fanart.BASEURL % (self._ws, self._id, self._apikey)
def response(self):
try:

View File

@ -26,7 +26,7 @@ import re
import sickbeard
from sickbeard import exceptions, helpers
from sickbeard import helpers
from sickbeard.metadata import helpers as metadata_helpers
from sickbeard import logger
from sickbeard import encodingKludge as ek
@ -35,6 +35,9 @@ from sickbeard.show_name_helpers import allPossibleShowNames
from lib.tmdb_api.tmdb_api import TMDB
import fanart
from fanart.core import Request as fanartRequest
class GenericMetadata():
"""
Base class for all metadata providers. Default behavior is meant to mostly
@ -615,6 +618,7 @@ class GenericMetadata():
continue
result = result + [self._write_image(seasonData, season_poster_file_path)]
if result:
return all(result)
else:
@ -663,6 +667,7 @@ class GenericMetadata():
continue
result = result + [self._write_image(seasonData, season_banner_file_path)]
if result:
return all(result)
else:
@ -997,22 +1002,20 @@ class GenericMetadata():
except Exception as e:
pass
logger.log(u"Could not find any images on TMDB for " + show.name, logger.DEBUG)
def _retrieve_show_images_from_fanart(self, show, type):
from fanart.core import Request
import fanart
logger.log(u"Could not find any " + type + " images on TMDB for " + show.name, logger.DEBUG)
def _retrieve_show_images_from_fanart(self, show, type, thumb=False):
types = {'poster': fanart.TYPE.TV.POSTER,
'banner': fanart.TYPE.TV.BANNER,
'fanart': fanart.TYPE.TV.ART,
'poster_thumb': fanart.TYPE.TV.THUMB,
'banner_thumb': fanart.TYPE.TV.BANNER}
'poster_thumb': fanart.TYPE.TV.POSTER,
'banner_thumb': fanart.TYPE.TV.BANNER,
'fanart': fanart.TYPE.TV.BACKGROUND,
}
try:
indexerid = helpers.mapIndexersToShow(show)[1]
if indexerid:
request = Request(
request = fanartRequest(
apikey=sickbeard.FANART_API_KEY,
id=indexerid,
ws=fanart.WS.TV,
@ -1022,8 +1025,11 @@ class GenericMetadata():
)
resp = request.response()
return resp.values()[-1].values()[-2][-1]['url']
url = resp[types[type]][0]['url']
if thumb:
url = re.sub('/fanart/', '/preview/', url)
return url
except Exception as e:
pass
logger.log(u"Could not find any images on Fanart.tv for " + show.name, logger.DEBUG)
logger.log(u"Could not find any " + type + " images on Fanart.tv for " + show.name, logger.DEBUG)