Coverage for resources/lib/ItemHelper.py : 62%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# -*- coding: utf-8 -*- # Module: ItemHelper # Author: asciidisco # Created on: 24.07.2017 # License: MIT https://goo.gl/WA1kby
"""Interface for matching API data with the Kodi item interface"""
""" Injects instances
:param constants: Constants instance :type constants: resources.lib.Constants :param utils: Utils instance :type utils: resources.lib.Utils """
""" Generates an item description
:param item: Item to be described :type item: dict :returns: string -- Item description """
""" Sets art for the given item
:param list_item: Kodi list item :type list_item: xbmcgui.ListItem :param sport: Chosen sport :type sport: string :param item: Item to set art for :type item: dict :returns: xbmcgui.ListItem -- Kodi list item """ sports = self.constants.get_sports_list() base_url = self.constants.get_base_url() list_item = self.__get_sports_art( list_item=list_item, sport=sport, sports=sports) if item is not None: metatdata = item.get('metadata', {}) if item.get('images'): images = item.get('images', {}) list_item = self.__get_editorial_art( list_item=list_item, base_url=base_url, images=images) if metatdata.get('images'): images = metatdata.get('images') list_item = self.__get_editorial_art( list_item=list_item, base_url=base_url, images=images) return list_item
""" Builds the data for an Kodi folder item
:param target_url: Plugin target url :type target_url: string :param details: EPG element details :type details: dict :param match_time: Events match time :type match_time: string :param shorts: Add shorts desc :type shorts: dict :returns: dict -- List item info properties """ return { 'hash': self.utils.generate_hash(target_url), 'url': self.constants.get_base_url() + target_url, 'title': self.build_epg_title( details=details, match_time=match_time), 'shorts': shorts, }
""" Generates an title for an item
:param item: Item to be described :type item: dict :returns: string -- Item title """ details = metadata.get('details') home = details.get('home', {}) name_full = home.get('name_full') if name_full is not None: title += self.__build_match_title_full(details=details) elif name_full is None and home.get('name_short') is not None: title += self.__build_match_title_short(details=details)
""" Sets editorial art for the given item
:param list_item: Kodi list item :type list_item: xbmcgui.ListItem :param base_url: Image base url :type base_url: string :param images: Map of usable images :type images: dict :returns: xbmcgui.ListItem -- Kodi list item """ image = '' if images.get('fallback'): image = base_url + '/' + images.get('fallback') if images.get('editorial'): image = base_url + '/' + images.get('editorial') if image != '': try: list_item.setArt({ 'poster': image, 'landscape': image, 'thumb': image, 'fanart': image }) except RuntimeError: self.utils.log('`setArt` not available') return list_item
""" Sets editorial art for static sport item
:param list_item: Kodi list item :type list_item: xbmcgui.ListItem :param sport: Chosen sport :type sport: string :param sports: Map of available sports :type sports: dict :returns: xbmcgui.ListItem -- Kodi list item """ try: list_item.setArt({ 'poster': sports.get(sport).get('fanart'), 'landscape': sports.get(sport).get('fanart'), 'thumb': sports.get(sport).get('image'), 'fanart': sports.get(sport).get('fanart') }) except RuntimeError: self.utils.log('`setArt` not available') return list_item
def __build_fallback_title(cls, title, metadata): """ Generates a fallback title
:param title: Original title :type title: string :param metadata: Item metadata :type metadata: dict :returns: string -- Fallback title """
def __build_match_title_short(cls, details): """ Generates a short match title
:param details: Item details :type details: dict :returns: string -- Match title (short) """
def __build_match_title_full(cls, details): """ Generates a long match title
:param details: Item details :type details: dict :returns: string -- Match title (long) """
def build_epg_title(cls, details, match_time): """ Generates a epg title
:param details: Item details :type details: dict :param match_time: Events match time :type match_time: string :returns: string -- EPG item title """
""" Generates a homan readable time from an items UTC timestamp
:param metadata: Item metadata :type metadata: dict :param details: Item details :type details: dict :returns: tuple -- Match date & match time """ |