def _check_updates(): _time = int(time()) if _time < settings.getInt('_last_updates_check', 0) + UPDATES_CHECK_TIME: return settings.setInt('_last_updates_check', _time) new_md5 = session.get(ADDONS_MD5).text.split(' ')[0] if new_md5 == settings.get('addon_md5'): return settings.set('_addon_md5', new_md5) updates = [] slyguy_addons = session.gz_json(ADDONS_URL) slyguy_installed = [x['addonid'] for x in kodi_rpc('Addons.GetAddons', {'installed': True, 'enabled': True})['addons'] if x['addonid'] in slyguy_addons] for addon_id in slyguy_installed: addon = get_addon(addon_id, install=False) if not addon: continue cur_version = addon.getAddonInfo('version') new_version = slyguy_addons[addon_id]['version'] if LooseVersion(cur_version) < LooseVersion(new_version): updates.append([addon_id, cur_version, new_version]) if not updates: return log.debug('Updating repos due to {} addon updates'.format(len(updates))) xbmc.executebuiltin('UpdateAddonRepos')
def _interact_thread(): if gui.yes_no(news['message'], news.get('heading', _.NEWS_HEADING)): addon = get_addon(news['addon_id'], install=True) if not addon: return url = router.url_for('', _addon_id=news['addon_id']) xbmc.executebuiltin('ActivateWindow(Videos,{})'.format(url))
def _check_news(): _time = int(time()) if _time < userdata.get('last_news_check', 0) + NEWS_CHECK_TIME: return userdata.set('last_news_check', _time) news = session.gz_json(NEWS_URL) if not news: return if 'id' not in news or news['id'] == userdata.get('last_news_id'): return userdata.set('last_news_id', news['id']) if _time > news.get('timestamp', _time) + NEWS_MAX_TIME: log.debug("news is too old to show") return if news['type'] == 'next_plugin_msg': userdata.set('_next_plugin_msg', news['message']) elif news['type'] == 'addon_release': if news.get('requires') and not get_addon(news['requires'], install=False): log.debug('addon_release {} requires addon {} which is not installed'.format(news['addon_id'], news['requires'])) return if get_addon(news['addon_id'], install=False): log.debug('addon_release {} already installed'.format(news['addon_id'])) return def _interact_thread(): if gui.yes_no(news['message'], news.get('heading', _.NEWS_HEADING)): addon = get_addon(news['addon_id'], install=True) if not addon: return url = router.url_for('', _addon_id=news['addon_id']) xbmc.executebuiltin('ActivateWindow(Videos,{})'.format(url)) thread = Thread(target=_interact_thread) thread.daemon = True thread.start()
def iptv_is_setup(): addon = get_addon(IPTV_SIMPLE_ID, required=False, install=False) if not addon: return False output_dir = settings.get('output_dir', '').strip() or ADDON_PROFILE playlist_path = os.path.join(output_dir, PLAYLIST_FILE_NAME) epg_path = os.path.join(output_dir, EPG_FILE_NAME) return addon.getSetting('m3uPathType') == '0' and addon.getSetting('epgPathType') == '0' \ and addon.getSetting('m3uPath') == playlist_path and addon.getSetting('epgPath') == epg_path
def merge_info(addon_id, merging=False): addon = get_addon(addon_id, required=True, install=False) addon_path = xbmc.translatePath(addon.getAddonInfo('path')) merge_path = os.path.join(addon_path, MERGE_SETTING_FILE) data = {} if os.path.exists(merge_path): try: with codecs.open(merge_path, 'r', encoding='utf8') as f: data = json.load(f) data['type'] = TYPE_IPTV_MERGE except Exception as e: log.exception(e) log.debug('failed to parse merge file: {}'.format(merge_path)) return addon, {} elif addon.getSetting('iptv.enabled'): data = { 'type': TYPE_IPTV_MANAGER, 'playlist': addon.getSetting('iptv.channels_uri'), 'epg': addon.getSetting('iptv.epg_uri'), } elif addon_id.lower() in INTEGRATIONS: data = INTEGRATIONS[addon_id.lower()] data['type'] = TYPE_INTEGRATION elif merging: raise Error('No integration found for this source') min_version = data.get('min_version') max_version = data.get('max_version') current_version = LooseVersion(addon.getAddonInfo('version')) if min_version and current_version < LooseVersion(min_version): if merging: raise Error('Min version {} required'.format(min_version)) else: data = {} if max_version and current_version > LooseVersion(max_version): if merging: raise Error('Max version {} exceeded'.format(max_version)) else: data = {} return addon, data
def merge_info(addon_id, integrations=None, merging=False): addon = get_addon(addon_id, required=True, install=False) addon_path = xbmc.translatePath(addon.getAddonInfo('path')) merge_path = os.path.join(addon_path, MERGE_SETTING_FILE) if os.path.exists(merge_path): try: with codecs.open(merge_path, 'r', encoding='utf8') as f: data = json.load(f) except Exception as e: log.exception(e) log.debug('failed to parse merge file: {}'.format(merge_path)) return addon, {} else: if integrations is None: integrations = get_integrations() data = integrations.get(addon_id) or {} if merging: if not integrations: raise Error('Failed to download integrations') elif not data: raise Error('No integration found for this source') min_version = data.get('min_version') max_version = data.get('max_version') current_version = LooseVersion(addon.getAddonInfo('version')) if min_version and current_version < LooseVersion(min_version): if merging: raise Error('Min version {} required'.format(min_version)) else: data = {} if max_version and current_version > LooseVersion(max_version): if merging: raise Error('Max version {} exceeded'.format(max_version)) else: data = {} return addon, data
def _setup(): addon = get_addon(IPTV_SIMPLE_ID, required=True, install=True) with gui.progress(_.SETTING_UP_IPTV) as progress: kodi_rpc('Addons.SetAddonEnabled', {'addonid': IPTV_SIMPLE_ID, 'enabled': False}) output_dir = settings.get('output_dir', '').strip() or ADDON_PROFILE playlist_path = os.path.join(output_dir, PLAYLIST_FILE_NAME) epg_path = os.path.join(output_dir, EPG_FILE_NAME) ## IMPORT ANY CURRENT URL SOURCES ## cur_epg_url = addon.getSetting('epgUrl') cur_epg_type = addon.getSetting('epgPathType') if cur_epg_url: epg = EPG(source_type=EPG.TYPE_URL, path=cur_epg_url, enabled=cur_epg_type == '1') try: epg.save() except: pass cur_m3u_url = addon.getSetting('m3uUrl') cur_m3u_type = addon.getSetting('m3uPathType') start_chno = int(addon.getSetting('startNum') or 1) #user_agent = addon.getSetting('userAgent') if cur_m3u_url: playlist = Playlist(source_type=Playlist.TYPE_URL, path=cur_m3u_url, enabled=cur_m3u_type == '1') if start_chno != 1: playlist.use_start_chno = True playlist.start_chno = start_chno try: playlist.save() except: pass ################################ addon.setSetting('epgPath', epg_path) addon.setSetting('m3uPath', playlist_path) addon.setSetting('epgUrl', '') addon.setSetting('m3uUrl', '') addon.setSetting('m3uPathType', '0') addon.setSetting('epgPathType', '0') monitor = xbmc.Monitor() progress.update(30) monitor.waitForAbort(2) kodi_rpc('Addons.SetAddonEnabled', {'addonid': IPTV_SIMPLE_ID, 'enabled': True}) progress.update(60) monitor.waitForAbort(2) progress.update(100) set_kodi_setting('epg.futuredaystodisplay', 7) # set_kodi_setting('epg.ignoredbforclient', True) set_kodi_setting('pvrmanager.syncchannelgroups', True) set_kodi_setting('pvrmanager.preselectplayingchannel', True) set_kodi_setting('pvrmanager.backendchannelorder', True) set_kodi_setting('pvrmanager.usebackendchannelnumbers', True) set_kodi_string('_iptv_merge_force_run', '1') gui.ok(_.SETUP_IPTV_COMPLETE) return True
def open_settings(addon_id, **kwargs): get_addon(addon_id, required=True).openSettings()
def _setup(): addon = get_addon(IPTV_SIMPLE_ID, required=True, install=True) with gui.progress(_.SETTING_UP_IPTV) as progress: kodi_rpc('Addons.SetAddonEnabled', {'addonid': IPTV_SIMPLE_ID, 'enabled': False}) output_dir = xbmc.translatePath(settings.get('output_dir', '').strip() or ADDON_PROFILE) playlist_path = os.path.join(output_dir, PLAYLIST_FILE_NAME) epg_path = os.path.join(output_dir, EPG_FILE_NAME) if not os.path.exists(playlist_path): with open(playlist_path, 'w') as f: f.write('''#EXTM3U #EXTINF:-1 tvg-id="iptv_merge" tvg-chno="1000" tvg-logo="{}",{} {}'''.format(ADDON_ICON, 'IPTV Merge: Click me to run a merge!', plugin.url_for(merge))) if not os.path.exists(epg_path): with open(epg_path, 'w') as f: f.write('''<?xml version="1.0" encoding="utf-8" ?><tv><channel id="iptv_merge"></channel></tv>''') ## IMPORT ANY CURRENT SOURCES ## cur_epg_url = addon.getSetting('epgUrl') cur_epg_path = addon.getSetting('epgPath') cur_epg_type = addon.getSetting('epgPathType') if cur_epg_path != epg_path and os.path.exists(xbmc.translatePath(cur_epg_path)): epg = EPG(source_type=EPG.TYPE_FILE, path=cur_epg_path, enabled=cur_epg_type == '0') epg.auto_archive_type() try: epg.save() except: pass if cur_epg_url: epg = EPG(source_type=EPG.TYPE_URL, path=cur_epg_url, enabled=cur_epg_type == '1') epg.auto_archive_type() try: epg.save() except: pass cur_m3u_url = addon.getSetting('m3uUrl') cur_m3u_path = addon.getSetting('m3uPath') cur_m3u_type = addon.getSetting('m3uPathType') start_chno = int(addon.getSetting('startNum') or 1) #user_agent = addon.getSetting('userAgent') if cur_m3u_path != playlist_path and os.path.exists(xbmc.translatePath(cur_m3u_path)): playlist = Playlist(source_type=Playlist.TYPE_FILE, path=cur_m3u_path, enabled=cur_m3u_type == '0') playlist.auto_archive_type() if start_chno != 1: playlist.use_start_chno = True playlist.start_chno = start_chno try: playlist.save() except: pass if cur_m3u_url: playlist = Playlist(source_type=Playlist.TYPE_URL, path=cur_m3u_url, enabled=cur_m3u_type == '1') playlist.auto_archive_type() if start_chno != 1: playlist.use_start_chno = True playlist.start_chno = start_chno try: playlist.save() except: pass ##### addon.setSetting('epgPath', epg_path) addon.setSetting('m3uPath', playlist_path) addon.setSetting('epgUrl', '') addon.setSetting('m3uUrl', '') addon.setSetting('m3uPathType', '0') addon.setSetting('epgPathType', '0') monitor = xbmc.Monitor() progress.update(30) monitor.waitForAbort(2) kodi_rpc('Addons.SetAddonEnabled', {'addonid': IPTV_SIMPLE_ID, 'enabled': True}) progress.update(60) monitor.waitForAbort(2) progress.update(100) set_kodi_setting('epg.futuredaystodisplay', 7) # set_kodi_setting('epg.ignoredbforclient', True) set_kodi_setting('pvrmanager.syncchannelgroups', True) set_kodi_setting('pvrmanager.preselectplayingchannel', True) set_kodi_setting('pvrmanager.backendchannelorder', True) set_kodi_setting('pvrmanager.usebackendchannelnumbers', True) gui.ok(_.SETUP_IPTV_COMPLETE) return True
def _setup(check_only=False, reinstall=True, run_merge=True): addon = get_addon(IPTV_SIMPLE_ID, required=not check_only, install=not check_only) if not addon: return False output_dir = settings.get('output_dir', '').strip() or ADDON_PROFILE playlist_path = os.path.join(output_dir, PLAYLIST_FILE_NAME) epg_path = os.path.join(output_dir, EPG_FILE_NAME) is_setup = addon.getSetting('m3uPathType') == '0' and addon.getSetting('epgPathType') == '0' \ and addon.getSetting('m3uPath') == playlist_path and addon.getSetting('epgPath') == epg_path if check_only: return is_setup elif is_setup and not reinstall: if run_merge: set_kodi_string('_iptv_merge_force_run', '1') return True ## IMPORT ANY CURRENT URL SOURCES ## cur_epg_url = addon.getSetting('epgUrl') cur_epg_type = addon.getSetting('epgPathType') if cur_epg_url: epg = EPG(source_type=EPG.TYPE_URL, path=cur_epg_url, enabled=cur_epg_type == '1') try: epg.save() except: pass cur_m3u_url = addon.getSetting('m3uUrl') cur_m3u_type = addon.getSetting('m3uPathType') start_chno = int(addon.getSetting('startNum') or 1) #user_agent = addon.getSetting('userAgent') if cur_m3u_url: playlist = Playlist(source_type=Playlist.TYPE_URL, path=cur_m3u_url, enabled=cur_m3u_type == '1') if start_chno != 1: playlist.use_start_chno = True playlist.start_chno = start_chno try: playlist.save() except: pass ################################ addon.setSetting('epgPath', epg_path) addon.setSetting('m3uPath', playlist_path) addon.setSetting('epgUrl', '') addon.setSetting('m3uUrl', '') addon.setSetting('m3uPathType', '0') addon.setSetting('epgPathType', '0') set_kodi_setting('epg.futuredaystodisplay', 7) # set_kodi_setting('epg.ignoredbforclient', True) set_kodi_setting('pvrmanager.syncchannelgroups', True) set_kodi_setting('pvrmanager.preselectplayingchannel', True) set_kodi_setting('pvrmanager.backendchannelorder', True) set_kodi_setting('pvrmanager.usebackendchannelnumbers', True) if run_merge: set_kodi_string('_iptv_merge_force_run', '1') gui.ok(_.SETUP_IPTV_COMPLETE) return True