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!
def update(self): """ Update the metadata with a foreground progress indicator """ # Create progress indicator progress_dialog = kodiutils.progress(message=kodiutils.localize(30715)) # Updating metadata def update_status(i, total): """ Update the progress indicator """ progress_dialog.update(int(((i + 1) / total) * 100), kodiutils.localize(30716, index=i + 1, total=total)) # Updating metadata ({index}/{total}) return progress_dialog.iscanceled() self.fetch_metadata(callback=update_status) # Close progress indicator progress_dialog.close()
def login(self): """ Start the authorisation flow. """ auth_info = self._auth.authorize() # Show the authorization message progress_dialog = kodiutils.progress( message=kodiutils.localize(30701, url=auth_info.get('verification_uri'), code=auth_info.get('user_code'))) progress_dialog.update(0) # Check the authorization until it succeeds or the user cancels. delay = auth_info.get('interval') expiry = auth_info.get('expires_in') time_start = datetime.now() time_end = time_start + timedelta(seconds=expiry) while datetime.now() < time_end: # Update progress progress_dialog.update( int((datetime.now() - time_start).seconds * 100 / expiry)) # Check if the users has cancelled the login flow if progress_dialog.iscanceled(): progress_dialog.close() return # Check if we are authorized now check = self._auth.authorize_check() if check: progress_dialog.close() kodiutils.notification(kodiutils.localize(30702)) kodiutils.redirect(kodiutils.url_for('show_main_menu')) return # Sleep a bit sleep(delay) # Close progress indicator progress_dialog.close() kodiutils.ok_dialog(message=kodiutils.localize(30703))
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()