def install_package(self, install_style): self.deploy_init() if install_style == None: install_style = tools.showDialog.select( tools.addonName, ['Browse...', 'Web Location...']) else: install_style = int(install_style) if install_style == 0: zip_location = tools.fileBrowser(1, 'Locate Provider Zip', 'files', '.zip', True, False) elif install_style == 1: zip_location = tools.showKeyboard( '', '%s: Enter Zip URL' % tools.addonName) zip_location.doModal() if zip_location.isConfirmed() and zip_location.getText() != '': zip_location = zip_location.getText() else: return else: return zip_file = self.get_zip_file(zip_location) if zip_file is None: return self.install_zip(zip_file)
def showsByActor(self, actionArgs): if actionArgs == None: k = tools.showKeyboard('', tools.lang(32016)) k.doModal() query = (k.getText() if k.isConfirmed() else None) if query == None or query == '': tools.cancel_directory() return else: query = tools.unquote(actionArgs) database.addSearchHistory(query, 'showActor') query = tools.deaccentString(query) query = query.replace(' ', '-') query = tools.quote_plus(query) trakt_list = trakt.json_response('people/%s/shows' % query, limit=True) try: trakt_list = trakt_list['cast'] except: import traceback traceback.print_exc() trakt_list = [] trakt_list = [i['show'] for i in trakt_list] self.showListBuilder(trakt_list) tools.closeDirectory('tvshows')
def moviesSearch(self): k = tools.showKeyboard('', tools.lang(32016).encode('utf-8')) k.doModal() query = (k.getText() if k.isConfirmed() else None) if query == None or query == '': return query = tools.deaccentString(query.encode('utf-8')) query = tools.quote_plus(query) traktList = trakt.json_response('search/movie?query=%s' % query) self.commonListBuilder(traktList) tools.closeDirectory('movies', viewType=self.viewType)
def showsSearch(self): k = tools.showKeyboard('', tools.lang(32016)) k.doModal() query = (k.getText() if k.isConfirmed() else None) if query == None or query == '': return query = tools.deaccentString(query) query = tools.quote_plus(query) traktList = trakt.json_response('search/show?query=%s&extended=full' % query, limit=True) self.showListBuilder(traktList) tools.closeDirectory('tvshows')
def moviesSearch(self, actionArgs=None): if actionArgs == None: k = tools.showKeyboard('', tools.lang(32016)) k.doModal() query = (k.getText() if k.isConfirmed() else None) if query == None or query == '': return else: query = actionArgs database.addSearchHistory(query, 'movie') query = tools.deaccentString(tools.display_string(query)) tools.quote(query) tools.closeAllDialogs() tools.closeDirectory('movies') tools.execute("Container.Update(%s?action=moviesSearchResults&actionArgs=%s, replace)'" % (sysaddon, query))
def showsSearch(self, actionArgs=None): if actionArgs == None: k = tools.showKeyboard('', tools.lang(32016)) k.doModal() query = (k.getText() if k.isConfirmed() else None) if query == None or query == '': tools.cancel_directory() return else: query = actionArgs query = query.decode('utf-8') database.addSearchHistory(query, 'show') query = tools.deaccentString(tools.display_string(query)) query = tools.quote(query) self.showsSearchResults(query)
def moviesSearch(self, actionArgs=None): if actionArgs == None: k = tools.showKeyboard('', tools.lang(32016).encode('utf-8')) k.doModal() query = (k.getText() if k.isConfirmed() else None) if query == None or query == '': return else: query = actionArgs database.addSearchHistory(query, 'movie') query = tools.deaccentString(query.encode('utf-8')) query = tools.quote_plus(query) trakt_list = trakt.json_response('search/movie?query=%s' % query) if trakt_list is None: return self.commonListBuilder(trakt_list) tools.closeDirectory('movies', viewType=self.viewType)
def _get_zip_location(self): zip_location = None install_type = tools.showDialog.select(tools.addonName, [tools.lang(40302), tools.lang(40303)]) if install_type == -1: return None if install_type == 0: zip_location = tools.fileBrowser(1, tools.lang(40304), 'files', '.zip', True, False) elif install_type == 1: user_input = tools.showKeyboard('', '%s: %s' % (tools.addonName, tools.lang(40305))) user_input.doModal() if user_input.isConfirmed() and user_input.getText() != '': zip_location = user_input.getText() else: return return zip_location
def showsSearch(self, actionArgs): if actionArgs == None: k = tools.showKeyboard('', tools.lang(32016).encode('utf-8')) k.doModal() query = (k.getText() if k.isConfirmed() else None) if query == None or query == '': return else: query = actionArgs database.addSearchHistory(query, 'show') query = tools.deaccentString(query) query = tools.quote_plus(query) trakt_list = trakt.json_response('search/show?query=%s&extended=full' % query, limit=True) if trakt_list is None: return self.showListBuilder(trakt_list) tools.closeDirectory('tvshows')
def install_package(self, install_style, url=None): self.deploy_init() if url is None: if install_style is None: install_style = tools.showDialog.select( tools.addonName, [tools.lang(40302), tools.lang(40303)]) else: install_style = int(install_style) if install_style == 0: zip_location = tools.fileBrowser( 1, tools.lang(40304).format('Provider'), 'files', '.zip', True, False) elif install_style == 1: zip_location = tools.showKeyboard( '', '%s: %s' % (tools.addonName, tools.lang(40305))) zip_location.doModal() if zip_location.isConfirmed() and zip_location.getText() != '': zip_location = zip_location.getText() else: return else: return else: zip_location = url if url is not None: zip_file = self.get_zip_file(zip_location, True) else: zip_file = self.get_zip_file(zip_location, False) if zip_file is None: return self.install_zip(zip_file)
def install_zip(install_style): folders = ['providerModules/', 'providers/'] deploy_init() if install_style == None: browse_download = tools.showDialog.select(tools.addonName, [tools.lang(40302), tools.lang(40303)]) if browse_download == 0: zip_location = tools.fileBrowser(1, tools.lang(40304), 'files', '.zip', True, False) elif browse_download == 1: zip_location = tools.showKeyboard('', '%s: %s' % (tools.addonName, tools.lang(40305))) zip_location.doModal() if zip_location.isConfirmed() and zip_location.getText() != '': zip_location = zip_location.getText() else: return else: return else: if install_style == '0': zip_location = tools.fileBrowser(1, tools.lang(40304), 'files', '.zip', True, False) if install_style == '1': zip_location = tools.showKeyboard('', '%s: %s' % (tools.addonName, tools.lang(40305))) zip_location.doModal() if zip_location.isConfirmed() and zip_location.getText() != '': zip_location = zip_location.getText() else: return if zip_location == '': return if zip_location.startswith('smb'): tools.showDialog.ok(tools.addonName, tools.lang(40309)) return if zip_location.startswith('http'): response = requests.get(zip_location, stream=True) if not response.ok: tools.showDialog.ok(tools.addonName, tools.lang(40310)) else: pass try: import StringIO file = zipfile.ZipFile(StringIO.StringIO(response.content)) except: #Python 3 Support import io file = zipfile.ZipFile(io.BytesIO(response.content)) else: file = zipfile.ZipFile(zip_location) file_list = file.namelist() for i in file_list: if i.startswith('/') or '..' in i: raise Exception meta_file = None for i in file_list: if i.startswith('meta.json'): meta_file = i if meta_file is not None: meta = file.open(meta_file) meta = meta.readlines() meta = ''.join(meta) meta = meta.replace(' ', '').replace('\r','').replace('\n','') meta = json.loads(meta) requirements = ['author', 'name', 'version'] for i in requirements: if i not in meta: malformed_output() return author = meta['author'] version = meta['version'] pack_name = meta['name'] else: malformed_output() import traceback traceback.print_exc() raise Exception line1 = tools.colorString('{}: '.format(tools.lang(40311))) + '{} - v{}'.format(pack_name, version) line2 = tools.colorString('{}: '.format(tools.lang(40312))) + "%s" % author line3 = tools.lang(40313) accept = tools.showDialog.yesno("{} - {}".format(tools.addonName, tools.lang(40314)), line1, line2, line3, tools.lang(40315), tools.lang(40316)) if accept == 0: return install_progress = tools.progressDialog install_progress.create(tools.addonName, '%s - %s' % (tools.lang(40317), pack_name), tools.lang(33009)) install_progress.update(-1) try: for folder in folders: for zip_file in file_list: if zip_file.startswith(folder): file.extract(zip_file, tools.dataPath) try: file.close() install_progress.close() except: pass tools.showDialog.ok(tools.addonName, '%s - %s' % (tools.lang(40318), pack_name)) except: import traceback traceback.print_exc() install_progress.close() tools.showDialog.ok(tools.addonName, '%s - %s' % (tools.lang(40319), pack_name), tools.lang(40320)) return customProviders.providers().update_known_providers()
def install_zip(install_style): folders = ['providerModules/', 'providers/'] deploy_init() if install_style == None: browse_download = tools.showDialog.select( tools.addonName, ['Browse...', 'Web Location...']) if browse_download == 0: zip_location = tools.fileBrowser(1, 'Locate Provider Zip', 'files', '.zip', True, False) elif browse_download == 1: zip_location = tools.showKeyboard( '', '%s: Enter Zip URL' % tools.addonName) zip_location.doModal() if zip_location.isConfirmed() and zip_location.getText() != '': zip_location = zip_location.getText() else: return else: return else: if install_style == '0': zip_location = tools.fileBrowser(1, 'Locate Provider Zip', 'files', '.zip', True, False) if install_style == '1': zip_location = tools.showKeyboard( '', '%s: Enter Zip URL' % tools.addonName) zip_location.doModal() if zip_location.isConfirmed() and zip_location.getText() != '': zip_location = zip_location.getText() else: return if zip_location == '': return if zip_location.startswith('smb'): tools.showDialog.ok(tools.addonName, 'Sorry, SMB shares are not supported') return if zip_location.startswith('http'): response = requests.get(zip_location, stream=True) if not response.ok: tools.showDialog.ok( tools.addonName, 'Unable to connect to file.\n' 'Please check URL and try again.') else: pass try: import StringIO file = zipfile.ZipFile(StringIO.StringIO(response.content)) except: #Python 3 Support import io file = zipfile.ZipFile(io.BytesIO(response.content)) else: file = zipfile.ZipFile(zip_location) file_list = file.namelist() for i in file_list: if i.startswith('/') or '..' in i: raise Exception meta_file = None for i in file_list: if i.startswith('meta.json'): meta_file = i if meta_file is not None: meta = file.open(meta_file) meta = meta.readlines() meta = ''.join(meta) meta = meta.replace(' ', '').replace('\r', '').replace('\n', '') meta = json.loads(meta) requirements = ['author', 'name', 'version'] for i in requirements: if i not in meta: malformed_output() return author = meta['author'] version = meta['version'] pack_name = meta['name'] else: malformed_output() import traceback traceback.print_exc() raise Exception line1 = tools.colorString('Installing:') + " %s - v%s" % (pack_name, version) line2 = tools.colorString("Author: ") + "%s" % author line3 = "Are you sure you wish to proceed?" accept = tools.showDialog.yesno( tools.addonName + " - Custom Sources Install", line1, line2, line3, "Cancel", "Install") if accept == 0: return install_progress = tools.progressDialog install_progress.create(tools.addonName, 'Extracting - %s' % pack_name, 'Please Wait...') install_progress.update(-1) try: for folder in folders: for zip_file in file_list: if zip_file.startswith(folder): file.extract(zip_file, tools.dataPath) try: file.close() install_progress.close() except: pass tools.showDialog.ok(tools.addonName, 'Successfully Installed - %s' % pack_name) except: import traceback traceback.print_exc() install_progress.close() tools.showDialog.ok(tools.addonName, 'Failed to install - %s', 'Please check the log for further details') return customProviders.providers().update_known_providers()