コード例 #1
0
    def refresh(cls, show_progress=False):
        """ Update channels and EPG data """
        channels = []
        epg = dict()

        if show_progress:
            progress = kodiutils.progress(
                message=kodiutils.localize(30703))  # Detecting IPTV add-ons...
        else:
            progress = None

        addons = cls.get_iptv_addons()

        for index, addon in enumerate(addons):
            _LOGGER.info('Updating IPTV data for %s...', addon.addon_id)

            if progress:
                progress.update(int(100 * index / len(addons)),
                                kodiutils.localize(30704).format(
                                    addon=kodiutils.addon_name(addon.addon_obj)
                                ))  # Fetching channels and guide of {addon}...

            # Fetch channels
            channels.extend(addon.get_channels())
            if progress and progress.iscanceled():
                progress.close()
                return

            # Fetch EPG data
            epg.update(addon.get_epg())
            if progress and progress.iscanceled():
                progress.close()
                return

        # Write files
        if show_progress:
            progress.update(
                100,
                kodiutils.localize(30705))  # Updating channels and guide...

        IptvSimple.write_playlist(channels)
        IptvSimple.write_epg(epg)

        if kodiutils.get_setting_bool('iptv_simple_restart'):
            if show_progress:
                # Try to restart now. We will schedule it if the user is watching TV.
                IptvSimple.restart(True)
            else:
                # Schedule a restart
                IptvSimple.restart(False)

        # Update last_refreshed
        kodiutils.set_setting_int('last_refreshed', int(time.time()))

        if show_progress:
            progress.close()
            kodiutils.ok_dialog(message=kodiutils.localize(
                30706))  # The channels and guide are updated successfully!
コード例 #2
0
ファイル: addon.py プロジェクト: im85288/service.iptv.manager
    def get_channels(self):
        """Get channel data from this add-on"""
        _LOGGER.info('Requesting channels from %s...', self.channels_uri)
        if not self.channels_uri:
            return {}

        try:
            data = self._get_data_from_addon(self.channels_uri)
            _LOGGER.debug(data)
        except Exception as exc:  # pylint: disable=broad-except
            _LOGGER.error('Something went wrong while calling %s',
                          self.addon_id,
                          exc_info=1)
            return []

        if data.get('version', 1) > CHANNELS_VERSION:
            _LOGGER.warning(
                'Skipping %s since it uses an unsupported version: %d',
                self.channels_uri, data.get('version'))
            return []

        channels = []
        for channel in data.get('streams', []):
            # Check for required fields
            if not channel.get('name') or not channel.get('stream'):
                _LOGGER.warning('Skipping channel since it is incomplete: %s',
                                channel)
                continue

            # Fix logo path to be absolute
            if channel.get('logo'):
                if not channel.get('logo').startswith(
                    ('http://', 'https://', 'special://', '/')):
                    channel['logo'] = os.path.join(self.addon_path,
                                                   channel.get('logo'))
            else:
                channel['logo'] = kodiutils.addon_icon(self.addon_obj)

            # Add add-on name as group
            if not channel.get('group'):
                channel['group'] = kodiutils.addon_name(self.addon_obj)

            channels.append(channel)

        return channels
コード例 #3
0
ファイル: addon.py プロジェクト: bobbybark/KODI_Addons
    def refresh(cls, show_progress=False, force=False):
        """Update channels and EPG data"""
        channels = []
        epg = []

        if show_progress:
            progress = kodiutils.progress(
                message=kodiutils.localize(30703))  # Detecting IPTV add-ons...
        else:
            progress = None

        addons = cls.detect_iptv_addons()
        for index, addon in enumerate(addons):
            """Check if addon requires update"""

            if not force and not cls.is_refresh_required(addon.addon_id):
                addon_epg = cls.cache.get('iptvmanager.epg.%s' %
                                          (addon.addon_id))
                addon_channel = cls.cache.get('iptvmanager.channel.%s' %
                                              (addon.addon_id))
                if addon_epg and addon_channel:
                    _LOGGER.info('Update not needed for %s...', addon.addon_id)
                    channels.append(addon_channel)
                    epg.append(addon_epg)
                    continue

            if progress:
                # Fetching channels and guide of {addon}...
                progress.update(
                    int(100 * index / len(addons)),
                    kodiutils.localize(30704).format(
                        addon=kodiutils.addon_name(addon.addon_obj)))
            _LOGGER.info('Updating IPTV data for %s...', addon.addon_id)

            # Fetch channels
            addon_channel = dict(
                addon_id=addon.addon_id,
                addon_name=kodiutils.addon_name(addon.addon_obj),
                channels=addon.get_channels(),
            )
            channels.append(addon_channel)

            if progress and progress.iscanceled():
                progress.close()
                return

            # Fetch EPG
            addon_epg = addon.get_epg()
            cls.set_cache_n_update(cls, addon.addon_id, addon_epg,
                                   addon_channel)
            epg.append(addon_epg)

            if progress and progress.iscanceled():
                progress.close()
                return

        # Write files
        if show_progress:
            progress.update(
                100,
                kodiutils.localize(30705))  # Updating channels and guide...

        IptvSimple.write_playlist(channels)
        IptvSimple.write_epg(epg, channels)

        if kodiutils.get_setting_bool('iptv_simple_restart'):
            if show_progress:
                # Restart now.
                IptvSimple.restart(True)
            else:
                # Try to restart now. We will schedule it if the user is watching TV.
                IptvSimple.restart(False)

        # Update last_refreshed
        kodiutils.set_property('last_refreshed', int(time.time()))

        if show_progress:
            progress.close()
コード例 #4
0
ファイル: addon.py プロジェクト: bobbybark/KODI_Addons
    def get_channels(self):
        """Get channel data from this add-on"""
        _LOGGER.info('Requesting channels from %s...', self.channels_uri)
        if not self.channels_uri:
            return []

        try:
            data = self._get_data_from_addon(self.channels_uri)
            _LOGGER.debug(data)
        except Exception as exc:  # pylint: disable=broad-except
            _LOGGER.error('Something went wrong while calling %s: %s',
                          self.addon_id, exc)
            return []

        # Return M3U8-format as-is without headers
        if not isinstance(data, dict):
            return data.replace('#EXTM3U\n', '')

        # JSON-STREAMS format
        if data.get('version', 1) > CHANNELS_VERSION:
            _LOGGER.warning(
                'Skipping %s since it uses an unsupported version: %d',
                self.channels_uri, data.get('version'))
            return []

        channels = []
        for channel in data.get('streams', []):
            # Check for required fields
            if not channel.get('name') or not channel.get('stream'):
                _LOGGER.warning('Skipping channel since it is incomplete: %s',
                                channel)
                continue

            # Fix logo path to be absolute
            if not channel.get('logo'):
                channel['logo'] = kodiutils.addon_icon(self.addon_obj)
            elif not channel.get('logo').startswith(
                ('http://', 'https://', 'special://', 'resource://', '/')):
                channel['logo'] = os.path.join(self.addon_path,
                                               channel.get('logo'))

            # Ensure group is a set
            if not channel.get('group'):
                channel['group'] = set()
            # Accept string values (backward compatible)
            elif isinstance(channel.get('group'), (bytes, str)):
                channel['group'] = set(channel.get('group').split(';'))
            # Accept string values (backward compatible, py2 version)
            elif sys.version_info.major == 2 and isinstance(
                    channel.get('group'), unicode):  # noqa: F821; pylint: disable=undefined-variable
                channel['group'] = set(channel.get('group').split(';'))
            elif isinstance(channel.get('group'), list):
                channel['group'] = set(list(channel.get('group')))
            else:
                _LOGGER.warning('Channel group is not a list: %s', channel)
                channel['group'] = set()
            # Add add-on name as group, if not already
            channel['group'].add(kodiutils.addon_name(self.addon_obj))

            channels.append(channel)

        return channels