def test_build_path_extra_args_py3(self):
     support.dispatcher.params["_title_"] = "video"
     try:
         ret = support.build_path(self.callback, testdata="data")
         self.assertEqual("plugin://script.module.codequick/root?_pickle_="
                          "80049529000000000000007d94288c075f7469746c655f948c"
                          "05766964656f948c087465737464617461948c046461746194752e", ret)
     finally:
         del support.dispatcher.params["_title_"]
 def test_build_path_extra_args_py2(self):
     support.dispatcher.params["_title_"] = "video"
     try:
         ret = support.build_path(self.callback, testdata="data")
         self.assertEqual("plugin://script.module.codequick/root?_pickle_="
                          "80027d71002855075f7469746c655f71015505766964656f71"
                          "025508746573746461746171035504646174617104752e", ret)
     finally:
         del support.dispatcher.params["_title_"]
Ejemplo n.º 3
0
 def test_build_path_extra_args_py3(self):
     support.dispatcher.params["_title_"] = "video"
     try:
         ret = support.build_path(self.callback, testdata="data")
         self.assertEqual(
             "plugin://script.module.codequick/root?_pickle_="
             "80049529000000000000007d94288c075f7469746c655f948c"
             "05766964656f948c087465737464617461948c046461746194752e", ret)
     finally:
         del support.dispatcher.params["_title_"]
Ejemplo n.º 4
0
 def test_build_path_extra_args_py2(self):
     support.dispatcher.params["_title_"] = "video"
     try:
         ret = support.build_path(self.callback, testdata="data")
         self.assertEqual(
             "plugin://script.module.codequick/root?_pickle_="
             "80027d71002855075f7469746c655f71015505766964656f71"
             "025508746573746461746171035504646174617104752e", ret)
     finally:
         del support.dispatcher.params["_title_"]
Ejemplo n.º 5
0
    def container(self, label, callback, **query):
        """
        Convenient method to add a context menu item.

        :param label: The label of the context menu item.
        :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.
        """
        command = "XBMC.Container.Update(%s)" % build_path(
            callback.route.path, query)
        self.append((label, command))
Ejemplo n.º 6
0
    def script(self, callback, label, *args, **kwargs):
        """
        Convenient method to add a context menu item that links to a "script".

        :param Callback callback: The function that will be called when menu item is activated.
        :type label: str or unicode
        :param label: The label of the context menu item.
        :param args: [opt] "Positional" arguments that will be passed to the callback.
        :param kwargs: [opt] "Keyword" arguments that will be passed to the callback.
        """
        command = "XBMC.RunPlugin(%s)" % build_path(callback, args, kwargs)
        self.append((label, command))
Ejemplo n.º 7
0
    def _close(self):
        callback = self.path
        if hasattr(callback, "route"):
            self.listitem.setProperty("isplayable", str(callback.route.is_playable).lower())
            self.listitem.setProperty("folder", str(callback.route.is_folder).lower())
            path = build_path(callback.route.path, self.params.raw_dict)
            isfolder = callback.route.is_folder
        elif callback:
            self.listitem.setProperty("isplayable", "true" if callback else "false")
            self.listitem.setProperty("folder", "false")
            path = callback
            isfolder = False
        else:
            raise ValueError("Missing required callback")

        if isfolder:
            # Set Kodi icon image if not already set
            if "icon" not in self.art.raw_dict:  # pragma: no branch
                self.art.raw_dict["icon"] = "DefaultFolder.png"
        else:
            # Set Kodi icon image if not already set
            if "icon" not in self.art.raw_dict:  # pragma: no branch
                self.art.raw_dict["icon"] = "DefaultVideo.png"

            # Add mediatype if not already set
            if "mediatype" not in self.info.raw_dict and self._content_type in ("video", "music"):  # pragma: no branch
                self.info.raw_dict["mediatype"] = self._content_type

            # Add Video Specific Context menu items
            self.context.append(("$LOCALIZE[13347]", "XBMC.Action(Queue)"))
            self.context.append(("$LOCALIZE[13350]", "XBMC.ActivateWindow(videoplaylist)"))

            # Close video related datasets
            self.stream._close()

        label = self.label
        # Set label to UNKNOWN if unset
        if not label:  # pragma: no branch
            self.label = label = u"UNKNOWN"

        # Add label as plot if no plot is found
        if "plot" not in self.info:  # pragma: no branch
            self.info["plot"] = label

        # Close common datasets
        self.listitem.setPath(path)
        self.property._close()
        self.context._close()
        self.info._close(self._content_type)
        self.art._close()

        # Return a tuple compatible with 'xbmcplugin.addDirectoryItems'
        return path, self.listitem, isfolder
Ejemplo n.º 8
0
    def script(self, callback, label, *args, **kwargs):
        """
        Convenient method to add a context menu item that links to a "script".

        :param callback: The function that will be called when menu item is activated.
        :type label: str or unicode
        :param label: The label of the context menu item.
        :param args: [opt] "Positional" arguments that will be passed to the callback.
        :param kwargs: [opt] "Keyword" arguments that will be passed to the callback.
        """
        command = "XBMC.RunPlugin(%s)" % build_path(callback, args, kwargs)
        self.append((label, command))
Ejemplo n.º 9
0
    def container(self, callback, label, *args, **kwargs):
        """
        Convenient method to add a context menu item that links to a "container".

        :type label: str
        :param callback: The function that will be called when menu item is activated.
        :param label: The label of the context menu item.
        :param args: [opt] "Positional" arguments that will be passed to the callback.
        :param kwargs: [opt] "Keyword" arguments that will be passed to the callback.
        """
        command = "XBMC.Container.Update(%s)" % build_path(
            callback, args, kwargs)
        self.append((label, command))
Ejemplo n.º 10
0
    def _close(self):
        path = self.path
        listitem = self.listitem
        if hasattr(path, "route"):
            isfolder = path.route.is_folder
            listitem.setProperty("isplayable",
                                 str(path.route.is_playable).lower())
            listitem.setProperty("folder", str(path.route.is_folder).lower())
            path = build_path(path, self._args, self.params.raw_dict)
        elif not path:
            listitem.setProperty("isplayable", "false")
            listitem.setProperty("folder", "false")
            isfolder = False
        else:
            listitem.setProperty("isplayable", str(self.is_playable).lower())
            listitem.setProperty("folder", str(self.is_folder).lower())
            isfolder = self.is_folder

        if not isfolder:
            # Add mediatype if not already set
            if "mediatype" not in self.info.raw_dict and self._content_type in (
                    "video", "music"):  # pragma: no branch
                self.info.raw_dict["mediatype"] = self._content_type

            # Set the listitem subtitles
            if self.subtitles:
                self.listitem.setSubtitles(self.subtitles)

            # Add Video Specific Context menu items
            self.context.append(("$LOCALIZE[13347]", "XBMC.Action(Queue)"))
            self.context.append(
                ("$LOCALIZE[13350]", "XBMC.ActivateWindow(videoplaylist)"))

            # Close video related datasets
            self.stream._close()

        # Set label to UNKNOWN if unset
        if not self.label:  # pragma: no branch
            self.label = u"UNKNOWN"

        # Close common datasets
        listitem.setPath(path)
        self.property._close()
        self.context._close()
        self.info._close(self._content_type)
        self.art._close(isfolder)

        # Return a tuple compatible with 'xbmcplugin.addDirectoryItems'
        return path, listitem, isfolder
Ejemplo n.º 11
0
    def create_loopback(self, url, **next_params):
        """
        Create a playlist where the second item loops back to current addon to load next video.

        Useful for faster playlist resolving by only resolving the video url as the playlist progresses.
        No need to resolve all video urls at once before playing the playlist.

        Also useful for continuous playback of videos with no foreseeable end. For example, party mode.

        :param url: Url of the first playable item.
        :type url: str or unicode

        :param next_params: [opt] Keyword arguments to add to the loopback request when accessing the next video.

        :returns: The Listitem that kodi will play.
        :rtype: xbmcgui.ListItem
        """
        # Video Playlist
        playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)

        # Main Playable listitem
        main_listitem = xbmcgui.ListItem()
        main_listitem.setPath(url)

        # When called from a loopback we just add title to main listitem
        if self._title.startswith(u"_loopback_"):
            main_listitem.setLabel(self._title.split(u" - ", 1)[1])
            next_params["_title_"] = self._title
        else:
            # Create playlist for loopback calling
            # The first item is the playable listitem
            main_listitem.setLabel(self._title)
            next_params["_title_"] = u"_loopback_ - %s" % self._title
            playlist.clear()
            playlist.add(url, main_listitem)

        # Create Loopback listitem
        loop_listitem = xbmcgui.ListItem()
        loop_listitem.setLabel(next_params["_title_"])

        # Build a loopback url that callback to the addon to fetch the next video
        loopback_url = build_path(**next_params)
        loop_listitem.setPath(loopback_url)
        playlist.add(loopback_url, loop_listitem)

        # Retrun the playable listitem
        return main_listitem
Ejemplo n.º 12
0
    def _close(self):
        path = self.path
        listitem = self.listitem
        if hasattr(path, "route"):
            isfolder = path.route.is_folder
            listitem.setProperty("isplayable", str(path.route.is_playable).lower())
            listitem.setProperty("folder", str(path.route.is_folder).lower())
            path = build_path(path, self._args, self.params.raw_dict)
        elif not path:
            listitem.setProperty("isplayable", "false")
            listitem.setProperty("folder", "false")
            isfolder = False
        else:
            listitem.setProperty("isplayable", str(self.is_playable).lower())
            listitem.setProperty("folder", str(self.is_folder).lower())
            isfolder = self.is_folder

        if not isfolder:
            # Add mediatype if not already set
            if "mediatype" not in self.info.raw_dict and self._content_type in ("video", "music"):  # pragma: no branch
                self.info.raw_dict["mediatype"] = self._content_type

            # Set the listitem subtitles
            if self.subtitles:
                self.listitem.setSubtitles(self.subtitles)

            # Add Video Specific Context menu items
            self.context.append(("$LOCALIZE[13347]", "XBMC.Action(Queue)"))
            self.context.append(("$LOCALIZE[13350]", "XBMC.ActivateWindow(videoplaylist)"))

            # Close video related datasets
            self.stream._close()

        # Set label to UNKNOWN if unset
        if not self.label:  # pragma: no branch
            self.label = u"UNKNOWN"

        # Close common datasets
        listitem.setPath(path)
        self.property._close()
        self.context._close()
        self.info._close(self._content_type)
        self.art._close(isfolder)

        # Return a tuple compatible with 'xbmcplugin.addDirectoryItems'
        return path, listitem, isfolder
Ejemplo n.º 13
0
    def script(self, callback, label, *args, **kwargs):
        """
        Convenient method to add a context menu item that links to a script.

        :param callback: The function that will be called when menu item is activated.
        :type label: str or unicode
        :param label: The label of the context menu item.
        :param args: [opt] Positional arguments that will be passed to callback.
        :param kwargs: [opt] Keyword arguments that will be passed on to callback function.
        """
        if args:
            # Convert positional arguments to keyword arguments
            args_map = callback.route.args_to_kwargs(args)
            kwargs.update(args_map)

        command = "XBMC.RunPlugin(%s)" % build_path(callback.route.path, kwargs)
        self.append((label, command))
Ejemplo n.º 14
0
    def create_loopback(self, url, **next_params):  # Undocumented
        """
        Create a playlist where the second item loops back to add-on to load next video.

        Also useful for continuous playback of videos with no foreseeable end. For example, party mode.

        :param str url: URL of the first playable item.
        :param next_params: [opt] "Keyword" arguments to add to the loopback request when accessing the next video.

        :returns: The Listitem that Kodi will play.
        :rtype: xbmcgui.ListItem
        """
        # Video Playlist
        playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)

        # Main Playable listitem
        main_listitem = xbmcgui.ListItem()
        main_listitem.setPath(url)

        # When called from a loopback we just add title to main listitem
        if self._title.startswith(u"_loopback_"):
            main_listitem.setLabel(self._title.split(u" - ", 1)[1])
            next_params["_title_"] = self._title
        else:
            # Create playlist for loopback calling
            # The first item is the playable listitem
            main_listitem.setLabel(self._title)
            next_params["_title_"] = u"_loopback_ - %s" % self._title
            playlist.clear()
            playlist.add(url, main_listitem)

        # Create Loopback listitem
        loop_listitem = xbmcgui.ListItem()
        loop_listitem.setLabel(next_params["_title_"])

        # Build a loopback url that callback to the addon to fetch the next video
        loopback_url = build_path(**next_params)
        loop_listitem.setPath(loopback_url)
        playlist.add(loopback_url, loop_listitem)

        # Retrun the playable listitem
        return main_listitem
Ejemplo n.º 15
0
 def test_build_path_new_args_py2(self):
     ret = support.build_path(self.callback, query={"testdata": "data"})
     self.assertEqual(
         "plugin://script.module.codequick/root?_pickle_="
         "80027d71005508746573746461746171015504646174617102732e", ret)
 def test_build_path_new_args_py2(self):
     ret = support.build_path(self.callback, query={"testdata": "data"})
     self.assertEqual("plugin://script.module.codequick/root?_pickle_="
                      "80027d71005508746573746461746171015504646174617102732e", ret)
 def test_build_path_new_args_py3(self):
     ret = support.build_path(self.callback, query={"testdata": "data"})
     self.assertEqual("plugin://script.module.codequick/root?_pickle_="
                      "80049516000000000000007d948c087465737464617461948c046461746194732e", ret)
 def test_build_new_path(self):
     ret = support.build_path(self.callback)
     self.assertEqual(ret, "plugin://script.module.codequick/root")
Ejemplo n.º 19
0
 def test_build_new_path(self):
     ret = support.build_path(self.callback)
     self.assertEqual(ret, "plugin://script.module.codequick/root")
Ejemplo n.º 20
0
 def test_build_path_no_args(self):
     ret = support.build_path()
     self.assertEqual(ret, "plugin://script.module.codequick/root")
Ejemplo n.º 21
0
 def test_build_path_new_args_py3(self):
     ret = support.build_path(self.callback, query={"testdata": "data"})
     self.assertEqual(
         "plugin://script.module.codequick/root?_pickle_="
         "80049516000000000000007d948c087465737464617461948c046461746194732e",
         ret)
 def test_build_path_no_args(self):
     ret = support.build_path()
     self.assertEqual(ret, "plugin://script.module.codequick/root")