def get_image_list(self, media_id): xml_url = self.url % (self.api_key, media_id) log('API: %s ' % xml_url) image_list = [] data = get_xml(xml_url) tree = ET.fromstring(data) for imagetype in self.imagetypes: imageroot = imagetype + 's' for images in tree.findall(imageroot): for image in images: info = {} info['id'] = image.get('id') info['url'] = urllib.quote(image.get('url'), ':/') info['preview'] = urllib.quote(image.get('preview'), ':/') info['type'] = imagetype info['language'] = image.get('lang') info['likes'] = image.get('likes') # Create Gui string to display info['generalinfo'] = 'Language: %s | Likes: %s ' % ( info['language'], info['likes']) if info: image_list.append(info) if image_list == []: raise NoFanartError(media_id) else: return image_list
def get_image_list(self, media_id): xml_url = self.url % (self.api_key,media_id) log('API: %s ' % xml_url) image_list = [] data = get_xml(xml_url) tree = ET.fromstring(data) for imagetype in self.imagetypes: imageroot = imagetype + 's' for images in tree.findall(imageroot): for image in images: info = {} info['id'] = image.get('id') info['url'] = urllib.quote(image.get('url'), ':/') info['preview'] = urllib.quote(image.get('preview'), ':/') info['type'] = imagetype info['language'] = image.get('lang') info['likes'] = image.get('likes') # Create Gui string to display info['generalinfo'] = '%s: %s | %s: %s ' %( __localize__(32141), info['language'], __localize__(32143), info['likes'] ) if info: image_list.append(info) if image_list == []: raise NoFanartError(media_id) else: return image_list
def get_items(self, url=None, category=None): # If no url is specified, return the root menu if url is None: return self.ROOT_MENU xml = utils.get_xml(url) items = [] # if the current url is a media stream if xml.find(".//httpLiveStreamingVideoAsset") is not None: items.append( self.get_stream_details( xml.find(".//httpLiveStreamingVideoAsset"))) # if no category is specified, find the categories or item collection elif category is None: # Prevent duplicates from collectionDividers with empty title tags. collections = [ elem for elem in xml.findall(".//collectionDivider") if elem.find("title").text ] # Show Categories if relevant if collections: items += self.generate_items( xml.findall(".//showcase") + collections, url) else: items += self.generate_items( xml.findall(".//twoLineMenuItem") + xml.findall(".//twoLineEnhancedMenuItem") + xml.findall(".//sixteenByNinePoster") + xml.findall(".//actionButton"), url, ) # if a category is specified, find the items for the specified category elif category is not None: if category in ("Featured", "Featured Events"): items += self.generate_items(xml.findall(".//showcasePoster")) else: collections = xml.iterfind(".//collectionDivider/../*") for collection in collections: if (collection.tag == "collectionDivider" and collection.get("accessibilityLabel") == category): elem = next(collections, None) # Skip end of page or closing collectionDividers if elem is None or elem.tag == "collectionDivider": continue items += self.generate_items( list(elem.find(".//items"))) return items
def get_image_list(self, media_id): #xml_url = self.url % (self.api_key,media_id) xml_url = self.url % (media_id) log('API: %s ' % xml_url) image_list = [] data = get_xml(xml_url) tree = ET.fromstring(data) for imagetype in self.imagetypes: imageroot = imagetype + 's' for images in tree.findall(imageroot): for image in images: info = {} info['id'] = image.get('id') info['url'] = urllib.quote(image.get('url'), ':/') info['preview'] = info['url'] info['type'] = [imagetype] info['rating'] = 'n/a' info['language'] = 'n/a' ''' info['preview'] = urllib.quote(image.get('preview'), ':/') info['language'] = image.get('lang') info['likes'] = image.get('likes') if imagetype == 'seasonthumb': seasonxx = "%.2d" % int(image.findtext('season')) #ouput is double digit int if seasonxx == '00': info['season'] = '-specials' else: info['season'] = str(seasonxx) info['season'] = "%.2d" % int(image.get('season')) #ouput is double digit int else: info['season'] = 'NA' info['generalinfo'] = 'Language: %s , Likes: %s ' %(info['language'], info['likes']) ''' # Create Gui string to display info['generalinfo'] = 'Language: %s | Rating: %s ' % ( info['language'], info['rating']) if info: image_list.append(info) if image_list == []: raise NoFanartError(media_id) else: return image_list
def get_items(self, url=None, category=None): # If no url is specified, return the root menu if url is None: return self.ROOT_MENU xml = utils.get_xml(url) items = [] # if the current url is a media stream if xml.find('.//httpLiveStreamingVideoAsset') is not None: items.append( self.get_stream_details( xml.find('.//httpLiveStreamingVideoAsset'))) # if no category is specified, find the categories or item collection elif category is None: data = { "collectionDividers": xml.findall('.//collectionDivider'), } # Show Categories if relevant if data["collectionDividers"]: items += self.generate_items( xml.findall('.//showcase') + data["collectionDividers"], url) else: items += self.generate_items( xml.findall('.//twoLineMenuItem') + xml.findall('.//twoLineEnhancedMenuItem') + xml.findall('.//sixteenByNinePoster') + xml.findall('.//actionButton'), url) # if a category is specified, find the items for the specified category elif category is not None: if category == 'Featured': items += self.generate_items(xml.findall('.//showcasePoster')) else: collections = xml.iterfind(".//collectionDivider/../*") for collection in collections: if collection.tag == 'collectionDivider' and collection.get( "accessibilityLabel") == category: items += self.generate_items( collections.next().find('.//items').getchildren()) return items
def get_image_list(self, media_id): #xml_url = self.url % (self.api_key,media_id) xml_url = self.url % (media_id) log('API: %s ' % xml_url) image_list = [] data = get_xml(xml_url) tree = ET.fromstring(data) for imagetype in self.imagetypes: imageroot = imagetype + 's' for images in tree.findall(imageroot): for image in images: info = {} info['id'] = image.get('id') info['url'] = urllib.quote(image.get('url'), ':/') info['preview'] = info['url'] info['type'] = [imagetype] info['rating'] = 'n/a' info['language'] = 'n/a' ''' info['preview'] = urllib.quote(image.get('preview'), ':/') info['language'] = image.get('lang') info['likes'] = image.get('likes') if imagetype == 'seasonthumb': seasonxx = "%.2d" % int(image.findtext('season')) #ouput is double digit int if seasonxx == '00': info['season'] = '-specials' else: info['season'] = str(seasonxx) info['season'] = "%.2d" % int(image.get('season')) #ouput is double digit int else: info['season'] = 'NA' info['generalinfo'] = 'Language: %s , Likes: %s ' %(info['language'], info['likes']) ''' # Create Gui string to display info['generalinfo'] = '%s: %s | %s: %s ' %( __localize__(32141), info['language'], __localize__(32142), info['rating']) if info: image_list.append(info) if image_list == []: raise NoFanartError(media_id) else: return image_list
def get_image_list(self, media_id): xml_url = self.url % (self.api_key, media_id) log("API: %s " % xml_url) image_list = [] data = get_xml(xml_url) tree = ET.fromstring(data) for image in tree.findall("Banner"): info = {} if image.findtext("BannerPath"): info["url"] = self.url_prefix + image.findtext("BannerPath") if image.findtext("ThumbnailPath"): info["preview"] = self.url_prefix + image.findtext("ThumbnailPath") else: info["preview"] = self.url_prefix + image.findtext("BannerPath") info["language"] = image.findtext("Language") info["id"] = image.findtext("id") # process fanarts if image.findtext("BannerType") == "fanart": info["type"] = ["fanart", "extrafanart"] # process posters elif image.findtext("BannerType") == "poster": info["type"] = ["poster"] # process banners elif image.findtext("BannerType") == "series" and image.findtext("BannerType2") == "graphical": info["type"] = ["banner"] # process seasonposters elif image.findtext("BannerType") == "season" and image.findtext("BannerType2") == "season": info["type"] = ["seasonposter"] # process seasonbanners elif image.findtext("BannerType") == "season" and image.findtext("BannerType2") == "seasonwide": info["type"] = ["seasonbanner"] else: info["type"] = [""] # convert image size ...x... in Bannertype2 if image.findtext("BannerType2"): try: x, y = image.findtext("BannerType2").split("x") info["width"] = int(x) info["height"] = int(y) except: info["type2"] = image.findtext("BannerType2") # check if fanart has text info["series_name"] = image.findtext("SeriesName") == "true" # find image ratings if image.findtext("RatingCount") and int(image.findtext("RatingCount")) >= 1: info["rating"] = float("%.1f" % float(image.findtext("Rating"))) # output string with one decimal else: info["rating"] = "n/a" # find season info if image.findtext("Season") != "": info["season"] = image.findtext("Season") # Create Gui string to display info["generalinfo"] = "Language: %s | Rating: %s | " % (info["language"], info["rating"]) if "season" in info: info["generalinfo"] += "Season: %s | " % (info["season"]) # info['generalinfo'] += 'Season: %s | ' %( info['season'].replace('-','') ) if "height" in info: info["generalinfo"] += "Size: %sx%s | " % (info["height"], info["width"]) if info: image_list.append(info) if image_list == []: raise NoFanartError(media_id) else: return image_list
def get_image_list(self, media_id): xml_url = self.url % (self.api_key, media_id) image_list = [] data = get_xml(xml_url) tree = ET.fromstring(data) for image in tree.findall('Banner'): info = {} if image.findtext('BannerPath'): info['url'] = self.url_prefix + image.findtext('BannerPath') if image.findtext('ThumbnailPath'): info['preview'] = self.url_prefix + image.findtext('ThumbnailPath') else: info['preview'] = self.url_prefix + image.findtext('BannerPath') info['language'] = image.findtext('Language') info['id'] = image.findtext('id') # process fanarts if image.findtext('BannerType') == 'fanart': info['type'] = ['fanart','extrafanart'] # process posters elif image.findtext('BannerType') == 'poster': info['type'] = ['poster'] # process banners elif image.findtext('BannerType') == 'series' and image.findtext('BannerType2') == 'graphical': info['type'] = ['banner'] # process seasonposters elif image.findtext('BannerType') == 'season' and image.findtext('BannerType2') == 'season': info['type'] = ['seasonposter'] # process seasonbanners elif image.findtext('BannerType') == 'season' and image.findtext('BannerType2') == 'seasonwide': info['type'] = ['seasonbanner'] else: info['type'] = [''] # convert image size ...x... in Bannertype2 if image.findtext('BannerType2'): try: x,y = image.findtext('BannerType2').split('x') info['width'] = int(x) info['height'] = int(y) except: info['type2'] = image.findtext('BannerType2') # check if fanart has text info['series_name'] = image.findtext('SeriesName') == 'true' # find image ratings if int(image.findtext('RatingCount')) >= 1: info['rating'] = float( "%.1f" % float( image.findtext('Rating')) ) #output string with one decimal info['votes'] = image.findtext('RatingCount') else: info['rating'] = 'n/a' info['votes'] = 'n/a' # find season info if image.findtext('Season'): info['season'] = image.findtext('Season') else: info['season'] = 'n/a' # Create Gui string to display info['generalinfo'] = '%s: %s | %s: %s | %s: %s | ' %( __localize__(32141), info['language'], __localize__(32142), info['rating'], __localize__(32143), info['votes'] ) if info['season'] != 'n/a': info['generalinfo'] += '%s: %s | ' %( __localize__(32144), info['season'] ) if 'height' in info: info['generalinfo'] += '%s: %sx%s | ' %( __localize__(32145), info['height'], info['width'] ) if info: image_list.append(info) if image_list == []: raise NoFanartError(media_id) else: # Sort the list before return. Last sort method is primary image_list = sorted(image_list, key=itemgetter('rating'), reverse=True) image_list = sorted(image_list, key=itemgetter('season')) image_list = sorted(image_list, key=itemgetter('language')) return image_list
def get_image_list(self, media_id): xml_url = self.url % (self.api_key, media_id) log('API: %s ' % xml_url) image_list = [] data = get_xml(xml_url) tree = ET.fromstring(data) for image in tree.findall('Banner'): info = {} if image.findtext('BannerPath'): info['url'] = self.url_prefix + image.findtext('BannerPath') if image.findtext('ThumbnailPath'): info['preview'] = self.url_prefix + image.findtext('ThumbnailPath') else: info['preview'] = self.url_prefix + image.findtext('BannerPath') info['language'] = image.findtext('Language') info['id'] = image.findtext('id') # process fanarts if image.findtext('BannerType') == 'fanart': info['type'] = ['fanart','extrafanart'] # process posters elif image.findtext('BannerType') == 'poster': info['type'] = ['poster'] # process banners elif image.findtext('BannerType') == 'series' and image.findtext('BannerType2') == 'graphical': info['type'] = ['banner'] # process seasonposters elif image.findtext('BannerType') == 'season' and image.findtext('BannerType2') == 'season': info['type'] = ['seasonposter'] # process seasonbanners elif image.findtext('BannerType') == 'season' and image.findtext('BannerType2') == 'seasonwide': info['type'] = ['seasonbanner'] else: info['type'] = [''] # convert image size ...x... in Bannertype2 if image.findtext('BannerType2'): try: x,y = image.findtext('BannerType2').split('x') info['width'] = int(x) info['height'] = int(y) except: info['type2'] = image.findtext('BannerType2') # check if fanart has text info['series_name'] = image.findtext('SeriesName') == 'true' # find image ratings if image.findtext('RatingCount') and int(image.findtext('RatingCount')) >= 1: info['rating'] = float( "%.1f" % float( image.findtext('Rating')) ) #output string with one decimal else: info['rating'] = 'n/a' # find season info if image.findtext('Season') != '': info['season'] = image.findtext('Season') # Create Gui string to display info['generalinfo'] = 'Language: %s | Rating: %s | ' %( info['language'], info['rating'] ) if 'season'in info: info['generalinfo'] += 'Season: %s | ' %( info['season'] ) #info['generalinfo'] += 'Season: %s | ' %( info['season'].replace('-','') ) if 'height' in info: info['generalinfo'] += 'Size: %sx%s | ' %( info['height'], info['width'] ) if info: image_list.append(info) if image_list == []: raise NoFanartError(media_id) else: return image_list