Пример #1
0
    def list_terms(self, extras):
        """
        List all saved searches.

        :returns: A generator of listitems.
        :rtype: :class:`types.GeneratorType`
        """
        # Add listitem for adding new search terms
        search_item = Listitem()
        search_item.label = u"[B]%s[/B]" % self.localize(SEARCH)
        search_item.set_callback(self, search=True, **extras)
        search_item.art.global_thumb("search_new.png")
        yield search_item

        # Set the callback function to the route that was given
        callback_params = extras.copy()
        callback = dispatcher[callback_params.pop("route")].callback

        # Prefetch the localized string for the context menu lable
        str_remove = self.localize(REMOVE)

        # List all saved searches
        for search_term in self.search_db:
            item = Listitem()
            item.label = search_term.title()

            # Creatre Context Menu item for removing search term
            item.context.container(str_remove, self, remove=search_term, **extras)

            # Update params with full url and set the callback
            item.params.update(callback_params, search_query=search_term)
            item.set_callback(callback)
            yield item

        self.search_db.close()
Пример #2
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
Пример #3
0
def list_terms(plugin, searchdb, extras):
    """
    List all saved searches.

    :param Route plugin: Tools related to Route callbacks.
    :param Search searchdb: Search DB
    :param dict extras: Extra parameters that will be farwarded on to the context.container.

    :returns: A generator of listitems.
    :rtype: :class:`types.GeneratorType`
    """
    # Add listitem for adding new search terms
    search_item = Listitem()
    search_item.label = u"[B]%s[/B]" % plugin.localize(SEARCH)
    search_item.set_callback(saved_searches, search=True, **extras)
    search_item.art.global_thumb("search_new.png")
    yield search_item

    # Set the callback function to the route that was given
    callback_params = extras.copy()
    route = callback_params.pop("_route")
    callback = dispatcher.get_route(route).callback

    # Prefetch the localized string for the context menu lable
    str_remove = plugin.localize(REMOVE)

    # List all saved searches
    for search_term in searchdb:
        item = Listitem()
        item.label = search_term.title()

        # Creatre Context Menu item for removing search term
        item.context.container(saved_searches,
                               str_remove,
                               remove_entry=search_term,
                               **extras)

        # Update params with full url and set the callback
        item.params.update(callback_params, search_query=search_term)
        item.set_callback(callback)
        yield item
Пример #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 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()
Пример #6
0
    def videos(self, video_ids, multi_channel=False):
        """
        Process VideoIDs and return listitems in a generator

        :param video_ids: List of all the videos to show.
        :param bool multi_channel: [opt] Set to True to enable linking to channel playlists. (default => False)

        :returns: A generator of listitems.
        :rtype: :class:`types.GeneratorType`
        """
        # Check that the quality setting is set to HD or greater
        try:
            ishd = self.setting.get_int("video_quality",
                                        addon_id="script.module.youtube.dl")
        except RuntimeError:  # pragma: no cover
            ishd = True

        # Process videos
        for video_data in self.request_videos(video_ids):
            # Create listitem object
            item = Listitem()

            # Fetch Title
            item.label = video_data["title"]

            # Add channel Fanart
            item.art["fanart"] = video_data["fanart"]

            # Fetch video Image url
            item.art["thumb"] = video_data["thumb"]

            # Fetch Description
            item.info["plot"] = u"[B]%s[/B]\n\n%s" % (
                video_data["channel_title"], video_data["description"])

            # Fetch Studio
            item.info["studio"] = video_data["channel_title"]

            # Fetch Viewcount
            if video_data["count"]:
                item.info["count"] = video_data["count"]

            # Fetch Possible Date
            date = video_data["date"]
            item.info.date(date[:date.find(u"T")], "%Y-%m-%d")

            # Fetch Category
            item.info["genre"] = video_data["genre"]

            # Set Quality and Audio Overlays
            item.stream.hd(bool(ishd and video_data["hd"]))

            # Set duration
            item.info["duration"] = video_data["duration"]

            # Add Context item to link to related videos
            item.context.related(related, video_id=video_data["video_id"])

            # Add Context item for youtube channel if videos from more than one channel are ben listed
            if multi_channel:
                item.context.container(playlist,
                                       u"Go to: %s" %
                                       video_data["channel_title"],
                                       contentid=video_data["channel_id"])

            # Return the listitem
            item.set_callback(play_video, video_id=video_data["video_id"])
            yield item