コード例 #1
0
    def __html_entity_converter(entity):
        """Substitutes an HTML entity with the correct character

        :param re.MatchObject entity: Value of the HTML entity without the '&'

        :rtype: str
        :return: Replaces &#xx where 'x' is single digit, or &...; where '.' is a
        character into the real character. That character is returned.

        """

        # Logger.Debug("1:%s, 2:%s", entity.group(1), entity.group(2))
        try:
            if entity.group(1) == "#":
                # Logger.Trace("%s: %s", entity.group(2), chr(int(entity.group(2))))
                return unichr(int(entity.group(2), 10))

            elif entity.group(1) == "#x":
                # check for hex values
                return unichr(int(entity.group(2), 16))

            elif entity.group(2) == 'apos':
                # this one is not covert in name2codepoint
                return "'"

            else:
                # Logger.Trace("%s: %s", entity.group(2), htmldefs.name2codepoint[entity.group(2)])
                return unichr(htmldefs.name2codepoint[entity.group(2)])
        except:
            Logger.error("Error converting HTMLEntities: &%s%s", entity.group(1), entity.group(2), exc_info=True)
            return '&%s%s;' % (entity.group(1), entity.group(2))
コード例 #2
0
    def get_external_add_on_label(add_on_url):
        """ Returns the formatting string for the label of an item with an external add-on url

        :param str add_on_url:   The plugin://-handle for the add-on
        
        :return: the name of the add-on or None if not installed
        :rtype: str

        """

        if add_on_url is None:
            return "{}"

        # We need the add-on ID
        add_on_id = add_on_url.split("/", 3)[2]
        add_on_label = XbmcWrapper.__add_on_name_lookup.get(add_on_id)
        if add_on_label is not None:
            return add_on_label

        try:
            add_on_name = xbmcaddon.Addon(add_on_id).getAddonInfo('name')
            via = LanguageHelper.get_localized_string(
                LanguageHelper.OtherAddon)
        except:
            add_on_name = add_on_id
            via = LanguageHelper.get_localized_string(
                LanguageHelper.MissingAddon)

        add_on_label = "{0} [COLOR gold]{1} '{2}'[/COLOR]".format(
            unichr(187), via, add_on_name)
        XbmcWrapper.__add_on_name_lookup[add_on_id] = add_on_label
        return add_on_label
コード例 #3
0
    def __special_chars_handler(match):
        """ Helper method to replace \\uXXXX with unichr(int(hex))

        :param re.Match match:  The matched element in which group(2) holds the
                                hex value.

        :return: Returns the Unicode character corresponding to the Hex value.
        :rtype: chr

        """

        hex_string = "0x%s" % (match.group(2))
        hex_value = int(hex_string, 16)
        return unichr(hex_value)
コード例 #4
0
    def get_kodi_item(self):
        """ Creates an Kodi ListItem object for this channel
        
        :return: a Kodi ListItem with all required properties set.
        :rtype: xbmcgui.ListItem

        """

        name = HtmlEntityHelper.convert_html_entities(self.channelName)
        description = HtmlEntityHelper.convert_html_entities(
            self.channelDescription)

        if self.uses_external_addon:
            other = LanguageHelper.get_localized_string(
                LanguageHelper.OtherAddon)
            name = "{0} {1} [COLOR gold]{2}[/COLOR]".format(
                name, unichr(187), other)

        self.icon = self.__get_image_path(self.icon)
        item = xbmcgui.ListItem(name, description)
        item.setArt({'thumb': self.icon, 'icon': self.icon})

        # http://mirrors.kodi.tv/docs/python-docs/14.x-helix/xbmcgui.html#ListItem-setInfo
        item.setInfo(
            "video",
            {
                "Title": name,
                # "Count": self.sortOrderPerCountry,
                # "TrackNumber": self.sortOrder,
                "Genre": LanguageHelper.get_full_language(self.language),
                # "Tagline": description,
                "Plot": description
            })

        if AddonSettings.hide_fanart():
            return item

        if self.fanart is not None:
            self.fanart = self.__get_image_path(self.fanart)
        else:
            self.fanart = os.path.join(Config.rootDir, "fanart.jpg")
        item.setArt({'fanart': self.fanart})
        return item
コード例 #5
0
    def __keep_handler(exc):
        """Sometimes the unicode decoding fails due to strange UTF-8 chars in
        string that should not be there. This method just converts the chars
        in the string to Unicode chars and then returns the as their unicode
        chars.

        Arguments:
        exc : UnicodeDecodeError - Excpetion thrown by Decode.


        Returns the same as the input but then Unicode:
        'Barnen p\xe5 Luna p\xe5 Svt.se' returns u'Barnen p\xe5 Luna p\xe5 Svt.se'

        """

        try:
            return_value = u''
            for c in exc.object[exc.start:exc.end]:
                # just convert each character as if it was Unicode to it's Unicode equivalent.
                return_value = u'%s%s' % (return_value, unichr(ord(c)))
        except:
            return_value = exc.object[exc.start:exc.end].decode(exc.encoding, 'replace')
        return return_value, exc.end
コード例 #6
0
    def get_kodi_item(self, name=None):
        """Creates a Kodi item with the same data is the MediaItem.

        This item is used for displaying purposes only and changes to it will
        not be passed on to the MediaItem.

        :param str|unicode name:    Overwrites the name of the Kodi item.

        :return: a complete Kodi ListItem
        :rtype: xbmcgui.ListItem

        """

        # Update name and descriptions
        name_post_fix, description_post_fix = self.__update_title_and_description_with_limitations(
        )

        name = self.__get_title(name)
        name = "%s%s" % (name, name_post_fix)
        name = self.__full_decode_text(name)

        if self.uses_external_addon:
            other = LanguageHelper.get_localized_string(
                LanguageHelper.OtherAddon)
            name = "{0} {1} [COLOR gold]{2}[/COLOR]".format(
                name, unichr(187), other)

        if self.description is None:
            self.description = ''

        description = "%s%s" % (self.description.lstrip(),
                                description_post_fix)
        description = self.__full_decode_text(description)
        if description is None:
            description = ""

        # the Kodi ListItem date
        # date: string (%d.%m.%Y / 01.01.2009) - file date
        if self.__timestamp > datetime.datetime.min:
            kodi_date = self.__timestamp.strftime("%d.%m.%Y")
            kodi_year = self.__timestamp.year
        else:
            kodi_date = ""
            kodi_year = 0

        # Get all the info labels starting with the ones set and then add the specific ones
        info_labels = self.__infoLabels.copy()
        info_labels["Title"] = name
        if kodi_date:
            info_labels["Date"] = kodi_date
            info_labels["Year"] = kodi_year
        if self.type != "audio":
            info_labels["Plot"] = description

        # now create the Kodi item
        item = xbmcgui.ListItem(name or "<unknown>", self.__date)
        item.setLabel(name)
        item.setLabel2(self.__date)

        # set a flag to indicate it is a item that can be used with setResolveUrl.
        if self.is_playable():
            Logger.trace("Setting IsPlayable to True")
            item.setProperty("IsPlayable", "true")

        # specific items
        Logger.trace("Setting InfoLabels: %s", info_labels)
        if self.type == "audio":
            item.setInfo(type="music", infoLabels=info_labels)
        else:
            item.setInfo(type="video", infoLabels=info_labels)

        # now set all the art to prevent duplicate calls to Kodi
        if self.fanart and not AddonSettings.hide_fanart():
            item.setArt({
                'thumb': self.thumb,
                'icon': self.icon,
                'fanart': self.fanart
            })
        else:
            item.setArt({'thumb': self.thumb, 'icon': self.icon})

        # Set Artwork
        # art = dict()
        # for l in ("thumb", "poster", "banner", "fanart", "clearart", "clearlogo", "landscape"):
        #     art[l] = self.thumb
        # item.setArt(art)

        # We never set the content resolving, Retrospect does this. And if we do, then the custom
        # headers are removed from the URL when opening the resolved URL.
        try:
            item.setContentLookup(False)
        except:
            # apparently not yet supported on this Kodi version3
            pass
        return item