def getThumb(url, tvdbId=None):
    """
	Try to find a better thumb than the one provided via url.
	The thumb data returned is either an URL or the image data itself.
	"""
    ret = None
    if (tvdbId is not None and Prefs['fanart'] is True):
        thumb = fanartScrapper.getRandImageOfTypes(tvdbId, ['tvthumbs'])
        if thumb is None: thumb = url
        url = thumb

    if url == R(CRUNCHYROLL_ICON):
        ret = url
    else:
        if url is not None:
            try:
                data = HTTP.Request(url, cacheTime=CACHE_1WEEK).content
                if url.endswith(".jpg"):
                    ret = DataObject(data, 'image/jpeg')
                elif url.endswith(".png"):
                    ret = DataObject(data, 'image/png')
            except Exception, arg:
                Log.Error("#####Thumbnail couldn't be retrieved:")
                Log.Error("#####" + repr(Exception) + repr(arg) + url)
                ret = None
def getThumbUrl(url, tvdbId=None):
    """
	just get the best url instead of the image data itself.
	this can help 'larger thumbs missing' issue
	"""
    if (tvdbId is not None and Prefs['fanart'] is True):
        thumb = fanartScrapper.getRandImageOfTypes(tvdbId, ['tvthumbs'])
        if thumb is not None: return thumb

    if url == R(CRUNCHYROLL_ICON):
        return url

    return url
def selectArt(url,tvdbId=None):
	ret = None
	if (tvdbId is not None and Prefs['fanart'] is True):
		art = fanartScrapper.getRandImageOfTypes(tvdbId,['clearlogos','cleararts'])
		if art is None: art = url
		url=art
	if url==R(CRUNCHYROLL_ART):
		ret = url
	else:
		if url is not None:
			ret = url
		else:
			ret = R(CRUNCHYROLL_ART)
	#Log.Debug("art: %s"%ret)
	return url#ret
def selectArt(url, tvdbId=None):
    ret = None
    if (tvdbId is not None and Prefs['fanart'] is True):
        art = fanartScrapper.getRandImageOfTypes(tvdbId,
                                                 ['clearlogos', 'cleararts'])
        if art is None: art = url
        url = art
    if url == R(CRUNCHYROLL_ART):
        ret = url
    else:
        if url is not None:
            ret = url
        else:
            ret = R(CRUNCHYROLL_ART)
    #Log.Debug("art: %s"%ret)
    return url  #ret
def getThumb(url,tvdbId=None):
	ret = None
	if (tvdbId is not None and Prefs['fanart'] is True):
		thumb = fanartScrapper.getRandImageOfTypes(tvdbId,['tvthumbs'])
		if thumb is None: thumb = url
		url=thumb
	if url==R(CRUNCHYROLL_ICON):
		ret = url
	else:
		if url is not None:
			try:
				data = HTTP.Request(url, cacheTime=CACHE_1WEEK).content
				if url.endswith(".jpg"):
					ret = DataObject(data, 'image/jpeg')
				elif url.endswith(".png"):
					ret = DataObject(data, 'image/png')
			except: pass
	if ret is None:
		return R(CRUNCHYROLL_ICON)
	else:
		return ret
def getArt(url, tvdbId=None):
    ret = None
    if (tvdbId is not None and Prefs['fanart'] is True):
        art = fanartScrapper.getRandImageOfTypes(tvdbId,
                                                 ['clearlogos', 'cleararts'])
        if art is None: art = url
        url = art
    if url == R(CRUNCHYROLL_ART) or url is None or url is "":
        req = urllib2.Request("http://127.0.0.1:32400" + R(CRUNCHYROLL_ART))
        ret = DataObject(urllib2.urlopen(req).read(), 'image/jpeg')
    else:
        try:
            #Log.Debug("url: %s"%url)
            data = HTTP.Request(url, cacheTime=CACHE_1WEEK).content
            if url.endswith(".jpg"):
                ret = DataObject(data, 'image/jpeg')
            elif url.endswith(".png"):
                ret = DataObject(data, 'image/png')
        except Exception, arg:
            Log.Error("####Exception when grabbing art at '%s'" % url)
            Log.Error(repr(Exception) + repr(arg))
def getArt(url,tvdbId=None):
	ret = None
	if (tvdbId is not None and Prefs['fanart'] is True):
		art = fanartScrapper.getRandImageOfTypes(tvdbId,['clearlogos','cleararts'])
		if art is None: art = url
		url=art
	if url==R(CRUNCHYROLL_ART) or url is None or url is "":
		req = urllib2.Request("http://127.0.0.1:32400"+R(CRUNCHYROLL_ART))
		ret = DataObject(urllib2.urlopen(req).read(), 'image/jpeg')
	else:
		try:
			#Log.Debug("url: %s"%url)
			data = HTTP.Request(url, cacheTime=CACHE_1WEEK).content
			if url.endswith(".jpg"):
				ret = DataObject(data, 'image/jpeg')
			elif url.endswith(".png"):
				ret = DataObject(data, 'image/png')
		except: pass
	if ret is None:
		req = urllib2.Request("http://127.0.0.1:32400"+R(CRUNCHYROLL_ART))
		return DataObject(urllib2.urlopen(req).read(), 'image/jpeg')
	else:
		return ret