コード例 #1
0
    def create_folder_item(self, result_set):
        """ Creates a MediaItem of type 'folder' using the result_set from the regex.

        This method creates a new MediaItem from the Regular Expression or Json
        results <result_set>. The method should be implemented by derived classes
        and are specific to the channel.

        :param list[str]|dict[str,str] result_set: The result_set of the self.episodeItemRegex

        :return: A new MediaItem of type 'folder'.
        :rtype: MediaItem|None

        """

        if len(result_set) > 3 and result_set[3] != "":
            Logger.debug("Sub category folder found.")
            url = parse.urljoin(self.baseUrl, HtmlEntityHelper.convert_html_entities(result_set[3]))
            name = "\a.: %s :." % (result_set[4],)
            item = MediaItem(name, url)
            item.thumb = self.noImage
            item.complete = True
            item.type = "folder"
            return item

        url = parse.urljoin(self.baseUrl, HtmlEntityHelper.convert_html_entities(result_set[0]))
        name = HtmlEntityHelper.convert_html_entities(result_set[1])

        helper = HtmlHelper(result_set[2])
        description = helper.get_tag_content("div", {'class': 'description'})

        item = MediaItem(name, "%s/RSS" % (url,))
        item.thumb = self.noImage
        item.type = 'folder'
        item.description = description.strip()

        date = helper.get_tag_content("div", {'class': 'date'})
        if date == "":
            date = helper.get_tag_content("span", {'class': 'lastPublishedDate'})

        if not date == "":
            date_parts = Regexer.do_regex(r"(\w+) (\d+)[^<]+, (\d+)", date)
            if len(date_parts) > 0:
                date_parts = date_parts[0]
                month_part = date_parts[0].lower()
                day_part = date_parts[1]
                year_part = date_parts[2]

                try:
                    month = DateHelper.get_month_from_name(month_part, "en")
                    item.set_date(year_part, month, day_part)
                except:
                    Logger.error("Error matching month: %s", month_part, exc_info=True)

        item.complete = True
        return item
コード例 #2
0
    def create_single_video_item(self, result_set):
        """ Creates a MediaItem of type 'video' using the result_set from the regex.

        This method creates a new MediaItem from the Regular Expression or Json
        results <result_set>. The method should be implemented by derived classes
        and are specific to the channel.

        If the item is completely processed an no further data needs to be fetched
        the self.complete property should be set to True. If not set to True, the
        self.update_video_item method is called if the item is focussed or selected
        for playback.

        :param str result_set: The result_set of the self.episodeItemRegex

        :return: A new MediaItem of type 'video' or 'audio' (despite the method's name).
        :rtype: MediaItem|None

        """

        if self.__hasAlreadyVideoItems:
            # we already have items, so don't show this one, it will be a duplicate
            return None

        result_set = result_set.replace('\\x27', "'")

        json_data = JsonHelper(result_set)
        url = self.parentItem.url
        title = json_data.get_value("name")
        description = HtmlHelper.to_text(json_data.get_value("description"))
        item = MediaItem(title, url, type="video")
        item.description = description
        item.thumb = self.parentItem.thumb
        item.fanart = self.parentItem.fanart
        return item
コード例 #3
0
    def create_video_item(self, result_set):
        """ Creates a MediaItem of type 'video' using the result_set from the regex.

        This method creates a new MediaItem from the Regular Expression or Json
        results <result_set>. The method should be implemented by derived classes
        and are specific to the channel.

        If the item is completely processed an no further data needs to be fetched
        the self.complete property should be set to True. If not set to True, the
        self.update_video_item method is called if the item is focussed or selected
        for playback.

        :param list[str]|dict result_set: The result_set of the self.episodeItemRegex

        :return: A new MediaItem of type 'video' or 'audio' (despite the method's name).
        :rtype: MediaItem|None

        """

        Logger.trace(result_set)

        media_link = result_set.get("ipadLink")
        title = result_set.get("title")

        # it seems overkill, but not all items have a contentLink and of we set
        # the url to self.baseUrl it will be a duplicate item if the titles are
        # equal
        url = result_set.get("contentLink") or media_link or self.baseUrl
        if not url.startswith("http"):
            url = parse.urljoin(self.baseUrl, url)

        item = MediaItem(title, url)
        item.thumb = self.noImage

        if media_link:
            item.append_single_stream(media_link, self.channelBitrate)

        # get the thumbs from multiple locations
        thumb_urls = result_set.get("images", None)
        thumb_url = None
        if thumb_urls:
            # noinspection PyUnresolvedReferences
            thumb_url = \
                thumb_urls[0].get("fullScreenLink", None) or \
                thumb_urls[0].get("previewLink", None) or \
                result_set.get("imageLink", None)

        if thumb_url and not thumb_url.startswith("http"):
            thumb_url = parse.urljoin(self.baseUrl, thumb_url)

        item.thumb = self.noImage
        if thumb_url:
            item.thumb = thumb_url

        item.icon = self.icon
        item.type = 'video'

        item.description = HtmlHelper.to_text(result_set.get("text"))

        posix = result_set.get("timestamp", None)
        if posix:
            broadcast_date = DateHelper.get_date_from_posix(int(posix))
            item.set_date(broadcast_date.year, broadcast_date.month,
                          broadcast_date.day, broadcast_date.hour,
                          broadcast_date.minute, broadcast_date.second)

        item.complete = True
        return item
コード例 #4
0
    def CreateFolderItem(self, resultSet):
        """Creates a MediaItem of type 'folder' using the resultSet from the regex.

        Arguments:
        resultSet : tuple(strig) - the resultSet of the self.folderItemRegex

        Returns:
        A new MediaItem of type 'folder'

        This method creates a new MediaItem from the Regular Expression or Json
        results <resultSet>. The method should be implemented by derived classes
        and are specific to the channel.

        """

        if len(resultSet) > 3 and resultSet[3] != "":
            Logger.Debug("Sub category folder found.")
            url = urlparse.urljoin(
                self.baseUrl,
                HtmlEntityHelper.ConvertHTMLEntities(resultSet[3]))
            name = "\a.: %s :." % (resultSet[4], )
            item = mediaitem.MediaItem(name, url)
            item.thumb = self.noImage
            item.complete = True
            item.type = "folder"
            return item

        url = urlparse.urljoin(
            self.baseUrl, HtmlEntityHelper.ConvertHTMLEntities(resultSet[0]))
        name = HtmlEntityHelper.ConvertHTMLEntities(resultSet[1])

        helper = HtmlHelper(resultSet[2])
        description = helper.GetTagContent("div", {'class': 'description'})

        item = mediaitem.MediaItem(name, "%s/RSS" % (url, ))
        item.thumb = self.noImage
        item.type = 'folder'
        item.description = description.strip()

        date = helper.GetTagContent("div", {'class': 'date'})
        if date == "":
            date = helper.GetTagContent("span", {'class': 'lastPublishedDate'})

        if not date == "":
            dateParts = Regexer.DoRegex("(\w+) (\d+)[^<]+, (\d+)", date)
            if len(dateParts) > 0:
                dateParts = dateParts[0]
                monthPart = dateParts[0].lower()
                dayPart = dateParts[1]
                yearPart = dateParts[2]

                try:
                    month = DateHelper.GetMonthFromName(monthPart, "en")
                    item.SetDate(yearPart, month, dayPart)
                except:
                    Logger.Error("Error matching month: %s",
                                 monthPart,
                                 exc_info=True)

        item.complete = True
        return item