コード例 #1
0
    def create_search_program_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)

        title = result_set["Title"]
        # Not used: uuid = result_set["Uuid"]
        abstract_key = result_set["AbstractKey"]
        url = "http://www.rtl.nl/system/s4m/vfd/version=1/d=pc/output=json/fun=getseasons/ak={}".format(
            abstract_key)
        item = MediaItem(title, url)

        time_stamp = result_set["LastBroadcastDate"]  # =1546268400000
        date_time = DateHelper.get_date_from_posix(int(time_stamp) / 1000)
        item.set_date(date_time.year, date_time.month, date_time.day,
                      date_time.hour, date_time.minute, date_time.second)

        return item
コード例 #2
0
    def create_episode_item_json(self, result_set):
        """ Creates a new MediaItem for an episode.

        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

        """

        time_stamp = result_set["created"]
        if time_stamp <= 1420070400:
            # older items don't have videos for now
            return None

        url = "https://at5news.vinsontv.com/api/news?source=web&externalid={}".format(
            result_set["externalId"])
        item = MediaItem(result_set["title"], url)
        item.complete = True
        item.description = result_set.get("text")

        date_time = DateHelper.get_date_from_posix(time_stamp)
        item.set_date(date_time.year, date_time.month, date_time.day)

        # noinspection PyTypeChecker
        image_data = result_set.get("media", [])
        for image in image_data:
            item.thumb = image.get("imageHigh", image["image"])
        return item
コード例 #3
0
    def create_live_channel(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[str,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

        """

        Logger.trace(result_set)

        item = MediaItem(result_set[0], result_set[1])
        item.type = "video"
        item.isGeoLocked = result_set[3].lower() == "true"

        date_time = DateHelper.get_date_from_posix(int(result_set[2]) * 1 / 1000)
        item.set_date(date_time.year, date_time.month, date_time.day, date_time.hour, date_time.minute,
                      date_time.second)

        thumb = result_set[4]
        if not thumb.startswith("http"):
            thumb = "%s%s" % (self.baseUrl, thumb)
        item.thumb = thumb

        return item
コード例 #4
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 dict[str,dict|None] 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)

        title = result_set["title"]
        if "subTitle" in result_set:
            title = "%s - %s" % (title, result_set["subTitle"])
        mgid = result_set["id"].split(":")[-1]
        url = "http://feeds.mtvnservices.com/od/feed/intl-mrss-player-feed" \
              "?mgid=mgid:arc:episode:mtvplay.com:%s" \
              "&ep=%s" \
              "&episodeType=segmented" \
              "&imageEp=android.playplex.mtv.%s" \
              "&arcEp=android.playplex.mtv.%s" \
              % (mgid, self.__backgroundServiceEp, self.__region.lower(), self.__region.lower())

        item = MediaItem(title, url)
        item.type = "video"
        item.description = result_set.get("description", None)
        item.isGeoLocked = True
        images = result_set.get("images", [])
        if images:
            # mgid:file:gsp:scenic:/international/mtv.nl/playplex/dutch-ridiculousness/Dutch_Ridiculousness_Landscape.png
            # http://playplex.mtvnimages.com/uri/mgid:file:gsp:scenic:/international/mtv.nl/playplex/dutch-ridiculousness/Dutch_Ridiculousness_Landscape.png
            for image in images:
                if image["width"] > 500:
                    pass  # no fanart here
                else:
                    item.thumb = "http://playplex.mtvnimages.com/uri/%(url)s" % image

        date = result_set.get("originalAirDate", None)
        if not date:
            date = result_set.get("originalPublishDate", None)
        if date:
            time_stamp = date["timestamp"]
            date_time = DateHelper.get_date_from_posix(time_stamp)
            item.set_date(date_time.year, date_time.month, date_time.day,
                          date_time.hour, date_time.minute, date_time.second)

        return item
コード例 #5
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 dict[str,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)

        is_serie_title = result_set["seriesTitle"]
        if not is_serie_title:
            return None

        if result_set["mediaType"] == "game":
            return None
        elif result_set["mediaType"] == "episode":
            title = "%(title)s (Episode)" % result_set
        else:
            title = result_set["title"]

        video_id = result_set["id"]
        url = "http://media.mtvnservices.com/pmt/e1/access/index.html?uri=mgid:%s:%s&configtype=edge" \
              % (self.__mgid, video_id, )

        item = MediaItem(title, url)
        item.description = result_set.get("description", None)
        item.type = "video"
        item.icon = self.icon
        item.fanart = self.fanart
        item.HttpHeaders = self.httpHeaders
        item.complete = False

        if "datePosted" in result_set:
            date = DateHelper.get_date_from_posix(
                float(result_set["datePosted"]["unixOffset"]) / 1000)
            item.set_date(date.year, date.month, date.day, date.hour,
                          date.minute, date.second)

        if "images" in result_set:
            images = result_set.get("images", {})
            thumbs = images.get("thumbnail", {})
            item.thumb = thumbs.get("r16-9", self.noImage)

        return item
コード例 #6
0
    def create_api_episode_type(self, result_set):
        """ Creates a new MediaItem for an episode.

        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 dict result_set: The result_set of the self.episodeItemRegex

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

        """

        # This URL gives the URL that contains the show info with Season ID's
        url = "https://graph.kijk.nl/graphql-video"

        if not result_set.get("sources"):
            return None

        title = result_set["title"]
        season_number = result_set.get("seasonNumber")
        episode_number = result_set.get("tvSeasonEpisodeNumber")

        title_format = self.parentItem.metaData.get("title_format",
                                                    "s{0:02d}e{1:02d} - {2}")
        if title is None:
            serie_title = result_set["series"]["title"]
            title = title_format.format(season_number, episode_number,
                                        serie_title)
        elif season_number is not None and episode_number is not None:
            title = title_format.format(season_number, episode_number, title)

        item = MediaItem(title, url, type="video")
        item.description = result_set.get("longDescription",
                                          result_set.get("description"))
        item.set_info_label("duration",
                            int(result_set.get("duration", 0) or 0))
        item.set_info_label("genre", result_set.get("displayGenre"))
        self.__get_artwork(item, result_set.get("imageMedia"), mode="thumb")

        updated = result_set["lastPubDate"] / 1000
        date_time = DateHelper.get_date_from_posix(updated)
        item.set_date(date_time.year, date_time.month, date_time.day,
                      date_time.hour, date_time.minute, date_time.second)

        # Find the media streams
        item.metaData["sources"] = result_set["sources"]
        item.metaData["subtitles"] = result_set.get("tracks", [])

        # DRM only
        no_drm_items = [src for src in result_set["sources"] if not src["drm"]]
        item.isDrmProtected = len(no_drm_items) == 0
        return item
コード例 #7
0
    def create_api_movie_type(self, result_set):
        """ Creates a new MediaItem for an program.

        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 dict result_set: The result_set of the self.episodeItemRegex

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

        """

        title = result_set["title"]
        if title is None:
            return None

        url = self.__get_api_persisted_url(
            "programs",
            "b6f65688f7e1fbe22aae20816d24ca5dcea8c86c8e72d80b462a345b5b70fa41",
            variables={
                "programTypes": "MOVIE",
                "guid": result_set["guid"]
            })

        item = MediaItem(result_set["title"], url)
        item.description = result_set.get("description")
        item.type = "video"
        item.set_info_label("duration",
                            int(result_set.get("duration", 0) or 0))
        item.set_info_label("genre", result_set.get("displayGenre"))
        self.__get_artwork(item, result_set.get("imageMedia"))

        time_stamp = result_set["epgDate"] / 1000
        date_stamp = DateHelper.get_date_from_posix(time_stamp,
                                                    tz=self.__timezone_utc)
        date_stamp = date_stamp.astimezone(self.__timezone)
        if date_stamp > datetime.datetime.now(tz=self.__timezone):
            available = LanguageHelper.get_localized_string(
                LanguageHelper.AvailableFrom)
            item.name = "{} - [COLOR=gold]{} {:%Y-%m-%d}[/COLOR]".format(
                title, available, date_stamp)
        item.set_date(date_stamp.year, date_stamp.month, date_stamp.day)

        # In the main list we should set the fanart too
        if self.parentItem is None:
            item.fanart = item.thumb

        sources = result_set.get("sources")
        item.metaData["sources"] = sources
        subs = result_set.get("tracks")
        item.metaData["subtitles"] = subs
        return item
コード例 #8
0
    def create_video_item_json(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 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)

        # get the title
        title = result_set["title"]
        mgid = result_set["id"]

        url = "http://media.mtvnservices.com/pmt/e1/access/index.html" \
              "?uri=mgid:arc:video:{}:{}&configtype=edge".format(self.__country_id, mgid)

        item = MediaItem(title, url)
        item.type = "video"
        item.description = result_set["description"]

        if "images" in result_set:
            item.thumb = result_set["images"]["url"]

        air_date = int(result_set["publishDate"])
        date_stamp = DateHelper.get_date_from_posix(air_date, self.__timezone_utc)
        item.set_date(date_stamp.year, date_stamp.month, date_stamp.day)

        episode = result_set.get("episode")
        season = result_set.get("season")
        if season and episode:
            item.set_season_info(season, episode)

        duration = result_set.get("duration", "0:00")
        duration = duration.split(":")
        duration = int(duration[1]) + 60 * int(duration[0])
        item.set_info_label("duration", duration)

        # store season info
        item.metaData["season_id"] = result_set.get("seasonId")
        item.isGeoLocked = True
        return item
コード例 #9
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 dict[str,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)

        title = result_set["title"]
        if title is None:
            Logger.warning("Found item with all <null> items. Skipping")
            return None

        if "subtitle" in result_set and result_set['subtitle'].lower(
        ) not in title.lower():
            title = "%(title)s - %(subtitle)s" % result_set

        url = "http://m.schooltv.nl/api/v1/afleveringen/%(mid)s.json" % result_set
        item = MediaItem(title, url)
        item.description = result_set.get("description", "")
        age_groups = result_set.get('ageGroups', ['Onbekend'])
        item.description = "%s\n\nLeeftijden: %s" % (item.description,
                                                     ", ".join(age_groups))

        item.thumb = result_set.get("image", "")
        item.icon = self.icon
        item.type = 'video'
        item.fanart = self.fanart
        item.complete = False
        item.set_info_label("duration", result_set['duration'])

        if "publicationDate" in result_set:
            broadcast_date = DateHelper.get_date_from_posix(
                int(result_set['publicationDate']))
            item.set_date(broadcast_date.year, broadcast_date.month,
                          broadcast_date.day, broadcast_date.hour,
                          broadcast_date.minute, broadcast_date.second)
        return item
コード例 #10
0
    def create_video_item_json(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 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)

        image_data = result_set.get("media", [])
        thumb = None
        url = None
        for image in image_data:
            thumb = image.get("imageHigh", image["image"])
            url = image.get("url")

        item = MediaItem(result_set["title"], url)
        item.type = "video"
        item.icon = self.icon
        item.thumb = thumb or self.noImage
        item.complete = True
        item.description = result_set.get("text")
        part = item.create_new_empty_media_part()
        M3u8.update_part_with_m3u8_streams(part,
                                           url,
                                           proxy=self.proxy,
                                           channel=self)

        # Let's not do the time now
        time_stamp = result_set["created"]
        date_time = DateHelper.get_date_from_posix(time_stamp)
        item.set_date(date_time.year, date_time.month, date_time.day,
                      date_time.hour, date_time.minute, date_time.second)
        return item
コード例 #11
0
    def create_episode_item_json(self, result_set):
        """ Creates a new MediaItem for an episode.

        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 result_set: The result_set of the self.episodeItemRegex

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

        """

        Logger.trace(result_set)

        time_stamp = result_set["created"]
        if time_stamp <= 1420070400:
            # older items don't have videos for now
            return None

        url = "{}/api/article/{}".format(self.baseUrl,
                                         result_set["externalId"])
        item = MediaItem(result_set["title"], url)
        item.description = HtmlHelper.to_text(result_set.get("text"))

        date_time = DateHelper.get_date_from_posix(time_stamp)
        item.set_date(date_time.year, date_time.month, date_time.day)

        # noinspection PyTypeChecker
        image_data = result_set.get("media", [])
        video_url = None
        for image in image_data:
            item.thumb = image.get("imageHigh", image.get("image"))
            video_url = image.get("url")

        # In some cases the main list only has videos
        if result_set.get("video", False):
            if video_url is None:
                return None

            item.type = "video"
            item.url = video_url

        return item
コード例 #12
0
    def create_clip_item_json(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 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)

        # get the title
        title = result_set["title"]
        mgid = result_set["id"]

        url = "https://media-utils.mtvnservices.com/services/MediaGenerator/" \
              "mgid:arc:video:{}:{}" \
              "?arcStage=live&format=json&acceptMethods=hls&clang=nl" \
              "&https=true".format(self.__country_id, mgid)

        item = MediaItem(title, url)
        item.type = "video"

        if "images" in result_set:
            item.thumb = result_set["images"]["url"]

        if "airDate" not in result_set:
            return item

        air_date = int(result_set["airDate"])
        date_stamp = DateHelper.get_date_from_posix(air_date, self.__timezone_utc)
        item.set_date(date_stamp.year, date_stamp.month, date_stamp.day)

        return item
コード例 #13
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[str,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.__no_clips:
            return None

        item = chn_class.Channel.create_video_item(self, result_set)

        # All of vier.be video's seem GEO locked.
        item.isGeoLocked = True

        # Set the correct url
        # videoId = resultSet["videoid"]
        # item.url = "https://api.viervijfzes.be/content/%s" % (videoId, )
        time_stamp = result_set.get("timestamp")
        if time_stamp:
            date_time = DateHelper.get_date_from_posix(
                int(result_set["timestamp"]))
            item.set_date(date_time.year, date_time.month, date_time.day,
                          date_time.hour, date_time.minute, date_time.second)

        if not item.thumb and "thumburl2" in result_set and result_set[
                "thumburl2"]:
            item.thumb = result_set["thumburl2"]

        if item.thumb and item.thumb != self.noImage:
            item.thumb = HtmlEntityHelper.strip_amp(item.thumb)
        return item
コード例 #14
0
    def __set_date(self, result_set, item):
        if "usageRights" in result_set and "availableFrom" in result_set["usageRights"] \
                and result_set["usageRights"]["availableFrom"] is not None:
            Logger.trace("Using 'usageRights.availableFrom' for date")
            # availableFrom=/Date(1540612800000+0200)/
            epoch_stamp = result_set["usageRights"]["availableFrom"][6:16]
            available_from = DateHelper.get_date_from_posix(int(epoch_stamp))
            item.set_date(available_from.year, available_from.month, available_from.day)

        elif "episodeNumberOrDate" in result_set and result_set["episodeNumberOrDate"] is not None:
            Logger.trace("Using 'episodeNumberOrDate' for date")
            date_parts = result_set["episodeNumberOrDate"].split(".")
            if len(date_parts) == 3:
                item.set_date(date_parts[2], date_parts[1], date_parts[0])

        elif "programUrlMetadata" in result_set and result_set["programUrlMetadata"] is not None:
            Logger.trace("Using 'programUrlMetadata' for date")
            date_parts = result_set["programUrlMetadata"].split("-")
            if len(date_parts) == 3:
                item.set_date(date_parts[2], date_parts[1], date_parts[0])
        return
コード例 #15
0
    def create_video_item_api(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[str,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

        """

        # Could be: title = result_set['episodeTitle']
        title = result_set['title']
        url = "https://api.viervijfzes.be/content/{}".format(
            result_set['videoUuid'])
        item = MediaItem(title, url)
        item.type = "video"
        item.description = HtmlHelper.to_text(
            result_set.get("description").replace(">\r\n", ">"))
        item.thumb = result_set["image"]
        item.isGeoLocked = result_set.get("isProtected")

        date_time = DateHelper.get_date_from_posix(result_set["createdDate"])
        item.set_date(date_time.year, date_time.month, date_time.day,
                      date_time.hour, date_time.minute, date_time.second)

        item.set_info_label("duration", result_set["duration"])
        if "epsiodeNumber" in result_set and "seasonNumber" in result_set:
            item.set_season_info(result_set["seasonNumber"],
                                 result_set["epsiodeNumber"])
        return item
コード例 #16
0
    def create_episode_item(self, result_set):
        """ Creates a new MediaItem for an episode.

        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

        """

        Logger.trace(result_set)
        title = result_set.get("title")

        if not title:
            return None

        link = result_set.get("feedLink")
        if not link.startswith("http"):
            link = parse.urljoin(self.baseUrl, link)

        item = MediaItem(title, link)
        item.thumb = result_set.get("image")
        item.description = result_set.get("text")
        if item.description is not None:
            item.description = item.description.replace("<br>", "\n")
        item.complete = True

        timestamp = result_set.get("timestamp")
        if timestamp is not None:
            date_time = DateHelper.get_date_from_posix(result_set["timestamp"])
            item.set_date(date_time.year, date_time.month, date_time.day,
                          date_time.hour, date_time.minute, date_time.second)

        return item
コード例 #17
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)

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

        item = MediaItem(title, media_link)
        item.thumb = result_set.get("image", result_set.get("imageLink"))
        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.set_info_label("duration", result_set.get("duration", 0))
        return item
コード例 #18
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)

        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)

        if thumb_url:
            item.thumb = thumb_url

        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
コード例 #19
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)

        episode_key = result_set["episode_key"]
        if episode_key:
            episode_data = self.episodes.get(episode_key, None)
            if not episode_data:
                Logger.warning("Could not find episodes data for key: %s",
                               episode_key)
                return None
            Logger.debug("Found Episode Data: %s", episode_data)
        else:
            Logger.debug("No Episode Data Found")
            episode_data = None

        title = result_set["title"]
        description = None
        if episode_data:
            if title:
                title = "%s - %s" % (episode_data["name"], title)
            else:
                title = episode_data["name"]
            description = episode_data.get("synopsis", None)

        # tarifs have datetimes
        # noinspection PyStatementEffect
        # """
        #             "ddr_timeframes": [{
        #                     "start": 1382119200,
        #                     "stop": 1382378399,
        #                     "tariff": 149
        #                 },
        #                 {
        #                     "start": 1382378400,
        #                     "tariff": 0
        #                 }],
        #
        #         """

        tariffs = result_set.get("ddr_timeframes")
        premium_item = False
        if tariffs:
            Logger.trace(tariffs)
            for tariff in tariffs:  # type: dict
                if tariff["tariff"] > 0:
                    start = tariff.get("start", 0)
                    end = tariff.get("stop", 2147483647)
                    start = DateHelper.get_date_from_posix(start)
                    end = DateHelper.get_date_from_posix(end)
                    now = datetime.datetime.now()
                    if start < now < end:
                        premium_item = True
                        Logger.debug(
                            "Found a tariff for this episode: %s - %s: %s",
                            start, end, tariff["tariff"])
                        break

        uuid = result_set["uuid"]
        url = "http://www.rtl.nl/system/s4m/xldata/ux/%s?context=rtlxl&d=pc&fmt=adaptive&version=3" % (
            uuid, )
        # The JSON urls do not yet work
        # url = "http://www.rtl.nl/system/s4m/vfd/version=1/d=pc/output=json/fun=abstract/uuid=%s/fmt=smooth" % (uuid,)

        item = MediaItem(title.title(), url)
        item.type = "video"
        item.isPaid = premium_item
        item.description = description
        item.thumb = "%s%s" % (
            self.posterBase,
            uuid,
        )

        station = result_set.get("station", None)
        if station:
            icon = self.largeIconSet.get(station.lower(), None)
            if icon:
                Logger.trace("Setting icon to: %s", icon)
                item.icon = icon

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

        return item
コード例 #20
0
    def log_on(self):
        """ Logs on to a website, using an url.

        First checks if the channel requires log on. If so and it's not already
        logged on, it should handle the log on. That part should be implemented
        by the specific channel.

        More arguments can be passed on, but must be handled by custom code.

        After a successful log on the self.loggedOn property is set to True and
        True is returned.

        :return: indication if the login was successful.
        :rtype: bool

        """

        api_key = "3_qhEcPa5JGFROVwu5SWKqJ4mVOIkwlFNMSKwzPDAh8QZOtHqu6L4nD5Q7lk0eXOOG"

        # Do we still have a valid short living token (1 hour)? If so, we have an active session.
        short_login_cookie = UriHandler.get_cookie("X-VRT-Token", ".vrt.be")
        if short_login_cookie is not None:
            # The old X-VRT-Token expired after 1 year. We don't want that old cookie
            short_login_cookie_can_live_too_long = \
                DateHelper.get_date_from_posix(short_login_cookie.expires) > datetime.datetime.now() + datetime.timedelta(hours=4)
            if not short_login_cookie_can_live_too_long:
                Logger.debug("Using existing VRT.be session.")
                return True

        # Do we still have a valid long living token? If so, try to extend the session. We need the
        # original UIDSignature value for that. The 'vrtlogin-rt' and all other related cookies
        # are valid for a same period (1 year).
        long_login_cookie = UriHandler.get_cookie("vrtlogin-rt", ".vrt.be")
        if long_login_cookie is not None:
            # if we stored a valid user signature, we can use it, together with the 'gmid' and
            # 'ucid' cookies to extend the session and get new token data
            data = UriHandler.open("https://token.vrt.be/refreshtoken", proxy=self.proxy, no_cache=True)
            if "vrtnutoken" in data:
                Logger.debug("Refreshed the VRT.be session.")
                return True

        Logger.warning("Failed to extend the VRT.be session.")
        username = self._get_setting("username")
        if not username:
            Logger.warning("No username configured for VRT.nu")
            return None

        v = Vault()
        password = v.get_channel_setting(self.guid, "password")
        if not password:
            Logger.warning("Found empty password for VRT user")

        # Get a 'gmid' and 'ucid' cookie by logging in. Valid for 10 years
        Logger.debug("Using: %s / %s", username, "*" * len(password))
        url = "https://accounts.vrt.be/accounts.login"
        data = {
            "loginID": username,
            "password": password,
            "sessionExpiration": "-1",
            "targetEnv": "jssdk",
            "include": "profile,data,emails,subscriptions,preferences,",
            "includeUserInfo": "true",
            "loginMode": "standard",
            "lang": "nl-inf",
            "APIKey": api_key,
            "source": "showScreenSet",
            "sdk": "js_latest",
            "authMode": "cookie",
            "format": "json"
        }
        logon_data = UriHandler.open(url, data=data, proxy=self.proxy, no_cache=True)
        user_id, signature, signature_time_stamp = self.__extract_session_data(logon_data)
        if user_id is None or signature is None or signature_time_stamp is None:
            return False

        # We need to initialize the token retrieval which will redirect to the actual token
        UriHandler.open("https://token.vrt.be/vrtnuinitlogin?provider=site&destination=https://www.vrt.be/vrtnu/",
                        proxy=self.proxy, no_cache=True)

        # Now get the actual VRT tokens (X-VRT-Token....). Valid for 1 hour. So we call the actual
        # perform_login url which will redirect and get cookies.
        csrf = UriHandler.get_cookie("OIDCXSRF", "login.vrt.be")
        if csrf is None:
            csrf = UriHandler.get_cookie("XSRF-TOKEN", "login.vrt.be")

        token_data = {
            "UID": user_id,
            "UIDSignature": signature,
            "signatureTimestamp": signature_time_stamp,
            "client_id": "vrtnu-site",
            "submit": "submit",
            "_csrf": csrf.value
        }
        UriHandler.open("https://login.vrt.be/perform_login", proxy=self.proxy, data=token_data, no_cache=True)
        return True