Exemplo n.º 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!
Exemplo n.º 2
0
    def run(self):
        """Background loop for maintenance tasks"""
        _LOGGER.debug('Service started')

        # Service loop
        while not self.abortRequested():
            # Check if we need to do an update
            if self._is_refresh_required():
                Addon.refresh()

            # Check if IPTV Simple needs to be restarted
            if IptvSimple.restart_required:
                IptvSimple.restart()

            # Stop when abort requested
            if self.waitForAbort(30):
                break

        _LOGGER.debug('Service stopped')
Exemplo n.º 3
0
    def update():
        """ Update the channels and epg data """
        channels = []
        epg = dict()

        addons = Addon.get_iptv_addons()
        for addon in addons:
            _LOGGER.info('Updating IPTV data for %s...', addon.addon_id)

            # Fetch channels
            channels.extend(addon.get_channels())

            # Fetch EPG data
            epg.update(addon.get_epg())

        # Write files
        IptvSimple.write_playlist(channels)
        IptvSimple.write_epg(epg)

        IptvSimple.restart()
Exemplo n.º 4
0
    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()