def enable_all_custom_sites(): conn = sqlite3.connect(favoritesdb) conn.text_factory = str c = conn.cursor() c.execute("SELECT author, name, title FROM custom_sites WHERE enabled = 0") rows = c.fetchall() conn.close() if not rows: utils.notify('No disabled custom sites found') return if not utils.dialog.yesno('WARNING', 'Custom sites are not verified by Cumination, and could contain malware.[CR]' 'Only enable sites from trusted sources. Proceed?'): return text = '' for author, _, title in rows: text += '{} by {}[CR]'.format(title, author) utils.textBox('Sites to enable', text.strip()) if not utils.dialog.yesno('WARNING', 'Custom sites are not verified by Cumination, and could contain malware.[CR]' 'All custom sites will be enabled.[CR]Continue?'): return conn = sqlite3.connect(favoritesdb) conn.text_factory = str c = conn.cursor() c.execute("UPDATE custom_sites SET enabled = 1 WHERE enabled = 0") conn.commit() conn.close() xbmc.executebuiltin('Container.Refresh') utils.notify("All custom sites enabled")
def disable_all_custom_sites(): conn = sqlite3.connect(favoritesdb) conn.text_factory = str c = conn.cursor() c.execute("SELECT author, name, title FROM custom_sites WHERE enabled = 1") rows = c.fetchall() conn.close() if not rows: utils.notify('No enabled custom sites found') return text = '' for author, _, title in rows: text += '{} by {}[CR]'.format(title, author) utils.textBox('Sites to disable', text.strip()) if not utils.dialog.yesno('WARNING', 'All custom sites will be disabled.[CR]Continue?'): return conn = sqlite3.connect(favoritesdb) conn.text_factory = str c = conn.cursor() c.execute("UPDATE custom_sites SET enabled = 0 WHERE enabled = 1") conn.commit() conn.close() xbmc.executebuiltin('Container.Refresh') utils.notify("All custom sites disabled")
def change(): if addon.getSetting('changelog_seen_version') == utils.__version__ or not os.path.isfile(utils.changelog): return addon.setSetting('changelog_seen_version', utils.__version__) heading = '[B][COLOR hotpink]Whitecream[/COLOR] [COLOR white]Changelog[/COLOR][/B]' with open(utils.changelog) as f: cl_lines = f.readlines() announce = '' for line in cl_lines: if not line.strip(): break announce += line utils.textBox(heading, announce)
def change(): version = addon.getAddonInfo('version') if addon.getSetting('changelog_seen_version') == version or not os.path.isfile(basics.changelog): return addon.setSetting('changelog_seen_version', version) heading = '[B][COLOR hotpink]Cumination[/COLOR] [COLOR white]Changelog[/COLOR][/B]' with open(basics.changelog) as f: cl_lines = f.readlines() announce = '' for line in cl_lines: if not line.strip(): break announce += line utils.textBox(heading, announce)
def list_custom_sites(): def create_text_block(sites): block = '' for site in sites: block += '{}, version {}, created by {}[CR]'.format(site[2], site[3], site[0]) return block sites = select_custom_sites_attributes(None, 'author', 'name', 'title', 'version', 'enabled') if not sites: utils.notify('No custom sites installed') enabled_sites = sorted([site for site in sites if site[4] == 1], key=lambda x: x[2].lower()) disabled_sites = sorted([site for site in sites if site[4] == 0], key=lambda x: x[2].lower()) text = '' if enabled_sites: text += 'Enabled sites:[CR]' text += create_text_block(enabled_sites) + '[CR]' if disabled_sites: text += 'Disabled sites:[CR]' text += create_text_block(disabled_sites) utils.textBox('Installed custom sites', text.strip())
def install_custom_sites_from_folder(): if not utils.dialog.yesno( 'WARNING', 'Custom sites are not verified by Cumination, and could contain malware.[CR]' 'Cumination is not responsible for custom sites. Proceed?'): return path = utils.xbmcgui.Dialog().browseSingle( 0, 'Select directory containing custom sites', 'myprograms') if not path: return progress = utils.progress progress.create('Installing custom sites', 'Searching for files') zips = sorted([ f for f in os.listdir(path) if os.path.isfile(os.path.join(path, f)) and f.endswith('.zip') ], key=lambda x: x[0].lower()) if not zips: utils.notify('Error', 'No files found') progress.close() return utils.textBox('Files found', '[CR]'.join(zips)) if not utils.dialog.yesno( 'WARNING', 'All custom sites from the list will be installed. Proceed?'): progress.close() return successful = [] unsuccessful = [] for idx, zip in enumerate(zips): progress.update(int(idx / len(zips)), "", "Processing {}".format(zip)) success = process_custom_site_zip(os.path.join(path, zip)) if success: successful.append(zip) else: unsuccessful.append(zip) progress.close() text = '' if successful: text += 'Successful:[CR]{}[CR]'.format('[CR]'.join(successful)) if unsuccessful: text += 'Unsuccessful:[CR]{}'.format('[CR]'.join(unsuccessful)) utils.textBox('Installation result', text)
def process_custom_site_zip(path): import json if int(basics.kodiver) == 18: from resources.lib import zfile as zipfile else: import zipfile def move(src, target): frm = os.path.join(basics.tempDir, src) to = os.path.join(basics.customSitesDir, target) os.rename(frm, to) basics.clean_temp() zip = zipfile.ZipFile(path, 'r') try: with zip.open('meta.json') as metafile: meta_data = json.load(metafile) except: zip.close() utils.kodilog('Invalid file') return False name = meta_data['name'] original_module = meta_data['module_name'] author = meta_data['author'] version = meta_data['version'] title = meta_data['title'] url = meta_data['url'] original_image = meta_data.get('image') original_about = meta_data.get('about') if original_about and not original_about.endswith('.txt'): zip.close() utils.kodilog('About file must have .txt extension') return False if original_module and not original_module.endswith('.py'): zip.close() utils.kodilog('Module file must have .py extension') return False checkable = (author, name) checkable_file_names = (original_module, original_about, original_image) invalid_chars = ['\\', '/', ':', '<', '>', '|', '"', '?', '*'] for c in checkable_file_names: if not c: continue for i in invalid_chars: if i in c: zip.close() utils.kodilog('Invalid character ({}) in value of meta data: {}'.format(i, c)) return False invalid_chars.append('.') for c in checkable: if not c: continue for i in invalid_chars: if i in c: zip.close() utils.kodilog('Invalid character ({}) in value of meta data: {}'.format(i, c)) return False extractable = (original_module, original_image, original_about) extracted = [] for e in extractable: if e: if e not in zip.namelist(): zip.close() utils.kodilog('File not found in archive: {}'.format(e)) basics.clean_temp() return False zipfile.ZipFile.extract(zip, e, basics.tempDir) extracted.append(e) zip.close() if len(extracted) == 0: basics.clean_temp() return False already_installed = select_custom_sites_attributes((author, name), 'title', 'version') if already_installed: old_title = already_installed[0][0] old_version = already_installed[0][1] utils.textBox('Site already installed', 'Custom site is already installed[CR]Title: {}[CR]Version: {}[CR][CR]' 'New title: {}[CR]New version: {}[CR]'.format(old_title, old_version, title, version)) if not utils.dialog.yesno('Site already installed', 'Replace version {} with {}?'.format(old_version, version)): basics.clean_temp() return False keep_favorites = utils.dialog.yesno('Site already installed', 'Old favorites and custom list items' ' could be incompatible with the new version. Keep them?') delete_custom_site(author, name, keep_favorites) id = get_new_site_id() new_module = "custom_{}.py".format(id) new_image = "{}_{}_img.{}".format(author, name, original_image.split('.')[-1]) if original_image else None new_about = "{}_{}_about.txt".format(author, name) if original_about else None add_custom_site(author, name, title, url, new_image, new_about.split('.')[0] if new_about else None, version, new_module.split('.')[0]) move(original_module, new_module) if original_image: move(original_image, new_image) if original_about: move(original_about, new_about) basics.clean_temp() return True
def change(): if os.path.isfile(utils.uwcchange): heading = '[B][COLOR hotpink]Whitecream[/COLOR] [COLOR white]Changelog[/COLOR][/B]' utils.textBox(heading, utils.uwcchange) os.remove(utils.uwcchange)
def about_site(name, about, custom): heading = '{0} {1}'.format(utils.i18n('about'), name) dir = basics.customSitesDir if custom else basics.aboutDir with open(TRANSLATEPATH(os.path.join(dir, '{}.txt'.format(about)))) as f: announce = f.read() utils.textBox(heading, announce)
TRANSLATEPATH = xbmcvfs.translatePath if six.PY3 else xbmc.translatePath progress = utils.progress dialog = utils.dialog url_dispatcher = URL_Dispatcher('main') if addon.getSetting('custom_sites') == 'true': sys.path.append(basics.customSitesDir) for module_name in favorites.enabled_custom_sites(): try: importlib.import_module(module_name) except Exception as e: utils.kodilog('{0} {1}: {2}'.format(utils.i18n('err_custom'), module_name, e)) favorites.disable_custom_site_by_module(module_name) title = favorites.get_custom_site_title_by_module(module_name) utils.textBox(utils.i18n('disable_custom'), '{0}:[CR]{1}'.format(utils.i18n('custom_msg'), title)) @url_dispatcher.register() def INDEX(): url_dispatcher.add_dir('[COLOR white]{}[/COLOR]'.format(utils.i18n('sites')), '', 'site_list', basics.cum_image('cum-sites.png'), '', list_avail=False) url_dispatcher.add_dir('[COLOR white]{}[/COLOR]'.format(utils.i18n('fav_videos')), '', 'favorites.List', basics.cum_image('cum-fav.png'), '', list_avail=False) download_path = addon.getSetting('download_path') if download_path != '' and xbmcvfs.exists(download_path): url_dispatcher.add_dir('[COLOR white]{}[/COLOR]'.format(utils.i18n('dnld_folder')), download_path, 'OpenDownloadFolder', basics.cum_image('cum-downloads.png'), '', list_avail=False) url_dispatcher.add_dir('[COLOR white]{}[/COLOR]'.format(utils.i18n('custom_list')), '', 'favorites.create_custom_list', Folder=False, list_avail=False) for rowid, name in favorites.get_custom_lists():