예제 #1
0
def index():
    """ Ask to login, or go to the main menu. """
    if not kodiutils.has_credentials():
        if not kodiutils.yesno_dialog(message=kodiutils.localize(
                30701)):  # You need to configure your credentials...
            # We have no credentials, return to the Home Menu
            kodiutils.end_of_directory()
            kodiutils.execute_builtin('ActivateWindow(Home)')
            return

        kodiutils.open_settings()

    try:
        # Try authentication
        AuthApi(username=kodiutils.get_setting('username'),
                password=kodiutils.get_setting('password'),
                tenant=kodiutils.get_setting('tenant'),
                token_path=kodiutils.get_tokens_path())
    except InvalidLoginException:
        kodiutils.ok_dialog(message=kodiutils.localize(
            30203))  # Your credentials are not valid!
        kodiutils.open_settings()
        kodiutils.execute_builtin('ActivateWindow(Home)')
        kodiutils.end_of_directory()
        return

    except HTTPError as exc:
        kodiutils.ok_dialog(message=kodiutils.localize(
            30702, code='HTTP %d' % exc.response.status_code)
                            )  # Unknown error while logging in: {code}
        kodiutils.end_of_directory()
        return

    show_main_menu()
예제 #2
0
    def configure():
        """ Configure the library integration. """
        # There seems to be no way to add sources automatically.
        # * https://forum.kodi.tv/showthread.php?tid=228840

        # Open the sources view
        kodiutils.execute_builtin('ActivateWindow(Videos,sources://video/)')
예제 #3
0
    def setup(cls):
        """ Setup IPTV Simple """
        try:
            # Install IPTV Simple
            kodiutils.execute_builtin('InstallAddon', IPTV_SIMPLE_ID)
            addon = kodiutils.get_addon(IPTV_SIMPLE_ID)
        except Exception as exc:  # pylint: disable=broad-except
            _LOGGER.warning('Could not setup IPTV Simple: %s', str(exc))
            return False

        # Deactivate IPTV Simple to hide the "Needs to be restarted" messages
        cls._deactivate()

        # Configure IPTV Simple
        output_dir = kodiutils.addon_profile()
        playlist_path = os.path.join(output_dir, IPTV_SIMPLE_PLAYLIST)
        epg_path = os.path.join(output_dir, IPTV_SIMPLE_EPG)
        logo_path = '/'

        addon.setSetting('m3uPathType', '0')  # Local path
        addon.setSetting('m3uPath', playlist_path)

        addon.setSetting('epgPathType', '0')  # Local path
        addon.setSetting('epgPath', epg_path)

        addon.setSetting('logoPathType', '0')  # Local path
        addon.setSetting('logoPath', logo_path)

        # Activate IPTV Simple
        cls._activate()

        return True
예제 #4
0
    def setup(cls):
        """ Setup IPTV Simple """
        try:
            # Install IPTV Simple
            kodiutils.execute_builtin('InstallAddon', IPTV_SIMPLE_ID)
            addon = kodiutils.get_addon(IPTV_SIMPLE_ID)
        except:
            raise Exception('Could not enable IPTV Simple.')

        # Deactivate IPTV Simple to hide the "Needs to be restarted" messages
        cls._deactivate()

        # Configure IPTV Simple
        output_dir = kodiutils.addon_profile()
        playlist_path = os.path.join(output_dir, IPTV_SIMPLE_PLAYLIST)
        epg_path = os.path.join(output_dir, IPTV_SIMPLE_EPG)

        addon.setSetting('m3uPathType', '0')  # Local path
        addon.setSetting('m3uPath', playlist_path)

        addon.setSetting('epgPathType', '0')  # Local path
        addon.setSetting('epgPath', epg_path)

        addon.setSetting('logoPathType', '0')  # Local path
        addon.setSetting('logoPath', '/')

        # Activate IPTV Simple
        cls._activate()
예제 #5
0
def play_from_contextmenu():
    """Play an item from the Context Menu in Kodi 18"""
    stream = ContextMenu.get_direct_uri()
    if stream is None:
        kodiutils.ok_dialog(message=kodiutils.localize(30706))
        return

    _LOGGER.debug('Playing using direct URI: %s', stream)
    kodiutils.execute_builtin('PlayMedia', stream)
예제 #6
0
def index():
    """ Show the profile selection, or go to the main menu. """
    # Verify credentials
    from resources.lib.modules.authentication import Authentication
    if not Authentication.verify_credentials():
        kodiutils.end_of_directory()
        kodiutils.execute_builtin('ActivateWindow(Home)')
        return

    if kodiutils.get_setting_bool('auto_login') and kodiutils.get_setting('profile'):
        show_main_menu()
    else:
        select_profile()
    def _play(cls, uri, program):
        """Play the selected program with the specified URI."""
        format_params = {}
        if '{date}' in uri:
            format_params.update({'date': program.get('start').isoformat()})

        if '{duration}' in uri:
            format_params.update({'duration': program.get('duration')})

        if format_params:
            uri = uri.format(**format_params)

        _LOGGER.debug('Executing "%s"', uri)
        kodiutils.execute_builtin('PlayMedia', uri)
예제 #8
0
def play_from_contextmenu():
    """Play an item from the Context Menu in Kodi 18"""
    # Use the direct URI if we have any
    stream = ContextMenu.get_direct_uri()
    if stream:
        _LOGGER.debug('Playing using direct URI: %s', stream)
        kodiutils.execute_builtin('PlayMedia', stream)
        return

    # Construct an URI based on the timestamp of the selection
    stream = ContextMenu.get_uri_by_timestamp()
    if stream:
        _LOGGER.debug('Playing using generated URI: %s', stream)
        kodiutils.execute_builtin('PlayMedia', stream)
        return
예제 #9
0
    def _get_data_from_addon(self, uri):
        """ Request data from the specified URI """
        if uri.startswith('plugin://'):
            # Plugin path

            # Make request
            _, temp_file = tempfile.mkstemp()
            uri = uri.replace('$FILE', temp_file)
            kodiutils.execute_builtin('RunPlugin', uri)

            # Wait for data
            self._wait_for_data(temp_file, 30)

            # Load data
            _LOGGER.info('Loading reply from %s', temp_file)
            with open(temp_file) as fdesc:
                data = json.load(fdesc)

            # Remove temp file
            os.unlink(temp_file)

            return data

        if uri.startswith('http://') or uri.startswith('https://'):
            # HTTP(S) path
            # TODO: implement requests to fetch data
            return None

        # Local path
        addon = kodiutils.get_addon(self.addon_id)
        addon_path = kodiutils.addon_path(addon)
        filename = os.path.join(addon_path, uri)

        if not os.path.exists(filename):
            raise Exception('File %s does not exist' % filename)

        # Read file
        _LOGGER.info('Loading fixed reply from %s', filename)
        with open(filename) as fdesc:
            data = json.load(fdesc)

        return data
예제 #10
0
def index():
    """ Show the profile selection, or go to the main menu. """
    while True:
        if not kodiutils.has_credentials():
            if not kodiutils.yesno_dialog(message=kodiutils.localize(
                    30701)):  # You need to configure your credentials...
                # We have no credentials
                kodiutils.end_of_directory()
                kodiutils.execute_builtin('ActivateWindow(Home)')
                return

            kodiutils.open_settings()
        else:
            break

    try:
        if kodiutils.get_setting_bool('auto_login') and kodiutils.get_setting(
                'profile'):
            # We have a profile
            show_main_menu()

        else:
            # Ask the user for the profile to use
            select_profile()

    except InvalidLoginException:
        kodiutils.ok_dialog(message=kodiutils.localize(
            30203))  # Your credentials are not valid!
        kodiutils.open_settings()
        kodiutils.end_of_directory()

    except LoginErrorException as exc:
        kodiutils.ok_dialog(message=kodiutils.localize(
            30702, code=exc.code))  # Unknown error while logging in: {code}
        kodiutils.end_of_directory()

    except HTTPError as exc:
        kodiutils.ok_dialog(message=kodiutils.localize(
            30702, code='HTTP %d' % exc.response.status_code)
                            )  # Unknown error while logging in: {code}
        kodiutils.end_of_directory()
예제 #11
0
    def _get_data_from_addon(self, uri):
        """Request data from the specified URI"""
        # Plugin path
        if uri.startswith('plugin://'):
            # Prepare data
            sock = self._prepare_for_data()
            uri = update_qs(uri, port=sock.getsockname()[1])

            _LOGGER.info('Executing RunPlugin(%s)...', uri)
            kodiutils.execute_builtin('RunPlugin', uri)

            # Wait for data
            result = self._wait_for_data(sock)

            # Load data
            data = json.loads(result)

            return data

        # Currently, only plugin:// uris are supported
        raise NotImplementedError
    def setup(cls):
        """Setup IPTV Simple"""
        try:
            # Install IPTV Simple
            kodiutils.execute_builtin('InstallAddon', IPTV_SIMPLE_ID)

            # Activate IPTV Simple so we can get the addon to be able to configure it
            cls._activate()
            addon = kodiutils.get_addon(IPTV_SIMPLE_ID)
        except Exception as exc:  # pylint: disable=broad-except
            _LOGGER.warning('Could not setup IPTV Simple: %s', str(exc))
            return False

        # Deactivate IPTV Simple to hide the "Needs to be restarted" messages
        cls._deactivate()

        # Configure IPTV Simple
        output_dir = kodiutils.addon_profile()

        addon.setSetting('m3uPathType', '0')  # Local path
        addon.setSetting('m3uPath',
                         os.path.join(output_dir, IPTV_SIMPLE_PLAYLIST))

        addon.setSetting('epgPathType', '0')  # Local path
        addon.setSetting('epgPath', os.path.join(output_dir, IPTV_SIMPLE_EPG))
        addon.setSetting('epgCache', 'true')
        addon.setSetting('epgTimeShift', '0')

        addon.setSetting('logoPathType', '0')  # Local path
        addon.setSetting('logoPath', '/')

        addon.setSetting('catchupEnabled', 'true')
        addon.setSetting('allChannelsCatchupMode', '1')
        addon.setSetting('catchupOnlyOnFinishedProgrammes', 'false')

        # Activate IPTV Simple
        cls._activate()

        return True
예제 #13
0
    def _get_data_from_addon(self, uri):
        """ Request data from the specified URI """
        # Plugin path
        if uri.startswith('plugin://'):
            # Prepare data
            sock = self._prepare_for_data()
            uri = update_qs(uri, port=sock.getsockname()[1])

            _LOGGER.info('Executing RunPlugin(%s)...', uri)
            kodiutils.execute_builtin('RunPlugin', uri)

            # Wait for data
            result = self._wait_for_data(sock)

            # Load data
            data = json.loads(result)

            return data

        # HTTP(S) path
        if uri.startswith(('http://', 'https://')):
            # TODO: implement requests to fetch data
            return None

        # Local path
        addon = kodiutils.get_addon(self.addon_id)
        addon_path = kodiutils.addon_path(addon)
        filename = os.path.join(addon_path, uri)

        if not os.path.exists(filename):
            raise Exception('File %s does not exist' % filename)

        # Read file
        _LOGGER.info('Loading fixed reply from %s', filename)
        with open(filename) as fdesc:
            data = json.load(fdesc)

        return data