Ejemplo n.º 1
0
    def _get_path_from_actions(self, actions, is_folder=True):
        """ Returns tuple of (path, is_folder) """
        keyboard_input = None
        path = (actions[0], is_folder)
        for action in actions[1:]:
            # Check if we've got a playable item already
            if not is_folder:
                return path

            # Start thread with keyboard inputter if needed
            if action.get('keyboard'):
                if action.get('keyboard') in [
                        'Up', 'Down', 'Left', 'Right', 'Select'
                ]:
                    keyboard_input = KeyboardInputter(
                        action="Input.{}".format(action.get('keyboard')))
                else:
                    text = string_format_map(action.get('keyboard', ''),
                                             self.item)
                    keyboard_input = KeyboardInputter(
                        text=text[::-1] if action.get('direction') ==
                        'rtl' else text)
                keyboard_input.setName('keyboard_input')
                keyboard_input.start()
                continue  # Go to next action

            # Get the next folder from the plugin
            folder = get_directory(string_format_map(path[0], self.item))

            # Kill our keyboard inputter thread
            if keyboard_input:
                keyboard_input.exit = True
                keyboard_input = None

            # Special option to show dialog of items to select
            if action.get('dialog'):
                auto = True if action.get('dialog',
                                          '').lower() == 'auto' else False
                return self._player_dialog_select(folder, auto=auto)

            # Apply the rules for the current action and grab the path
            path = self._get_path_from_rules(folder, action)
            if not path:
                return
        return path
Ejemplo n.º 2
0
    def _get_path_from_actions(self, actions, is_folder=True):
        """ Returns tuple of (path, is_folder) """
        is_dialog = None
        keyboard_input = None
        path = (actions[0], is_folder)
        if not is_folder:
            return path
        for action in actions[1:]:
            # Start thread with keyboard inputter if needed
            if action.get('keyboard'):
                if action['keyboard'] in [
                        'Up', 'Down', 'Left', 'Right', 'Select'
                ]:
                    keyboard_input = KeyboardInputter(
                        action="Input.{}".format(action.get('keyboard')))
                else:
                    text = string_format_map(action['keyboard'], self.item)
                    keyboard_input = KeyboardInputter(
                        text=text[::-1] if action.get('direction') ==
                        'rtl' else text)
                keyboard_input.setName('keyboard_input')
                keyboard_input.start()
                continue  # Go to next action

            # Get the next folder from the plugin
            folder = get_directory(string_format_map(path[0], self.item))

            # Kill our keyboard inputter thread
            if keyboard_input:
                keyboard_input.exit = True
                keyboard_input = None

            # Pop special actions
            is_return = action.pop('return', None)
            is_dialog = action.pop('dialog', None)

            # Get next path if there's still actions left
            next_path = self._get_path_from_rules(folder,
                                                  action) if action else None

            # Special action to fallback to select dialog if match is not found directly
            if is_dialog and not next_path:
                next_path = self._player_dialog_select(
                    folder, auto=is_dialog.lower() == 'auto')

            # Early return flag ignores a step failure and instead continues onto trying next step
            # Check against next_path[1] also to make sure we aren't trying to play a folder
            if is_return and (not next_path or next_path[1]):
                continue

            # No next path and no special flags means that player failed
            if not next_path:
                return

            # File is playable and user manually selected or early return flag set
            # Useful for early exit to play episodes in flattened miniseries instead of opening season folder
            if not next_path[1] and (is_dialog or is_return):
                return next_path

            # Set next path to path for next action
            path = next_path

        # If dialog repeat flag set then repeat action over until find playable or user cancels
        if path and is_dialog == 'repeat':
            return self._get_path_from_actions([path[0], {
                'dialog': 'repeat'
            }], path[1])

        return path