Пример #1
0
def related(plugin, video_id, pagetoken=None):
    """
    Search for all videos related to a giving video id.

    :param Route plugin: Tools related to Route callbacks.
    :param str video_id: Id of the video the fetch related video for.
    :param str pagetoken: [opt] The page token representing the next page of content.

    :returns: A generator of listitems.
    :rtype: :class:`types.GeneratorType`
    """
    gdata = APIControl()
    plugin.category = "Related"
    plugin.update_listing = bool(pagetoken)
    feed = gdata.api.search(pageToken=pagetoken, relatedToVideoId=video_id)
    video_list = [item[u"id"][u"videoId"]
                  for item in feed[u"items"]]  # pragma: no branch

    # List all the related videos
    results = list(gdata.videos(video_list, multi_channel=True))
    if u"nextPageToken" in feed:  # pragma: no branch
        next_item = Listitem.next_page(video_id=video_id,
                                       pagetoken=feed[u"nextPageToken"])
        results.append(next_item)

    # Close db
    gdata.close()
    return results
Пример #2
0
    def run(self, video_id, pagetoken=None):
        """
        Search for all videos related to a giving video id.

        :param video_id: Id of the video the fetch related video for.
        :type video_id: unicode

        :param pagetoken: [opt] The page token representing the next page of content.
        :type pagetoken: unicode

        :returns: A generator of listitems.
        :rtype: :class:`types.GeneratorType`
        """
        self.category = "Related"
        self.update_listing = bool(pagetoken)
        feed = self.api.search(pageToken=pagetoken, relatedToVideoId=video_id)
        video_list = [item[u"id"][u"videoId"]
                      for item in feed[u"items"]]  # pragma: no branch

        # List all the related videos
        results = list(self.videos(video_list, multi_channel=True))
        if u"nextPageToken" in feed:  # pragma: no branch
            next_item = Listitem.next_page(video_id=video_id,
                                           pagetoken=feed[u"nextPageToken"])
            results.append(next_item)
        return results
Пример #3
0
def playlist(plugin,
             contentid,
             pagetoken=None,
             enable_playlists=True,
             loop=False):
    """
    List all videos within youtube playlist

    :param Route plugin: Tools related to Route callbacks.
    :param str contentid: Channel id or playlist id to list videos for.
    :param str pagetoken: [opt] The page token representing the next page of content.
    :param bool enable_playlists: [opt] Set to True to enable linking to channel playlists. (default => False)
    :param bool loop: [opt] Return all the videos within playlist. (Default => False)

    :returns: A generator of listitems.
    :rtype: :class:`types.GeneratorType`
    """
    gdata = APIControl()

    # Fetch channel uploads uuid
    playlist_id = gdata.valid_playlistid(contentid)

    # Request data feed
    feed = gdata.api.playlist_items(playlist_id, pagetoken, loop)
    channel_list = set()
    video_list = []

    # Fetch video ids for all public videos
    for item in feed[u"items"]:
        if u"status" in item and item[u"status"][
                u"privacyStatus"] in EXCEPTED_STATUS:  # pragma: no branch
            channel_list.add(item[u"snippet"][u"channelId"])
            video_list.append(item[u"snippet"][u"resourceId"][u"videoId"])
        else:  # pragma: no cover
            logger.debug("Skipping non plublic video: '%s'",
                         item[u"snippet"][u"resourceId"][u"videoId"])

    # Return the list of video listitems
    results = list(
        gdata.videos(video_list, multi_channel=len(channel_list) > 1))
    if u"nextPageToken" in feed:
        next_item = Listitem.next_page(contentid=contentid,
                                       pagetoken=feed[u"nextPageToken"])
        results.append(next_item)

    # Add playlists item to results
    if enable_playlists and contentid.startswith("UC") and pagetoken is None:
        item = Listitem()
        item.label = u"[B]%s[/B]" % plugin.localize(PLAYLISTS)
        item.info["plot"] = plugin.localize(PLAYLISTS_PLOT)
        item.art["icon"] = "DefaultVideoPlaylists.png"
        item.art.global_thumb("playlist.png")
        item.set_callback(playlists, channel_id=contentid, show_all=False)
        results.append(item)

    # Close db
    gdata.close()
    return results
Пример #4
0
    def run(self, contentid, pagetoken=None, enable_playlists=True, loop=False):
        """
        List all video within youtube playlist

        :param contentid: Channel id or playlist id to list videos for.
        :type contentid: unicode

        :param pagetoken: [opt] The page token representing the next page of content.
        :type pagetoken: unicode

        :param enable_playlists: [opt] Set to True to enable linking to channel playlists. (default => False)
        :type enable_playlists: bool

        :param loop: [opt] Return all the videos within playlist. (Default => False)
        :type loop: bool

        :returns: A generator of listitems.
        :rtype: :class:`types.GeneratorType`
        """
        # Fetch channel uploads uuid
        playlist_id = self.valid_playlistid(contentid)

        # Request data feed
        feed = self.api.playlist_items(playlist_id, pagetoken, loop)
        channel_list = set()
        video_list = []

        # Fetch video ids for all public videos
        for item in feed[u"items"]:
            if item[u"status"][u"privacyStatus"] == u"public":
                channel_list.add(item[u"snippet"][u"channelId"])
                video_list.append(item[u"snippet"][u"resourceId"][u"videoId"])
            else:
                logger.debug("Skipping non plublic video: '%s'", item[u"snippet"][u"resourceId"][u"videoId"])

        # Return the list of video listitems
        results = list(self.videos(video_list, multi_channel=len(channel_list) > 1))
        if u"nextPageToken" in feed:
            next_item = Listitem.next_page(contentid=contentid, pagetoken=feed[u"nextPageToken"])
            results.append(next_item)

        # Add playlists item to results
        if enable_playlists and contentid.startswith("UC") and pagetoken is None:
            item = Listitem()
            item.label = u"[B]%s[/B]" % self.localize(PLAYLISTS)
            item.info["plot"] = "Show all channel playlists."
            item.art["icon"] = "DefaultVideoPlaylists.png"
            item.art.global_thumb("playlist.png")
            item.set_callback(Playlists, channel_id=contentid, show_all=False)
            results.append(item)

        return results
Пример #5
0
    def run(self, contentid, pagetoken=None, enable_playlists=True, loop=False):
        """
        List all video within youtube playlist

        :param str contentid: Channel id or playlist id to list videos for.
        :param str pagetoken: [opt] The page token representing the next page of content.
        :param bool enable_playlists: [opt] Set to True to enable linking to channel playlists. (default => False)
        :param bool loop: [opt] Return all the videos within playlist. (Default => False)

        :returns: A generator of listitems.
        :rtype: :class:`types.GeneratorType`
        """
        # Fetch channel uploads uuid
        playlist_id = self.valid_playlistid(contentid)

        # Request data feed
        feed = self.api.playlist_items(playlist_id, pagetoken, loop)
        channel_list = set()
        video_list = []

        # Fetch video ids for all public videos
        for item in feed[u"items"]:
            if u"status" in item and item[u"status"][u"privacyStatus"] in EXCEPTED_STATUS:  # pragma: no branch
                channel_list.add(item[u"snippet"][u"channelId"])
                video_list.append(item[u"snippet"][u"resourceId"][u"videoId"])
            else:  # pragma: no cover
                logger.debug("Skipping non plublic video: '%s'", item[u"snippet"][u"resourceId"][u"videoId"])

        # Return the list of video listitems
        results = list(self.videos(video_list, multi_channel=len(channel_list) > 1))
        if u"nextPageToken" in feed:
            next_item = Listitem.next_page(contentid=contentid, pagetoken=feed[u"nextPageToken"])
            results.append(next_item)

        # Add playlists item to results
        if enable_playlists and contentid.startswith("UC") and pagetoken is None:
            item = Listitem()
            item.label = u"[B]%s[/B]" % self.localize(PLAYLISTS)
            item.info["plot"] = self.localize(PLAYLISTS_PLOT)
            item.art["icon"] = "DefaultVideoPlaylists.png"
            item.art.global_thumb("playlist.png")
            item.set_callback(Playlists, channel_id=contentid, show_all=False)
            results.append(item)

        return results
Пример #6
0
    def run(self, video_id, pagetoken=None):
        """
        Search for all videos related to a giving video id.

        :param str video_id: Id of the video the fetch related video for.
        :param str pagetoken: [opt] The page token representing the next page of content.

        :returns: A generator of listitems.
        :rtype: :class:`types.GeneratorType`
        """
        self.category = "Related"
        self.update_listing = bool(pagetoken)
        feed = self.api.search(pageToken=pagetoken, relatedToVideoId=video_id)
        video_list = [item[u"id"][u"videoId"] for item in feed[u"items"]]  # pragma: no branch

        # List all the related videos
        results = list(self.videos(video_list, multi_channel=True))
        if u"nextPageToken" in feed:  # pragma: no branch
            next_item = Listitem.next_page(video_id=video_id, pagetoken=feed[u"nextPageToken"])
            results.append(next_item)
        return results
Пример #7
0
    def run(self, channel_id, show_all=True, pagetoken=None, loop=False):
        """
        List all playlist for giving channel

        :param str channel_id: Channel id to list playlists for.
        :param bool show_all: [opt] Add link to all of the channels videos if True. (default => True)
        :param str pagetoken: [opt] The token for the next page of results.
        :param bool loop: [opt] Return all the playlist for channel. (Default => False)

        :returns: A generator of listitems.
        :rtype: :class:`types.GeneratorType`
        """
        # Make sure that we have a valid channel id
        if not channel_id.startswith("UC"):
            raise ValueError("channel_id is not valid: %s" % channel_id)

        # Fetch fanart image for channel
        fanart = self.db.cur.execute("SELECT fanart FROM channels WHERE channel_id = ?", (channel_id,)).fetchone()
        if fanart:  # pragma: no branch
            fanart = fanart[0]

        # Fetch channel playlists feed
        feed = self.api.playlists(channel_id, pagetoken, loop)

        # Add next Page entry if pagetoken is found
        if u"nextPageToken" in feed:  # pragma: no branch
            yield Listitem.next_page(channel_id=channel_id, show_all=False, pagetoken=feed[u"nextPageToken"])

        # Display a link for listing all channel videos
        # This is usefull when the root of a addon is the playlist directory
        if show_all:
            title = bold(self.localize(ALLVIDEOS))
            yield Listitem.youtube(channel_id, title, enable_playlists=False)

        # Loop Entries
        for playlist_item in feed[u"items"]:
            # Create listitem object
            item = Listitem()

            # Check if there is actualy items in the playlist before listing
            item_count = playlist_item[u"contentDetails"][u"itemCount"]
            if item_count == 0:  # pragma: no cover
                continue

            # Fetch video snippet
            snippet = playlist_item[u"snippet"]

            # Set label
            item.label = u"%s (%s)" % (snippet[u"localized"][u"title"], item_count)

            # Fetch Image Url
            item.art["thumb"] = snippet[u"thumbnails"][u"medium"][u"url"]

            # Set Fanart
            item.art["fanart"] = fanart

            # Fetch Possible Plot and Check if Available
            item.info["plot"] = snippet[u"localized"][u"description"]

            # Add InfoLabels and Data to Processed List
            item.set_callback(Playlist, contentid=playlist_item[u"id"], enable_playlists=False)
            yield item
Пример #8
0
def playlists(plugin, channel_id, show_all=True, pagetoken=None, loop=False):
    """
    List all playlist for giving channel

    :param Route plugin: Tools related to Route callbacks.
    :param str channel_id: Channel id to list playlists for.
    :param bool show_all: [opt] Add link to all of the channels videos if True. (default => True)
    :param str pagetoken: [opt] The token for the next page of results.
    :param bool loop: [opt] Return all the playlist for channel. (Default => False)

    :returns: A generator of listitems.
    :rtype: :class:`types.GeneratorType`
    """
    gdata = APIControl()

    # Make sure that we have a valid channel id
    if not channel_id.startswith("UC"):
        raise ValueError("channel_id is not valid: %s" % channel_id)

    # Fetch fanart image for channel
    fanart = gdata.db.cur.execute(
        "SELECT fanart FROM channels WHERE channel_id = ?",
        (channel_id, )).fetchone()
    if fanart:  # pragma: no branch
        fanart = fanart[0]

    # Fetch channel playlists feed
    feed = gdata.api.playlists(channel_id, pagetoken, loop)

    # Add next Page entry if pagetoken is found
    if u"nextPageToken" in feed:  # pragma: no branch
        yield Listitem.next_page(channel_id=channel_id,
                                 show_all=False,
                                 pagetoken=feed[u"nextPageToken"])

    # Display a link for listing all channel videos
    # This is usefull when the root of a addon is the playlist directory
    if show_all:
        title = bold(plugin.localize(ALLVIDEOS))
        yield Listitem.youtube(channel_id, title, enable_playlists=False)

    # Loop Entries
    for playlist_item in feed[u"items"]:
        # Create listitem object
        item = Listitem()

        # Check if there is actualy items in the playlist before listing
        item_count = playlist_item[u"contentDetails"][u"itemCount"]
        if item_count == 0:  # pragma: no cover
            continue

        # Fetch video snippet
        snippet = playlist_item[u"snippet"]

        # Set label
        item.label = u"%s (%s)" % (snippet[u"localized"][u"title"], item_count)

        # Fetch Image Url
        item.art["thumb"] = snippet[u"thumbnails"][u"medium"][u"url"]

        # Set Fanart
        item.art["fanart"] = fanart

        # Fetch Possible Plot and Check if Available
        item.info["plot"] = snippet[u"localized"][u"description"]

        # Add InfoLabels and Data to Processed List
        item.set_callback(playlist,
                          contentid=playlist_item[u"id"],
                          enable_playlists=False)
        yield item

    # Close db
    gdata.close()