def update_addons(quiet=True): from distutils.version import LooseVersion if not quiet: kodi.open_busy_dialog() sources = DB.query("SELECT addon_id, source FROM install_history") update_count = 0 for source in sources: addon_id = source[0] source = json.loads(source[1]) if kodi.get_condition_visiblity("System.HasAddon(%s)" % addon_id): if source['type'] == SOURCES.ZIP: url, filename, full_name, version = github.find_zip(source['user'], addon_id) current_version = kodi.get_addon(addon_id).getAddonInfo('version') if LooseVersion(version) > LooseVersion(current_version): GitHub_Installer(addon_id, url, full_name, kodi.vfs.join("special://home", "addons"), False, quiet) update_count += 1 elif source['type'] == SOURCES.REPO: full_name = sources['user'] + '/' + sources['repo'] xml_str = github.find_xml(full_name) xml = BeautifulSoup(xml_str) addon = xml.find('addon') current_version = kodi.get_addon(addon_id).getAddonInfo('version') if LooseVersion(addon['version']) > LooseVersion(current_version): GitHub_Installer(addon_id, source['url'], full_name, kodi.vfs.join("special://home", "addons"), True, quiet) update_count += 1 if not quiet: kodi.close_busy_dialog() if update_count > 0: kodi.notify("Update complete",'Some addons may require restarting kodi.') else: kodi.notify("Update complete",'No updates found.')
def main(): menu = kodi.ContextMenu() menu.add( 'Set Default View', { "mode": "set_default_view", "api": { "name": "kodi", "method": "set_default_view", "args": ("list", ) } }) kodi.add_menu_item({'mode': 'tv_menu'}, {'title': "Shows"}, menu=menu, icon='shows.png') kodi.add_menu_item({'mode': 'movie_menu'}, {'title': "Movies"}, menu=menu, icon='movies.png') kodi.add_menu_item( { 'mode': 'execute_api', "api": { "name": "kodi", "method": "go_to_url", "args": ("plugin://plugin.video.scrapecore.bowser", ) } }, {'title': "Bowser"}, menu=menu, icon='bowser.png', visible=kodi.get_condition_visiblity( 'System.HasAddon(plugin.video.scrapecore.bowser)') == 1) kodi.add_menu_item({'mode': 'settings_menu'}, {'title': "Settings and Tools"}, menu=menu, icon='settings.png') kodi.eod(DEFAULT_VIEWS.LIST)
def update_addons(quiet=True): from distutils.version import LooseVersion if not quiet: kodi.open_busy_dialog() sources = DB.query("SELECT addon_id, source FROM install_history") update_count = 0 for source in sources: addon_id = source[0] source = json.loads(source[1]) if kodi.get_condition_visiblity("System.HasAddon(%s)" % addon_id): if source['type'] == SOURCES.ZIP: url, filename, full_name, version = github.find_zip(source['user'], addon_id) current_version = kodi.get_addon(addon_id).getAddonInfo('version') if LooseVersion(version) > LooseVersion(current_version): GitHub_Installer(addon_id, url, full_name, kodi.vfs.join("special://home", "addons"), False, quiet) update_count += 1 elif source['type'] == SOURCES.REPO: full_name = sources['user'] + '/' + sources['repo'] xml_str = github.find_xml(full_name) xml = BeautifulSoup(xml_str) addon = xml.find('addon') current_version = kodi.get_addon(addon_id).getAddonInfo('version') if LooseVersion(addon['version']) > LooseVersion(current_version): GitHub_Installer(addon_id, source['url'], full_name, kodi.vfs.join("special://home", "addons"), True, quiet) update_count += 1 if not quiet: kodi.close_busy_dialog() if update_count > 0: kodi.notify("Update complete",'Some addons may require restarting kodi.') else: kodi.notify("Update complete",'No updates found.')
class mythtvScraper(DirectScraper): valid = kodi.get_condition_visiblity("System.HasAddon(pvr.mythtv)") service = 'mythtv' name = 'MythTV' settings_definition = """ <setting label="MythTV" type="lsep" /> <setting default="false" id="mythtv_enable" type="bool" label="Enable MythTV" visible="System.HasAddon(pvr.mythtv)" enabled="System.HasAddon(pvr.mythtv)" /> <setting label="Requires PVR.MythTV to be enabled" type="text" enable="false" visible="!System.HasAddon(pvr.mythtv)" /> """ def search_shows(self, args): results = [] result = mythtv.search_episodes(args['title'], args['season'], args['episode']) if result: media = { "title": "%s %sx%s" % (args['title'], args['season'], args['episode']), "host": self.name, "host_icon": '', "raw_url": result['url'], "service": self.service, "size": result['size'], "quality": QUALITY.LOCAL, "extension": result['extension'] } results.append(media) results = self.verify_results(self.process_results, results) return results def search_movies(self, args): results = [] result = mythtv.search_movies(args['title'], args['year']) if result: media = { "title": "%s (%s)" % (args['title'], args['year']), "host": self.name, "host_icon": '', "raw_url": result['url'], "service": self.service, "size": result['size'], "quality": QUALITY.LOCAL, "extension": result['extension'] } results.append(media) results = self.verify_results(self.process_results, results) return results
def enable_addon(self, addon_id): try: if addon_id in ['xbmc.python', 'xbmc.gui' ] or kodi.get_condition_visiblity( 'System.HasAddon(%s)' % addon_id) == 1: return True kodi.log("Enable Addon: %s" % addon_id) kodi.kodi_json_request("Addons.SetAddonEnabled", { "addonid": addon_id, "enabled": True }) except: pass
def build_dependency_list(self, addon_id, url, full_name, master): #if test in ['xbmc.python', 'xbmc.gui'] or kodi.get_condition_visiblity('System.HasAddon(%s)' % addon_id) == 1: return True if addon_id in self.installed_list: kodi.log('Dependency is already installed: %s' % addon_id) return True user, repo = full_name.split("/") kodi.log('Finding dependencies for: %s' % addon_id) if master: self.sources[addon_id] = {"type": SOURCES.REPO, "url": url, "user": user, "repo": repo, "version": ""} xml_str = github.find_xml(full_name) self.sources[addon_id]['version'] = github.get_version_by_xml(BeautifulSoup(xml_str)) else: version = downloader.download(url, addon_id, self._destination, True, self.quiet) src_file = kodi.vfs.join("special://home/addons", addon_id) kodi.vfs.join(src_file, "addon.xml") xml = kodi.vfs.read_file(kodi.vfs.join(src_file, "addon.xml"), soup=True) self.save_source(addon_id, {"type": SOURCES.ZIP, "url": url, "user": user, "repo": repo, "version": version}) for dep in xml.findAll('import'): test = dep['addon'] try: if dep['optional'].lower() == 'true': if kodi.get_setting('install_optional') == 'false': continue elif kodi.get_setting('prompt_optional') == "true": c = kodi.dialog_confirm("Install Optional Dependency", dep['name'], dep['addon']) if not c: continue except: pass if test in ['xbmc.python', 'xbmc.gui'] or kodi.get_condition_visiblity('System.HasAddon(%s)' % test) == 1 or test in self.installed_list: kodi.log('Dependency is already installed: %s' % test) continue self.required_addons += [test] if test not in self.available_addons: self.unmet_addons += [test] else: self.sources[test] = {"type": SOURCES.DEFAULT, "url": self.source_table[test]} kodi.log("%s dependency met in %s" % (test, self.source_table[test])) def user_resolver(user, unmet): dep_url, dep_filename, dep_full_name, version = github.find_zip(user, unmet) if dep_url: kodi.log("%s found in %s repo" % (unmet, user)) self.met_addons.append(unmet) user, repo = dep_full_name.split("/") self.sources[unmet] = {"type": SOURCES.ZIP, "url": dep_url, "user": user, "repo": repo, "version": ""} kodi.log("%s dependency met in %s" % (unmet, dep_url)) return True return False def github_resolver(unmet): results = github.web_search(unmet) c = kodi.dialog_select("GitHub Search Results for %s" % unmet, [r['full_name'] for r in results['items']]) if c is not False: dep = results['items'][c] dep_url = url = "https://github.com/%s/archive/master.zip" % (dep['full_name']) self.met_addons.append(unmet) dep_filename = "%s.zip" % unmet self.sources[unmet] = {"type": SOURCES.REPO, "url": dep_url, "user": user, "repo": repo, "version": ""} kodi.log("%s dependency met in %s" % (unmet, dep_url)) self.install_addon(unmet, dep_url, dep['full_name'], master=True) return True return False for unmet in self.unmet_addons: # Now attempt to locate dependencies from available sources # The addons that can be found in any enabled repos will be installed at the end. # check if this exists in users root repo if kodi.get_setting('source_user') == 'true': if user_resolver(user, unmet): continue # check if this exists in tva root repo if kodi.get_setting('source_tva') == 'true': if user_resolver(tva_user, unmet): continue # check if this exists on github if kodi.get_setting('source_github') == 'true': if github_resolver(unmet): continue self.unmet_addons = list(set(self.unmet_addons) - set(self.met_addons)) if len(self.unmet_addons): self.install_error = True if not self.quiet: kodi.close_busy_dialog() kodi.raise_error("", "Unmet Dependencies:", "See log or install manually", ','.join(self.unmet_addons)) kodi.log("Unmet Dependencies for addon install: %s" % addon_id) # % self.addon_id) kodi.log(','.join(self.unmet_addons)) inserts = [(a, ) for a in self.unmet_addons] DB.execute_many("INSERT INTO failed_depends(addon_id) VALUES(?)", inserts) DB.commit() self.completed.append(addon_id)
def install_batch(): import xbmcgui from libs import github from libs import github_installer if kodi.mode == 'install_batch': url = kodi.arg('url') xml, zip_ref = github.batch_installer(url) else: url = kodi.dialog_file_browser('Select a install file', mask='.zip') if not github.re_installer.search(url): return xml, zip_ref = github.batch_installer(url, True) if not kodi.dialog_confirm('Batch Installer?', "Click YES to proceed.", "This will install a list of addons.", "Some configuration files and settings may be overwritten."): return if not xml: return # Install each addon as instructed installed_list = [] count = 0 for a in xml.findAll('addon'): count +=1 PB = kodi.ProgressBar() PB.new('Batch Installer - Progress', count) for a in xml.findAll('addon'): addon_id = a.find('addon_id') username = a.find('username') if addon_id is None or username is None: continue username = username.text addon_id = addon_id.text PB.next(addon_id) if not kodi.get_condition_visiblity("System.HasAddon(%s)"% addon_id): if PB.is_canceled(): return kodi.log("Batch install " + addon_id) url, filename, full_name, version = github.find_zip(username, addon_id) installed_list += github_installer.GitHub_Installer(addon_id, url, full_name, kodi.vfs.join("special://home", "addons"), quiet=True, batch=True, installed_list=installed_list).installed_list kodi.sleep(1000) # Look for config files. # Need to add error checking for missing config files configs= xml.find('configs') if configs is not None and 'dir' in configs.attrs[0]: config_dir = configs['dir'] for config in configs.findAll('config'): source = config.find('source') destination = config.find('destination') if source is None or destination is None: continue source = source.text destination = destination.text if not kodi.vfs.exists(destination): kodi.vfs.mkdir(destination, True) kodi.vfs.write_file(kodi.vfs.join(destination, source), zip_ref.read(config_dir + '/' + source)) # Now look for individual setting key and value pairs # Set them as instructed settings= xml.find('settings') if settings is not None: for setting in settings.findAll('setting'): if 'addon_id' in setting.attrs[0]: addon_id = setting['addon_id'] k = setting.find('key') v = setting.find('value') if k is None or v is None: continue kodi.set_setting(k.text, v.text, addon_id) builtins= xml.find('builtins') if builtins is not None: for cmd in builtins.findAll('command'): cmd = cmd.text kodi.run_command(cmd) jsonrpc= xml.find('jsonrpc') if jsonrpc is not None: from ast import literal_eval for cmd in jsonrpc.findAll('command'): method = cmd.find('method').text params = literal_eval(cmd.find('params').text) id = cmd.find('id').text kodi.kodi_json_request(method, params, id) # Now clean up zip_ref.close() PB.close() r = kodi.dialog_confirm(kodi.get_name(), 'Click Continue to install more addons or', 'Restart button to finalize addon installation', yes='Restart', no='Continue') if r: import sys import xbmc if sys.platform in ['linux', 'linux2', 'win32']: xbmc.executebuiltin('RestartApp') else: xbmc.executebuiltin('ShutDown')
def install_batch(): import xbmcgui from libs import github from libs import github_installer if kodi.mode == 'install_batch': url = kodi.arg('url') xml, zip_ref = github.batch_installer(url) else: url = kodi.dialog_file_browser('Select a install file', mask='.zip') if not github.re_installer.search(url): return xml, zip_ref = github.batch_installer(url, True) if not kodi.dialog_confirm('Batch Installer?', "Click YES to proceed.", "This will install a list of addons.", "Some configuration files and settings may be overwritten."): return if not xml: return # Install each addon as instructed installed_list = [] count = 0 for a in xml.findAll('addon'): count +=1 PB = kodi.ProgressBar() PB.new('Batch Installer - Progress', count) for a in xml.findAll('addon'): addon_id = a.find('addon_id') username = a.find('username') if addon_id is None or username is None: continue username = username.text addon_id = addon_id.text PB.next(addon_id) if not kodi.get_condition_visiblity("System.HasAddon(%s)"% addon_id): if PB.is_canceled(): return kodi.log("Batch install " + addon_id) url, filename, full_name, version = github.find_zip(username, addon_id) installed_list += github_installer.GitHub_Installer(addon_id, url, full_name, kodi.vfs.join("special://home", "addons"), quiet=True, batch=True, installed_list=installed_list).installed_list kodi.sleep(1000) # Look for config files. # Need to add error checking for missing config files configs= xml.find('configs') if configs is not None and 'dir' in configs.attrs[0]: config_dir = configs['dir'] for config in configs.findAll('config'): source = config.find('source') destination = config.find('destination') if source is None or destination is None: continue source = source.text destination = destination.text if not kodi.vfs.exists(destination): kodi.vfs.mkdir(destination, True) kodi.vfs.write_file(kodi.vfs.join(destination, source), zip_ref.read(config_dir + '/' + source)) # Now look for individual setting key and value pairs # Set them as instructed settings= xml.find('settings') if settings is not None: for setting in settings.findAll('setting'): if 'addon_id' in setting.attrs[0]: addon_id = setting['addon_id'] k = setting.find('key') v = setting.find('value') if k is None or v is None: continue kodi.set_setting(k.text, v.text, addon_id) builtins= xml.find('builtins') if builtins is not None: for cmd in builtins.findAll('command'): cmd = cmd.text kodi.run_command(cmd) jsonrpc= xml.find('jsonrpc') if jsonrpc is not None: from ast import literal_eval for cmd in jsonrpc.findAll('command'): method = cmd.find('method').text params = literal_eval(cmd.find('params').text) id = cmd.find('id').text kodi.kodi_json_request(method, params, id) # Now clean up zip_ref.close() PB.close() r = kodi.dialog_confirm(kodi.get_name(), 'Click Continue to install more addons or', 'Restart button to finalize addon installation', yes='Restart', no='Continue') if r: import sys import xbmc if sys.platform in ['linux', 'linux2', 'win32']: xbmc.executebuiltin('RestartApp') else: xbmc.executebuiltin('ShutDown')
def enable_addon(self, addon_id): try: if addon_id in ['xbmc.python', 'xbmc.gui'] or kodi.get_condition_visiblity('System.HasAddon(%s)' % addon_id) == 1: return True kodi.log("Enable Addon: %s" % addon_id) kodi.kodi_json_request("Addons.SetAddonEnabled", {"addonid": addon_id, "enabled": True}) except: pass
def build_dependency_list(self, addon_id, url, full_name, master): #if test in ['xbmc.python', 'xbmc.gui'] or kodi.get_condition_visiblity('System.HasAddon(%s)' % addon_id) == 1: return True if addon_id in self.installed_list: kodi.log('Dependency is already installed: %s' % addon_id) return True user, repo = full_name.split("/") kodi.log('Finding dependencies for: %s' % addon_id) if master: self.sources[addon_id] = {"type": SOURCES.REPO, "url": url, "user": user, "repo": repo, "version": ""} xml_str = github.find_xml(full_name) self.sources[addon_id]['version'] = github.get_version_by_xml(BeautifulSoup(xml_str)) else: version = downloader.download(url, addon_id, self._destination, True, self.quiet) src_file = kodi.vfs.join("special://home/addons", addon_id) kodi.vfs.join(src_file, "addon.xml") xml = kodi.vfs.read_file(kodi.vfs.join(src_file, "addon.xml"), soup=True) self.save_source(addon_id, {"type": SOURCES.ZIP, "url": url, "user": user, "repo": repo, "version": version}) for dep in xml.findAll('import'): test = dep['addon'] try: if dep['optional'].lower() == 'true': if kodi.get_setting('install_optional') == 'false': continue elif kodi.get_setting('prompt_optional') == "true": c = kodi.dialog_confirm("Install Optional Dependency", dep['name'], dep['addon']) if not c: continue except: pass if test in ['xbmc.python', 'xbmc.gui'] or kodi.get_condition_visiblity('System.HasAddon(%s)' % test) == 1 or test in self.installed_list: kodi.log('Dependency is already installed: %s' % test) continue self.required_addons += [test] if test not in self.available_addons: self.unmet_addons += [test] else: self.sources[test] = {"type": SOURCES.DEFAULT, "url": self.source_table[test]} kodi.log("%s dependency met in %s" % (test, self.source_table[test])) def user_resolver(user, unmet): dep_url, dep_filename, dep_full_name, version = github.find_zip(user, unmet) if dep_url: kodi.log("%s found in %s repo" % (unmet, user)) self.met_addons.append(unmet) user, repo = dep_full_name.split("/") self.sources[unmet] = {"type": SOURCES.ZIP, "url": dep_url, "user": user, "repo": repo, "version": ""} kodi.log("%s dependency met in %s" % (unmet, dep_url)) return True return False def github_resolver(unmet): results = github.web_search(unmet) c = kodi.dialog_select("GitHub Search Results for %s" % unmet, [r['full_name'] for r in results['items']]) if c is not False: dep = results['items'][c] dep_url = url = "https://github.com/%s/archive/master.zip" % (dep['full_name']) self.met_addons.append(unmet) dep_filename = "%s.zip" % unmet self.sources[unmet] = {"type": SOURCES.REPO, "url": dep_url, "user": user, "repo": repo, "version": ""} kodi.log("%s dependency met in %s" % (unmet, dep_url)) self.install_addon(unmet, dep_url, dep['full_name'], master=True) return True return False for unmet in self.unmet_addons: # Now attempt to locate dependencies from available sources # The addons that can be found in any enabled repos will be installed at the end. # check if this exists in users root repo if kodi.get_setting('source_user') == 'true': if user_resolver(user, unmet): continue # check if this exists in tva root repo if kodi.get_setting('source_tva') == 'true': if user_resolver(tva_user, unmet): continue # check if this exists on github if kodi.get_setting('source_github') == 'true': if github_resolver(unmet): continue self.unmet_addons = list(set(self.unmet_addons) - set(self.met_addons)) if len(self.unmet_addons): self.install_error = True if not self.quiet: kodi.close_busy_dialog() kodi.raise_error("", "Unmet Dependencies:", "See log or install manually", ','.join(self.unmet_addons)) kodi.log("Unmet Dependencies for addon install: %s" % addon_id) # % self.addon_id) kodi.log(','.join(self.unmet_addons)) self.completed.append(addon_id)