'Gets an image URL from theTVDB.com and TMDB.com, downloads it and returns the data.
image_type: type of image to retrieve (currently supported: fanart, poster, banner)
show_obj: a TVShow object to use when searching for the image
which: optional, a specific numbered poster to look for
Returns: the binary image data if available, or else None'

def _retrieve_show_image(self, image_type, show_obj, which=None):

    image_url = None
    indexer_lang = show_obj.lang
    try:
        lINDEXER_API_PARMS = sickbeard.indexerApi(show_obj.indexer).api_params.copy()
        lINDEXER_API_PARMS[u'banners'] = True
        lINDEXER_API_PARMS[u'language'] = (indexer_lang or sickbeard.INDEXER_DEFAULT_LANGUAGE)
        if show_obj.dvdorder:
            lINDEXER_API_PARMS[u'dvdorder'] = True
        t = sickbeard.indexerApi(show_obj.indexer).indexer(**lINDEXER_API_PARMS)
        indexer_show_obj = t[show_obj.indexerid]
    except (sickbeard.indexer_error, IOError) as e:
        logger.log((((u'Unable    to    look    up    show    on    ' + sickbeard.indexerApi(show_obj.indexer).name) + u',    not    downloading    images:    ') + ex(e)), logger.WARNING)
        logger.log(u'{0}    may    be    experiencing    some    problems.    Try    again    later.'.format(sickbeard.indexerApi(show_obj.indexer).name), logger.DEBUG)
        return None
    if (image_type not in (u'fanart', u'poster', u'banner', u'poster_thumb', u'banner_thumb')):
        logger.log(((((u'Invalid    image    type    ' + str(image_type)) + u",    couldn't    find    it    in    the    ") + sickbeard.indexerApi(show_obj.indexer).name) + u'    object'), logger.ERROR)
        return None
    if (image_type == u'poster_thumb'):
        if getattr(indexer_show_obj, u'poster', None):
            image_url = re.sub(u'posters', u'_cache/posters', indexer_show_obj[u'poster'])
        if (not image_url):
            image_url = self._retrieve_show_images_from_fanart(show_obj, image_type)
        if (not image_url):
            image_url = self._retrieve_show_images_from_tmdb(show_obj, image_type)
    elif (image_type == u'banner_thumb'):
        if getattr(indexer_show_obj, u'banner', None):
            image_url = re.sub(u'graphical', u'_cache/graphical', indexer_show_obj[u'banner'])
        if (not image_url):
            image_url = self._retrieve_show_images_from_fanart(show_obj, image_type)
    else:
        if getattr(indexer_show_obj, image_type, None):
            image_url = indexer_show_obj[image_type]
        if (not image_url):
            image_url = self._retrieve_show_images_from_fanart(show_obj, image_type)
        if (not image_url):
            image_url = self._retrieve_show_images_from_tmdb(show_obj, image_type)
    if image_url:
        image_data = metadata_helpers.getShowImage(image_url, which)
        return image_data
    return None
