Exemple #1
0
 def _get_next_item_item_information():
     current_position = g.PLAYLIST.getposition()
     url = g.PLAYLIST[  # pylint: disable=unsubscriptable-object
         current_position + 1].getPath()
     params = dict(tools.parse_qsl(tools.unquote(url.split("?")[1])))
     return tools.get_item_information(
         tools.deconstruct_action_args(params.get("action_args")))
Exemple #2
0
    def init_request(self, argv):
        if argv is None:
            return

        self.URL = tools.urlparse(argv[0])
        try:
            self.PLUGIN_HANDLE = int(argv[1])
            self.IS_SERVICE = False
        except IndexError:
            self.PLUGIN_HANDLE = 0
            self.IS_SERVICE = True

        if self.URL[1] != "":
            self.BASE_URL = "{scheme}://{netloc}".format(scheme=self.URL[0],
                                                         netloc=self.URL[1])
        else:
            self.BASE_URL = ""
        self.PATH = tools.unquote(self.URL[2])
        try:
            self.PARAM_STRING = argv[2].lstrip('?/')
        except IndexError:
            self.PARAM_STRING = ""
        self.REQUEST_PARAMS = self.legacy_params_converter(
            dict(tools.parse_qsl(self.PARAM_STRING)))
        if "action_args" in self.REQUEST_PARAMS:
            self.REQUEST_PARAMS["action_args"] = tools.deconstruct_action_args(
                self.REQUEST_PARAMS["action_args"])
            if isinstance(self.REQUEST_PARAMS["action_args"], dict):
                self.REQUEST_PARAMS[
                    "action_args"] = self.legacy_action_args_converter(
                        self.REQUEST_PARAMS["action_args"])
        self.FROM_WIDGET = self.REQUEST_PARAMS.get("from_widget",
                                                   "true") == "true"
        self.PAGE = int(g.REQUEST_PARAMS.get("page", 1))
Exemple #3
0
    def playlist_present_check(self, ignore_setting=False):
        """
        Confirms if a playlist is currently present. If not or playlist is for a different item, clear current list
        and build a new one
        :param ignore_setting: Force playlist building if setting is disabled
        :type ignore_setting: bool
        :return: Playlist if playlist is present else False
        :rtype: any
        """
        if g.get_bool_setting("smartplay.playlistcreate") or ignore_setting:

            if not self.item_information["info"]["mediatype"] == "episode":
                g.log("Movie playback requested, clearing playlist")
                g.PLAYLIST.clear()
                return False

            playlist_uris = [
                g.PLAYLIST[i].getPath()  # pylint: disable=unsubscriptable-object
                for i in range(g.PLAYLIST.size())
            ]

            # Check to see if we are just starting playback and kodi has created a playlist
            if len(playlist_uris) == 1 and playlist_uris[0].split(
                    '/')[-1].lstrip('?') == g.PARAM_STRING:
                return False

            if g.PLAYLIST.getposition() == -1:
                return self.create_single_item_playlist_from_info()

            if [i for i in playlist_uris if g.ADDON_NAME.lower() not in i]:
                g.log("Cleaning up other addon items from playlsit", "debug")
                playlist_uris = []

            action_args = [
                g.legacy_action_args_converter(
                    g.legacy_params_converter(
                        dict(tools.parse_qsl(
                            i.split("?")[-1]))))["action_args"]
                for i in playlist_uris
            ]

            show_ids = set(
                tools.deconstruct_action_args(i).get('trakt_show_id')
                for i in action_args)

            if len(show_ids) > 1 and self.show_trakt_id not in show_ids:
                g.log("Cleaning up items from other shows", "debug")
                playlist_uris = []

            if (len(playlist_uris) == 0 or
                (len(playlist_uris) > 1 and not any(g.PARAM_STRING in i for i in playlist_uris))) or \
                    g.PLAYLIST.getposition() == -1:
                return self.create_single_item_playlist_from_info()

        return False
 def get_task_info(self, url_hash):
     """
     Takes a task hash and returns the information stored in the Window property
     :param url_hash: Sting
     :return: dict
     """
     try:
         return tools.deconstruct_action_args(
             self._win.getProperty("sdm.{}".format(url_hash)))
     except Exception:
         raise TaskDoesNotExist(url_hash)
Exemple #5
0
    def playlist_present_check(self, ignore_setting=False):
        """
        Confirms if a playlist is currently present. If not or playlist is for a different item, clear current list
        and build a new one
        :param ignore_setting: Force playlist building if setting is disabled
        :type ignore_setting: bool
        :return: Playlist if playlist is present else False
        :rtype: any
        """
        if g.get_bool_setting("smartplay.playlistcreate") or ignore_setting:

            if not self.item_information["info"]["mediatype"] == "episode":
                g.log("Movie playback requested, clearing playlist")
                g.PLAYLIST.clear()
                return False

            playlist_uris = [
                g.PLAYLIST[i].getPath()  # pylint: disable=unsubscriptable-object
                for i in range(g.PLAYLIST.size())
            ]

            # Check to see if we are just starting playback and kodi has created a playlist
            if len(playlist_uris) == 1 and playlist_uris[0].split(
                    '/')[-1] == sys.argv[2]:
                return False

            if [i for i in playlist_uris if g.ADDON_NAME.lower() not in i]:
                g.log("Cleaning up other addon items from playlsit", "debug")
                playlist_uris = []

            action_args = [
                dict(tools.parse_qsl(i.split("?")[-1])).get("action_args")
                for i in playlist_uris
            ]
            action_args = [i for i in action_args if i is not None]

            if not action_args:
                playlist_uris = []

            show_ids = set(
                tools.deconstruct_action_args(i).get('trakt_show_id')
                for i in action_args)

            if len(show_ids) > 1 and self.show_trakt_id not in show_ids:
                g.log("Cleaning up items from other shows", "debug")
                playlist_uris = []

            if len(playlist_uris) == 0 or (len(playlist_uris) > 1 and
                                           not any(sys.argv[2] in i
                                                   for i in playlist_uris)):
                g.cancel_playback()
                name = self.item_information["info"]["title"]
                item = g.add_directory_item(
                    name,
                    action="getSources",
                    menu_item=self.item_information,
                    action_args=tools.construct_action_args(
                        self.item_information),
                    bulk_add=True,
                    is_playable=True,
                )
                g.PLAYLIST.add(url=sys.argv[0] + sys.argv[2], listitem=item[1])
                return g.PLAYLIST
        return False