예제 #1
0
    def detect_iptv_addons():
        """Find add-ons that provide IPTV channel data"""
        result = kodiutils.jsonrpc(method="Addons.GetAddons",
                                   params={
                                       'installed': True,
                                       'enabled': True,
                                       'type': 'xbmc.python.pluginsource'
                                   })

        addons = []
        for row in result['result']['addons']:
            addon = kodiutils.get_addon(row['addonid'])

            # Check if add-on supports IPTV Manager
            if addon.getSetting('iptv.enabled') != 'true':
                continue

            addons.append(
                Addon(
                    addon_id=row['addonid'],
                    addon_obj=addon,
                    channels_uri=addon.getSetting('iptv.channels_uri'),
                    epg_uri=addon.getSetting('iptv.epg_uri'),
                ))

        return addons
예제 #2
0
    def __init__(self, addon_id, channels_uri, epg_uri):
        self.addon_id = addon_id
        self.channels_uri = channels_uri
        self.epg_uri = epg_uri

        addon = kodiutils.get_addon(addon_id)
        self.addon_path = kodiutils.addon_path(addon)
예제 #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 get_iptv_addons():
        """ Find add-ons that provide IPTV channel data """
        result = kodiutils.jsonrpc(method="Addons.GetAddons",
                                   params={
                                       'installed': True,
                                       'enabled': True,
                                       'type': 'xbmc.python.pluginsource'
                                   })

        addons = []
        for row in result['result']['addons']:
            addon = kodiutils.get_addon(row['addonid'])
            addon_path = kodiutils.addon_path(addon)
            addon_iptv_config = os.path.join(addon_path, IPTV_FILENAME)

            # Check if this addon has an iptv.json
            if not os.path.exists(addon_iptv_config):
                continue

            # Read iptv.json
            with open(addon_iptv_config) as fdesc:
                data = json.load(fdesc)

            # Check version
            if data.get('version', 1) > IPTV_VERSION:
                _LOGGER.warning(
                    'Skipping %s since it uses an unsupported version of iptv.json: %d',
                    row['addonid'], data.get('version'))
                continue

            if not data.get('channels'):
                _LOGGER.warning('Skipping %s since it has no channels defined',
                                row['addonid'])
                continue

            addons.append(
                Addon(
                    addon_id=row['addonid'],
                    channels_uri=data.get('channels'),
                    epg_uri=data.get('epg'),
                ))

        return addons
예제 #6
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
    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
예제 #8
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