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 install_feed(url, local=False): import requests from commoncore import zipfile if kodi.strings.PY2: from cStringIO import StringIO as byte_reader else: from io import BytesIO as byte_reader from commoncore.beautifulsoup import BeautifulSoup if local: r = kodi.vfs.open(url, "r") if kodi.strings.PY2: zip_ref = zipfile.ZipFile(byte_reader(r.read())) else: zip_ref = zipfile.ZipFile(byte_reader(r.readBytes())) else: r = requests.get(url, stream=True) zip_ref = zipfile.ZipFile(byte_reader(r.content)) for f in zip_ref.namelist(): if f.endswith(".xml"): xml = BeautifulSoup(zip_ref.read(f)) return xml return False
def browse_repository(url): import requests from commoncore import zipfile from commoncore.beautifulsoup import BeautifulSoup r = requests.get(url, stream=True) if kodi.strings.PY2: import StringIO zip_ref = zipfile.ZipFile(StringIO.StringIO(r.content)) else: from io import BytesIO zip_ref = zipfile.ZipFile(BytesIO(r.content)) for f in zip_ref.namelist(): if f.endswith('addon.xml'): xml = BeautifulSoup(zip_ref.read(f)) url = xml.find('info').text xml = BeautifulSoup(requests.get(url).text) return xml return False
def get_content(self, response): _type = type(response) if self.default_return_type == 'json': if _type in [TYPES.TEXT, TYPES.UTF8, TYPES.STR]: return json.loads(response) elif self.default_return_type == 'xml': import xml.etree.ElementTree as ET if type(response) == unicode: response = response.encode("utf-8", errors="ignore") return ET.fromstring(response) elif self.default_return_type == 'soup': return BeautifulSoup(response) elif self.default_return_type == 'html_dom': return dom_parser.parse_html(response) return response
def batch_installer(url, local=False): import requests from commoncore import zipfile if kodi.strings.PY2: from StringIO import StringIO as byte_reader else: from io import BytesIO as byte_reader from commoncore.beautifulsoup import BeautifulSoup if local: r = kodi.vfs.open(url, "r") if kodi.strings.PY2: zip_ref = zipfile.ZipFile(byte_reader(r.read())) else: zip_ref = zipfile.ZipFile(byte_reader(r.readBytes())) else: r = requests.get(url, stream=True) zip_ref = zipfile.ZipFile(byte_reader(r.content)) xml = BeautifulSoup(zip_ref.read('manifest.xml')) return xml, zip_ref
def read_file(path, soup=False, json=False, mode=''): try: if mode=='b': file = _open(path, 'rb') else: file = _open(path, 'r') content=file.read() file.close() if soup: from commoncore.beautifulsoup import BeautifulSoup soup = BeautifulSoup(content) return soup elif json: try: import simplejson as json except ImportError: import json return json.loads(content) else: return content except IOError as e: xbmc.log('******** VFS error: %s' % e) return None
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)