def next_page(cls, *args, **kwargs): """ Constructor for adding link to "Next Page" of content. The current running "callback" will be called with all of the parameters that are given here. You can also specify which "callback" will be called by setting a keywork only argument called 'callback'. :param args: "Positional" arguments that will be passed to the callback. :param kwargs: "Keyword" arguments that will be passed to the callback. :example: >>> item = Listitem() >>> item.next_page(url="http://example.com/videos?page2") """ # Current running callback callback = dispatcher.get_route().callback callback = kwargs.pop("callback", callback) # Add support params to callback params kwargs["_updatelisting_"] = True if u"_nextpagecount_" in dispatcher.params else False kwargs["_title_"] = dispatcher.params.get(u"_title_", u"") kwargs["_nextpagecount_"] = dispatcher.params.get(u"_nextpagecount_", 1) + 1 # Create listitem instance item = cls() label = u"%s %i" % (Script.localize(NEXT_PAGE), kwargs["_nextpagecount_"]) item.info["plot"] = Script.localize(NEXT_PAGE_PLOT) item.label = bold(label) item.art.global_thumb("next.png") item.set_callback(callback, *args, **kwargs) return item
def next_page(cls, *args, **kwargs): """ Constructor for adding link to "Next Page" of content. By default the current running "callback" will be called with all of the parameters that are given here. You can specify which "callback" will be called by setting a keyword only argument called 'callback'. :param args: "Positional" arguments that will be passed to the callback. :param kwargs: "Keyword" arguments that will be passed to the callback. :example: >>> item = Listitem() >>> item.next_page(url="http://example.com/videos?page2") """ # Current running callback callback = kwargs.pop( "callback") if "callback" in kwargs else dispatcher.get_route( ).callback # Add support params to callback params kwargs[ "_updatelisting_"] = True if u"_nextpagecount_" in dispatcher.params else False kwargs["_title_"] = dispatcher.params.get(u"_title_", u"") kwargs["_nextpagecount_"] = dispatcher.params.get( u"_nextpagecount_", 1) + 1 # Create listitem instance item = cls() label = u"%s %i" % (Script.localize(NEXT_PAGE), kwargs["_nextpagecount_"]) item.info["plot"] = Script.localize(NEXT_PAGE_PLOT) item.label = bold(label) item.art.global_thumb("next.png") item.set_callback(callback, *args, **kwargs) return item
def search(cls, callback, *args, **kwargs): """ Constructor to add "saved search" support to add-on. This will first link to a "sub" folder that lists all saved "search terms". From here, "search terms" can be created or removed. When a selection is made, the "callback" function that was given will be executed with all parameters forwarded on. Except with one extra parameter, ``search_query``, which is the "search term" that was selected. :param Callback callback: Function that will be called when the "listitem" is activated. :param args: "Positional" arguments that will be passed to the callback. :param kwargs: "Keyword" arguments that will be passed to the callback. """ if hasattr(callback, "route"): route = callback.route elif isinstance(callback, CallbackRef): route = callback else: route = dispatcher.get_route(callback) kwargs["first_load"] = True kwargs["_route"] = route.path item = cls() item.label = bold(Script.localize(SEARCH)) item.art.global_thumb("search.png") item.info["plot"] = Script.localize(SEARCH_PLOT) item.set_callback(Route.ref("/codequick/search:saved_searches"), *args, **kwargs) return item
def search(cls, callback, *args, **kwargs): """ Constructor to add "saved search" support to add-on. This will first link to a "sub" folder that lists all saved "search terms". From here, "search terms" can be created or removed. When a selection is made, the "callback" function that was given will be executed with all parameters forwarded on. Except with one extra parameter, ``search_query``, which is the "search term" that was selected. :param callback: Function that will be called when the "listitem" is activated. :param args: "Positional" arguments that will be passed to the callback. :param kwargs: "Keyword" arguments that will be passed to the callback. :raises ValueError: If the given "callback" function does not have a ``search_query`` parameter. """ # Check that callback function has required parameter(search_query) if "search_query" not in callback.route.arg_names(): raise ValueError("callback function is missing required argument: 'search_query'") if args: # Convert positional arguments to keyword arguments callback.route.args_to_kwargs(args, kwargs) item = cls() item.label = bold(Script.localize(SEARCH)) item.art.global_thumb("search.png") item.info["plot"] = Script.localize(SEARCH_PLOT) item.set_callback(SavedSearches, _route=callback.route.path, first_load=True, **kwargs) return item
def search(cls, callback, *args, **kwargs): """ Constructor to add "saved search" support to add-on. This will first link to a "sub" folder that lists all saved "search terms". From here, "search terms" can be created or removed. When a selection is made, the "callback" function that was given will be executed with all parameters forwarded on. Except with one extra parameter, ``search_query``, which is the "search term" that was selected. :param callback: Function that will be called when the "listitem" is activated. :param args: "Positional" arguments that will be passed to the callback. :param kwargs: "Keyword" arguments that will be passed to the callback. :raises ValueError: If the given "callback" function does not have a ``search_query`` parameter. """ # Check that callback function has required parameter(search_query) if "search_query" not in callback.route.arg_names(): raise ValueError( "callback function is missing required argument: 'search_query'" ) if args: # Convert positional arguments to keyword arguments callback.route.args_to_kwargs(args, kwargs) item = cls() item.label = bold(Script.localize(SEARCH)) item.art.global_thumb("search.png") item.info["plot"] = Script.localize(SEARCH_PLOT) item.set_callback(SavedSearches, route=callback.route.path, first_load=True, **kwargs) return item
def next_page(cls, **params): """ Constructor for adding Next Page. Add a listitem that will link to the next page of items. The current running callback will be called with all of the params that are given here. :param params: Keyword arguments of params that will be added to the current set of callback params. :example: >>> item = Listitem() >>> item.next_page(url="http://example.com/videos?page2") """ # Add support params to callback params params["_updatelisting_"] = True params["_title_"] = dispatcher.support_params.get(u"_title_", u"") params["_nextpagecount_"] = dispatcher.support_params.get( u"_nextpagecount_", 1) + 1 # Create listitem instance item = cls() label = u"%s %i" % (Script.localize(NEXT_PAGE), params["_nextpagecount_"]) item.info["plot"] = "Show the next page of content." item.label = "[B]%s[/B]" % label item.art.global_thumb("next.png") item.params.update(params) item.set_callback(dispatcher.callback, **params) return item
def youtube(cls, content_id, label=None, enable_playlists=True): """ Constructor to add a youtube channel to addon. This listitem will list all videos from a youtube channel or playlist. All videos also have a related videos option via context menu. If content_id is a channel id and enable_playlists is ``True`` then a link to the channel playlists will also be added to the list of videos. :param content_id: Channel id or playlist id of video content. :type content_id: str or unicode :param label: [opt] Label of listitem. (default => 'All Videos'). :type label: str or unicode :param bool enable_playlists: [opt] Set to ``False`` to disable linking to channel playlists. (default => ``True``) :example: >>> item = Listitem() >>> item.youtube("UC4QZ_LsYcvcq7qOsOhpAX4A") """ # Youtube exists, Creating listitem link item = cls() item.label = label if label else Script.localize(ALLVIDEOS) item.art.global_thumb("videos.png") item.params["contentid"] = content_id item.params["enable_playlists"] = False if content_id.startswith("PL") else enable_playlists item.set_callback(YTPlaylist) return item
def search(cls, callback, *args, **kwargs): """ Constructor to add saved search Support to addon. This will first link to a sub folder that lists all saved search terms. From here, search terms can be created or removed. When a selection is made, the callback function that was given will be executed with all params forwarded on. Except with one extra param, 'search_query' witch is the search term that was selected. :param callback: Function that will be called when the listitem is activated. :param args: Positional arguments that will be passed to callback. :param kwargs: Keyword arguments that will be passed to callback. :raises ValueError: If the given callback function does not have a 'search_query' parameter. """ if args: # Convert positional arguments to keyword arguments args_map = callback.route.args_to_kwargs(args) kwargs.update(args_map) # Check that callback function has required parameter(search_query). if "search_query" not in callback.route.arg_names(): raise ValueError("callback function is missing required argument: 'search_query'") item = cls() item.label = u"[B]%s[/B]" % Script.localize(SEARCH) item.art.global_thumb("search.png") item.info["plot"] = "Search for video content." item.set_callback(SavedSearches, route=callback.route.path, first_load=True, **kwargs) return item
def next_page(cls, *args, **kwargs): """ Constructor for adding link to Next Page of content. The current running callback will be called with all of the params that are given here. :param args: Positional arguments that will be passed to current callback. :param kwargs: Keyword arguments that will be passed to current callback. :example: >>> item = Listitem() >>> item.next_page(url="http://example.com/videos?page2") """ # Current running callback callback = dispatcher.current_route.org_callback if args: # Convert positional arguments to keyword arguments args_map = callback.route.args_to_kwargs(args) kwargs.update(args_map) # Add support params to callback params kwargs["_updatelisting_"] = True if u"_nextpagecount_" in dispatcher.support_params else False kwargs["_title_"] = dispatcher.support_params.get(u"_title_", u"") kwargs["_nextpagecount_"] = dispatcher.support_params.get(u"_nextpagecount_", 1) + 1 # Create listitem instance item = cls() label = u"%s %i" % (Script.localize(NEXT_PAGE), kwargs["_nextpagecount_"]) item.info["plot"] = "Show the next page of content." item.label = "[B]%s[/B]" % label item.art.global_thumb("next.png") item.params.update(kwargs) item.set_callback(callback, **kwargs) return item
def youtube(cls, content_id, label=None, enable_playlists=True): """ Constructor to add a "YouTube channel" to add-on. This listitem will list all videos from a "YouTube", channel or playlist. All videos will have a "Related Videos" option via the context menu. If ``content_id`` is a channel ID and ``enable_playlists`` is ``True``, then a link to the "channel playlists" will also be added to the list of videos. :param str content_id: Channel ID or playlist ID, of video content. :param str label: [opt] Listitem Label. (default => "All Videos"). :param bool enable_playlists: [opt] Set to ``False`` to disable linking to channel playlists. (default => ``True``) :example: >>> item = Listitem() >>> item.youtube("UC4QZ_LsYcvcq7qOsOhpAX4A") """ # Youtube exists, Creating listitem link item = cls() item.label = label if label else bold(Script.localize(ALLVIDEOS)) item.art.global_thumb("videos.png") item.params["contentid"] = content_id item.params["enable_playlists"] = False if content_id.startswith( "PL") else enable_playlists item.set_callback(Route.ref("/codequick/youtube:playlist")) return item
def youtube(cls, content_id, label=None, enable_playlists=True): """ Constructor to add a "YouTube channel" to add-on. This listitem will list all videos from a "YouTube", channel or playlist. All videos will have a "Related Videos" option via the context menu. If ``content_id`` is a channel ID and ``enable_playlists`` is ``True``, then a link to the "channel playlists" will also be added to the list of videos. :param str content_id: Channel ID or playlist ID, of video content. :param str label: [opt] Listitem Label. (default => "All Videos"). :param bool enable_playlists: [opt] Set to ``False`` to disable linking to channel playlists. (default => ``True``) :example: >>> item = Listitem() >>> item.youtube("UC4QZ_LsYcvcq7qOsOhpAX4A") """ # Youtube exists, Creating listitem link item = cls() item.label = label if label else bold(Script.localize(ALLVIDEOS)) item.art.global_thumb("videos.png") item.params["contentid"] = content_id item.params["enable_playlists"] = False if content_id.startswith("PL") else enable_playlists item.set_callback(YTPlaylist) return item
def recent(cls, callback, *args, **kwargs): """ Constructor for adding "Recent Videos" folder. This is a convenience method that creates the listitem with "name", "thumbnail" and "plot", already preset. :param Callback callback: The "callback" function. :param args: "Positional" arguments that will be passed to the callback. :param kwargs: "Keyword" arguments that will be passed to the callback. """ # Create listitem instance item = cls() item.label = bold(Script.localize(RECENT_VIDEOS)) item.info["plot"] = Script.localize(RECENT_VIDEOS_PLOT) item.art.global_thumb("recent.png") item.set_callback(callback, *args, **kwargs) return item
def recent(cls, callback, *args, **kwargs): """ Constructor for adding "Recent Videos" folder. This is a convenience method that creates the listitem with "name", "thumbnail" and "plot", already preset. :param callback: The "callback" function. :param args: "Positional" arguments that will be passed to the callback. :param kwargs: "Keyword" arguments that will be passed to the callback. """ # Create listitem instance item = cls() item.label = bold(Script.localize(RECENT_VIDEOS)) item.info["plot"] = Script.localize(RECENT_VIDEOS_PLOT) item.art.global_thumb("recent.png") item.set_callback(callback, *args, **kwargs) return item
def related(self, callback, **query): """ Convenient method to add a related videos context menu item. All this really does is set the label of the menu item for you. :param callback: The function that will be called when menu item is activated. :param query: [opt] Keyword arguments that will be passed on to callback function. """ self.container(Script.localize(RELATED_VIDEOS), callback, **query)
def related(self, callback, *args, **kwargs): """ Convenient method to add a related videos context menu item. All this really does is call context.container and sets label for you. :param callback: The function that will be called when menu item is activated. :param args: [opt] Positional arguments that will be passed to callback. :param kwargs: [opt] Keyword arguments that will be passed on to callback function. """ self.container(callback, Script.localize(RELATED_VIDEOS), *args, **kwargs)
def related(self, callback, *args, **kwargs): """ Convenient method to add a "Related Videos" context menu item. All this really does is to call "context.container" and sets "label" for you. :param callback: The function that will be called when menu item is activated. :param args: [opt] "Positional" arguments that will be passed to the callback. :param kwargs: [opt] "Keyword" arguments that will be passed to the callback. """ self.container(callback, Script.localize(RELATED_VIDEOS), *args, **kwargs)
def related(self, callback, *args, **kwargs): """ Convenient method to add a "Related Videos" context menu item. All this really does is to call "context.container" and sets "label" for you. :param callback: The function that will be called when menu item is activated. :param args: [opt] "Positional" arguments that will be passed to the callback. :param kwargs: [opt] "Keyword" arguments that will be passed to the callback. """ # Add '_updatelisting_ = True' to callback params if called from the same callback as is given here if callback.route == dispatcher.get_route(): kwargs["_updatelisting_"] = True related_videos_text = Script.localize(RELATED_VIDEOS) kwargs["_title_"] = related_videos_text self.container(callback, related_videos_text, *args, **kwargs)
def related(self, callback, *args, **kwargs): """ Convenient method to add a "Related Videos" context menu item. All this really does is to call "context.container" and sets "label" for you. :param callback: The function that will be called when menu item is activated. :param args: [opt] "Positional" arguments that will be passed to the callback. :param kwargs: [opt] "Keyword" arguments that will be passed to the callback. """ # Add '_updatelisting_ = True' to callback params if called from the same callback as is given here if callback.route == dispatcher.get_route(): kwargs["_updatelisting_"] = True related_videos_text = Script.localize(RELATED_VIDEOS) kwargs["_title_"] = related_videos_text self.container(callback, related_videos_text, *args, **kwargs)
def recent(cls, callback, **params): """ Constructor for adding Recent Folder. This is really more of a convenience method that creates the listitem with name, thumbnail and plot already preset for the user. :param callback: The callback function. :type callback: :class:`types.FunctionType` :param params: Keyword arguments of parameters that will be passed to the callback function. """ # Create listitem instance item = cls() item.label = Script.localize(RECENT_VIDEOS) item.info["plot"] = "Show the most recent videos." item.art.global_thumb("recent.png") item.set_callback(callback, **params) return item
def recent(cls, callback, *args, **kwargs): """ Constructor for adding Recent Videos folder. This is a convenience method that creates the listitem with name, thumbnail and plot already preset. :param callback: The callback function. :param args: Positional arguments that will be passed to callback. :param kwargs: Keyword arguments that will be passed to callback. """ if args: # Convert positional arguments to keyword arguments args_map = callback.route.args_to_kwargs(args) kwargs.update(args_map) # Create listitem instance item = cls() item.label = Script.localize(RECENT_VIDEOS) item.info["plot"] = "Show the most recent videos." item.art.global_thumb("recent.png") item.set_callback(callback, **kwargs) return item