Commit ab9883d7 authored by echel0n's avatar echel0n

Added imagetypes dict to image cache class

parent 2c3f10ca
......@@ -31,6 +31,22 @@ from sickrage.metadata import GenericMetadata
class ImageCache(object):
BANNER = 1
POSTER = 2
BANNER_THUMB = 3
POSTER_THUMB = 4
FANART = 5
FANART_THUMB = 6
IMAGE_TYPES = {
BANNER: 'banner',
POSTER: 'poster',
BANNER_THUMB: 'banner_thumb',
POSTER_THUMB: 'poster_thumb',
FANART: 'fanart',
FANART_THUMB: 'fanart_thumb'
}
def __init__(self):
hachoir_config.quiet = True
......@@ -149,13 +165,6 @@ class ImageCache(object):
sickrage.app.log.debug("Checking if file " + str(banner_thumb_path) + " exists")
return os.path.isfile(banner_thumb_path)
BANNER = 1
POSTER = 2
BANNER_THUMB = 3
POSTER_THUMB = 4
FANART = 5
FANART_THUMB = 6
def which_type(self, path):
"""
Analyzes the image provided and attempts to determine whether it is a poster or banner.
......@@ -238,30 +247,30 @@ class ImageCache(object):
# generate the path based on the type & indexer_id
if img_type == self.POSTER:
img_type_name = 'poster'
img_thumb = False
dest_path = self.poster_path(show_obj.indexer_id)
elif img_type == self.BANNER:
img_type_name = 'series'
img_thumb = False
dest_path = self.banner_path(show_obj.indexer_id)
elif img_type == self.FANART:
img_type_name = 'fanart'
img_thumb = False
dest_path = self.fanart_path(show_obj.indexer_id)
elif img_type == self.POSTER_THUMB:
img_type_name = 'poster_thumb'
img_thumb = True
dest_path = self.poster_thumb_path(show_obj.indexer_id)
elif img_type == self.BANNER_THUMB:
img_type_name = 'series_thumb'
img_thumb = True
dest_path = self.banner_thumb_path(show_obj.indexer_id)
elif img_type == self.FANART_THUMB:
img_type_name = 'fanart_thumb'
img_thumb = True
dest_path = self.fanart_thumb_path(show_obj.indexer_id)
else:
sickrage.app.log.error("Invalid cache image type: " + str(img_type))
sickrage.app.log.error("Invalid cache image type: {}".format(img_type))
return False
# retrieve the image from indexer using the generic metadata class
metadata_generator = GenericMetadata()
img_data = metadata_generator._retrieve_show_image(img_type_name, show_obj)
img_data = metadata_generator._retrieve_show_image(self.IMAGE_TYPES[img_type], img_thumb, show_obj)
result = metadata_generator._write_image(img_data, dest_path, force)
return result
......
......@@ -589,7 +589,7 @@ class GenericMetadata(object):
return True
def _retrieve_show_image(self, image_type, show_obj, which=0):
def _retrieve_show_image(self, image_type, image_thumb, show_obj, which=0):
"""
Gets an image URL from theTVDB.com and fanart.tv, downloads it and returns the data.
......@@ -603,6 +603,10 @@ class GenericMetadata(object):
image_data = None
indexer_lang = show_obj.lang or sickrage.app.config.indexer_default_language
if image_type not in ('fanart', 'poster', 'series', 'poster_thumb', 'series_thumb', 'fanart_thumb'):
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
......@@ -621,40 +625,16 @@ class GenericMetadata(object):
sickrage.app.log.debug("Indexer " + IndexerApi(show_obj.indexer).name + " maybe experiencing some problems. Try again later")
return None
if image_type not in ('fanart', 'poster', 'series', 'poster_thumb', 'series_thumb'):
sickrage.app.log.warning("Invalid image type " + str(image_type) + ", couldn't find it in the " + IndexerApi(show_obj.indexer).name + " object")
return
image_types = {
'poster_thumb': {
'indexer': lambda: t.images(show_obj.indexer_id, key_type='poster')[which]['thumbnail'],
'fanart': lambda: self._retrieve_show_images_from_fanart(show_obj, image_type, True)
},
'series_thumb': {
'indexer': lambda: t.images(show_obj.indexer_id, key_type='series')[which]['thumbnail'],
'fanart': lambda: self._retrieve_show_images_from_fanart(show_obj, image_type, True)
},
'fanart_thumb': {
'indexer': lambda: t.images(show_obj.indexer_id, key_type='fanart')[which]['thumbnail'],
'fanart': lambda: self._retrieve_show_images_from_fanart(show_obj, image_type, True)
},
'poster': {
'indexer': lambda: t.images(show_obj.indexer_id, key_type='poster')[which]['filename'],
'fanart': lambda: self._retrieve_show_images_from_fanart(show_obj, image_type)
},
'series': {
'indexer': lambda: t.images(show_obj.indexer_id, key_type='series')[which]['filename'],
'fanart': lambda: self._retrieve_show_images_from_fanart(show_obj, image_type)
},
'fanart': {
'indexer': lambda: t.images(show_obj.indexer_id, key_type='fanart')[which]['filename'],
'fanart': lambda: self._retrieve_show_images_from_fanart(show_obj, image_type)
'{}'.format(image_type): {
'indexer': lambda: t.images(show_obj.indexer_id, key_type=image_type.strip('_thumb'))[which][('filename', 'thumbnail')[image_thumb]],
'fanart': lambda: self._retrieve_show_images_from_fanart(show_obj, image_type.strip('_thumb'), image_thumb)
}
}
for func in ['indexer', 'fanart']:
for fname in ['indexer', 'fanart']:
try:
image_url = image_types[image_type][func]()
image_url = image_types[image_type][fname]()
if image_url:
image_data = self.get_show_image(image_url)
if image_data:
......@@ -795,8 +775,6 @@ class GenericMetadata(object):
types = {
'poster': fanart.TYPE.TV.POSTER,
'series': fanart.TYPE.TV.BANNER,
'poster_thumb': fanart.TYPE.TV.POSTER,
'series_thumb': fanart.TYPE.TV.BANNER,
'fanart': fanart.TYPE.TV.BACKGROUND,
}
......
Markdown is supported
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