def restore(): backup = dialog.browse(1, utils.get_string(32098), 'files', mask='.zip', defaultt=_backup_location) if backup.endswith('zip'): with zipfile.ZipFile(backup, 'r') as z: info = z.infolist() choice = dialog.yesno( 'AutoWidget', utils.get_string(32099).format(len(info), 's' if len(info) > 1 else '')) if choice: overwrite = dialog.yesno('AutoWidget', utils.get_string(32100)) if overwrite: files = [ x for x in os.listdir(utils._addon_path) if x.endswith('.group') ] for file in files: utils.remove_file(file) z.extractall(utils._addon_path) else: dialog.notification('AutoWidget', utils.get_string(32101)) else: dialog.notification('AutoWidget', utils.get_string(32101)) return
def restore(): dialog = xbmcgui.Dialog() backup = dialog.browse( 1, utils.get_string(30075), "files", mask=".zip", defaultt=_backup_location ) if backup.endswith("zip"): with zipfile.ZipFile(backup, "r") as z: info = z.infolist() choice = dialog.yesno( "AutoWidget", utils.get_string(30076).format(len(info), "s" if len(info) > 1 else ""), ) if choice: overwrite = dialog.yesno("AutoWidget", utils.get_string(30077)) if overwrite: files = [x for x in os.listdir(_addon_data) if x.endswith(".group")] for file in files: utils.remove_file(file) z.extractall(_addon_data) else: dialog.notification("AutoWidget", utils.get_string(30078)) del dialog else: dialog.notification("AutoWidget", utils.get_string(30078)) del dialog return
def _show_options(group_def, path_def=None, type=''): edit_def = path_def if path_def else group_def options = _get_options(edit_def) remove_label = utils.get_string(32025) if path_def else utils.get_string(32023) options.append(u'[COLOR firebrick]{}[/COLOR]'.format(six.ensure_text(remove_label))) if not type: target = path_def['target'] if path_def else group_def['type'] if target not in ['shortcut', 'widget', 'settings']: main_action = utils.get_string(32140) else: main_action = utils.get_string(32048) if target in ['shortcut', 'settings'] else utils.get_string(32141) else: main_action = utils.get_string(32061) idx = dialog.select(main_action, options) if idx < 0: return elif idx == len(options) - 1: if path_def: _remove_path(path_def['id'], group_def['id']) utils.update_container(group_def['type'] == 'shortcut') else: _remove_group(group_def['id']) utils.update_container(group_def['type'] == 'shortcut') return else: key = _clean_key(options[idx]) return _get_value(edit_def, key)
def _copy_path(path_def): group_id = add_group(path_def["target"], path_def["label"]) if not group_id: return progress = xbmcgui.DialogProgressBG() progress.create("AutoWidget", utils.get_string(30143)) progress.update(1, "AutoWidget", utils.get_string(30144)) group_def = manage.get_group_by_id(group_id) files, hash = refresh.get_files_list(path_def["file"]["file"], background=False) if not files: progress.close() return done = 0 for file in files: done += 1 if file["type"] in ["movie", "episode", "musicvideo", "song"]: continue progress.update( int(done / float(len(files)) * 100), heading=utils.get_string(30143), message=file.get("label"), ) labels = build_labels("json", file, path_def["target"]) _add_path(group_def, labels, over=True) progress.close() del progress dialog = xbmcgui.Dialog() dialog.notification( "AutoWidget", utils.get_string(30105).format(len(files), group_def["label"]) ) del dialog
def tools_menu(): directory.add_menu_item( title=32006, params={"mode": "force"}, art=utils.get_art("refresh"), info={"plot": utils.get_string(32020)}, isFolder=False, ) directory.add_menu_item( title=32129, params={"mode": "clean"}, art=utils.get_art("spray-bottle"), isFolder=False, ) directory.add_menu_item( title=32064, params={"mode": "wipe"}, art=utils.get_art("remove"), isFolder=False, ) directory.add_menu_item( title=32127, params={"mode": "skindebug"}, art=utils.get_art("bug-outline"), isFolder=False, ) return True, utils.get_string(32008)
def edit_widget_dialog(widget_id): dialog = xbmcgui.Dialog() updated = False if advanced and not warning_shown: _warn() widget_def = manage.get_widget_by_id(widget_id) if not widget_def: return options = _get_widget_options(widget_def) remove_label = utils.get_string(32025) if widget_id else utils.get_string( 32023) options.append('[COLOR firebrick]{}[/COLOR]'.format(remove_label)) idx = dialog.select(utils.get_string(32048), options) if idx < 0: return elif idx == len(options) - 1: _remove_widget(widget_id) utils.update_container() return else: key = _clean_key(options[idx]) updated = _get_widget_value(widget_def, key) utils.log(updated, xbmc.LOGNOTICE) if updated: convert.save_path_details(widget_def, widget_id) utils.update_container() edit_widget_dialog(widget_id)
def my_groups_menu(): groups = manage.find_defined_groups() if len(groups) > 0: for group in groups: _id = uuid.uuid4() group_name = group['label'] group_id = group['id'] group_type = group['type'] cm = [(utils.get_string(32061), ('RunPlugin(' 'plugin://plugin.program.autowidget/' '?mode=manage' '&action=edit' '&group={})').format(group_id))] directory.add_menu_item( title=group_name, params={ 'mode': 'group', 'group': group_id, 'target': group_type, 'id': six.text_type(_id) }, info=group.get('info'), art=group.get('art') or (folder_shortcut if group_type == 'shortcut' else folder_sync), cm=cm, isFolder=True) else: directory.add_menu_item(title=32068, art=alert, isFolder=False) return True, utils.get_string(32007)
def backup(): choice = dialog.yesno('AutoWidget', utils.get_string(32094)) if choice: filename = dialog.input(utils.get_string(32095)) if not filename: dialog.notification('AutoWidget', utils.get_string(32096)) return if not os.path.exists(_backup_location): try: os.makedirs(_backup_location) except Exception as e: utils.log(str(e), 'error') dialog.notification('AutoWidget', utils.get_string(32097)) return files = [ x for x in os.listdir(utils._addon_path) if x.endswith('.group') ] if len(files) == 0: dialog.notification('AutoWidget', utils.get_string(32068)) return path = os.path.join(_backup_location, '{}.zip'.format(filename.replace('.zip', ''))) content = six.BytesIO() with zipfile.ZipFile(content, 'w', zipfile.ZIP_DEFLATED) as z: for file in files: with open(os.path.join(utils._addon_path, file), 'r') as f: z.writestr(file, six.ensure_text(f.read())) with open(path, 'wb') as f: f.write(content.getvalue())
def my_groups_menu(): groups = manage.find_defined_groups() if len(groups) > 0: for group in groups: group_name = group['label'] group_id = group['id'] group_type = group['type'] cm = [(utils.get_string(32061), ('RunPlugin(' 'plugin://plugin.program.autowidget/' '?mode=manage' '&action=edit' '&group={})').format(group_id))] directory.add_menu_item( title=six.text_type(group_name), params={ 'mode': 'group', 'group': group_id }, info=group.get('info', {}), art=group.get('art') or (utils.get_art('folder-shortcut') if group_type == 'shortcut' else utils.get_art('folder-sync')), cm=cm, isFolder=True) else: directory.add_menu_item(title=32068, art=utils.get_art('alert'), isFolder=False, props={'specialsort': 'bottom'}) return True, utils.get_string(32007)
def _create_context_items(group_id, path_id, idx, length): cm = [(utils.get_string(32048), ('RunPlugin(' 'plugin://plugin.program.autowidget/' '?mode=manage' '&action=edit' '&group={}' '&path={})').format(group_id, path_id))] if idx > 0: cm.append( (utils.get_string(32026), ('RunPlugin(' 'plugin://plugin.program.autowidget/' '?mode=manage' '&action=shift_path' '&target=up' '&group={}' '&path={})').format(group_id, path_id))) if idx < length - 1: cm.append( (utils.get_string(32027), ('RunPlugin(' 'plugin://plugin.program.autowidget/' '?mode=manage' '&action=shift_path' '&target=down' '&group={}' '&path={})').format(group_id, path_id))) return cm
def add_group(target, group_name=""): dialog = xbmcgui.Dialog() group_name = dialog.input(heading=utils.get_string(30023), defaultt=group_name) group_id = "" if group_name: group_id = utils.get_unique_id(group_name) filename = os.path.join(_addon_data, "{}.group".format(group_id)) group_def = { "label": group_name, "type": target, "paths": [], "id": group_id, "art": folder_sync if target == "widget" else folder_shortcut, "version": settings.get_addon_info("version"), "content": None, } utils.write_json(filename, group_def) else: dialog.notification("AutoWidget", utils.get_string(30024)) del dialog return group_id
def restore(): backup = dialog.browse(1, utils.get_string(32098), "files", mask=".zip", defaultt=_backup_location) if backup.endswith("zip"): with zipfile.ZipFile(backup, "r") as z: info = z.infolist() choice = dialog.yesno( "AutoWidget", utils.get_string(32099).format(len(info), "s" if len(info) > 1 else ""), ) if choice: overwrite = dialog.yesno("AutoWidget", utils.get_string(32100)) if overwrite: files = [ x for x in os.listdir(utils._addon_path) if x.endswith(".group") ] for file in files: utils.remove_file(file) z.extractall(utils._addon_path) else: dialog.notification("AutoWidget", utils.get_string(32101)) else: dialog.notification("AutoWidget", utils.get_string(32101)) return
def _create_group_context_items(group_id, target): cm = [ ( utils.get_string(30042), ( "RunPlugin(" "plugin://plugin.program.autowidget/" "?mode=manage" "&action=edit" "&group={})" ).format(group_id), ), ( utils.get_string(30120), ( "RunPlugin(" "plugin://plugin.program.autowidget/" "?mode=manage" "&action=copy" "&group={}" "&target={})" ).format(group_id, target), ), ] return cm
def _get_options(edit_def, useThumbs=None): options = [] all_keys = sorted(edit_def.keys()) base_keys = [i for i in all_keys if i in filter['include']] option_keys = [i for i in (all_keys if advanced else base_keys) if i not in filter['exclude']] for key in option_keys: if key in edit_def and (edit_def[key] not in [None, "", -1]): if key in utils.art_types: li = xbmcgui.ListItem('[B]{}[/B]: {}'.format(key, edit_def[key])) li.setArt({'icon': edit_def[key]}) options.append(li) elif key == 'color': options.append('[B]{0}[/B]: [COLOR {1}]{1}[/COLOR]'.format(key, edit_def[key])) else: formatted_key = '[COLOR goldenrod]{}[/COLOR]'.format(key) if key not in filter['include'] else key if isinstance(edit_def[key], dict): label = ', '.join(edit_def[key].keys()) options.append('[B]{}[/B]: {}'.format(formatted_key, label)) else: v = edit_def[key] try: v = edit_def[key].encode('utf-8') except: pass options.append('[B]{}[/B]: {}'.format(formatted_key, v)) if useThumbs is not None: new_item = xbmcgui.ListItem(utils.get_string(32077) if not useThumbs else utils.get_string(32078)) new_item.setArt(plus) options.append(new_item) return options
def remove_widget(widget_id, over=False): if not over: choice = dialog.yesno("AutoWidget", utils.get_string(30025)) if over or choice: file = os.path.join(utils._addon_path, "{}.widget".format(widget_id)) utils.remove_file(file) dialog.notification("AutoWidget", utils.get_string(30030).format(widget_id))
def remove_widget(widget_id, over=False): if not over: choice = dialog.yesno('AutoWidget', utils.get_string(32039)) if over or choice: file = os.path.join(utils._addon_path, '{}.widget'.format(widget_id)) utils.remove_file(file) dialog.notification('AutoWidget', utils.get_string(32045).format(widget_id))
def _get_widget_options(edit_def): options = [] all_keys = sorted(edit_def.keys()) base_keys = [i for i in all_keys if i in widget_filter["include"]] option_keys = [ i for i in (all_keys if advanced else base_keys) if i not in widget_filter["exclude"] ] for key in option_keys: if key in edit_def and (edit_def[key] and edit_def[key] != -1): formatted_key = ("[COLOR goldenrod]{}[/COLOR]".format(key) if key not in widget_filter["include"] else key) _def = edit_def[key] label = _def if key == 'action': if label == 'random': label = utils.get_string(32079) elif label == 'randomized': label = utils.get_string(32242) elif label == 'next': label = utils.get_string(32080) elif label in ['merged', 'static']: continue elif key == "refresh": if edit_def["action"] in ["static", "merged"]: continue hh = int(_def) mm = int((_def * 60) % 60) if hh and mm: label = "{}h {}m".format(hh, mm) elif not mm: label = "{}h".format(hh) elif not hh: label = "{}m".format(mm) elif key == "path": if edit_def["action"] not in ["static", "merged"]: continue paths = [] if isinstance(_def, list): for i in _def: paths.append(i["label"]) label = ", ".join(paths) else: label = _def try: label = six.ensure_text(label) except: pass options.append("[B]{}[/B]: {}".format(formatted_key, label)) return options
def _remove_widget(widget_id): dialog = xbmcgui.Dialog() choice = dialog.yesno('AutoWidget', utils.get_string(32039)) if choice: file = os.path.join(_addon_path, '{}.widget'.format(widget_id)) utils.remove_file(file) dialog.notification('AutoWidget', utils.get_string(32045).format(widget_id))
def tools_menu(): directory.add_menu_item(title=32006, params={'mode': 'force'}, art=refresh, info={'plot': utils.get_string(32020)}, isFolder=False) directory.add_menu_item(title=32064, params={'mode': 'wipe'}, art=remove, isFolder=False) return True, utils.get_string(32008)
def _remove_group(group_id, over=False): group_def = manage.get_group_by_id(group_id) group_name = group_def['label'] if not over: choice = dialog.yesno('AutoWidget', utils.get_string(32039)) if over or choice: file = os.path.join(utils._addon_path, '{}.group'.format(group_id)) utils.remove_file(file) dialog.notification('AutoWidget', utils.get_string(32045).format(group_name))
def _remove_group(group_id, over=False): group_def = manage.get_group_by_id(group_id) group_name = group_def["label"] if not over: choice = dialog.yesno("AutoWidget", utils.get_string(32039)) if over or choice: file = os.path.join(utils._addon_path, "{}.group".format(group_id)) utils.remove_file(file) dialog.notification( "AutoWidget", utils.get_string(32045).format(six.text_type(group_name)))
def _get_widget_options(edit_def): options = [] all_keys = sorted(edit_def.keys()) base_keys = [i for i in all_keys if i in widget_filter["include"]] option_keys = [ i for i in (all_keys if advanced else base_keys) if i not in widget_filter["exclude"] ] for key in option_keys: if key in edit_def and (edit_def[key] and edit_def[key] != -1): formatted_key = ("[COLOR goldenrod]{}[/COLOR]".format(key) if key not in widget_filter["include"] else key) _def = edit_def[key] label = _def if key == "action": if label == "random": label = utils.get_string(30057) elif label == "next": label = utils.get_string(30058) elif label in ["merged", "static"]: continue elif key == "refresh": if edit_def["action"] in ["static", "merged"]: continue hh = int(_def) mm = int((_def * 60) % 60) if hh and mm: label = "{}h {}m".format(hh, mm) elif not mm: label = "{}h".format(hh) elif not hh: label = "{}m".format(mm) elif key == "path": if edit_def["action"] not in ["static", "merged"]: continue paths = [] if isinstance(_def, list): for i in _def: paths.append(i["label"]) label = ", ".join(paths) else: label = _def try: options.append("[B]{}[/B]: {}".format(formatted_key, label)) except UnicodeEncodeError: options.append("[B]{}[/B]: {}".format(formatted_key, label.encode("utf-8"))) return options
def _get_options(edit_def, base_key='', use_thumbs=False): label = '' options = [] all_keys = sorted([i for i in edit_def.keys() if i not in exclude]) base_keys = sorted([ i for i in all_keys if any(i in x for x in [safe, utils.art_types, utils.info_types]) ]) keys = all_keys if advanced else base_keys for key in keys: disp = '[COLOR goldenrod]{}[/COLOR]'.format( key) if key not in safe else key disp = disp if key not in utils.info_types else key _def = edit_def[key] if isinstance(_def, dict): _keys = sorted(_def.keys()) if key == 'art': arts = [i for i in _keys if _def[i]] label = ' / '.join(arts) elif key == 'info': label = ', '.join(_keys) elif key in edit_def: if key in utils.art_types: if edit_def[key]: item = xbmcgui.ListItem('{}: {}'.format( key, edit_def[key])) if use_thumbs: item.setArt({'icon': edit_def[key]}) options.append(item) else: label = _def if not label: label = 'n/a' try: label = label.encode('utf-8') except: pass if base_key != 'art': options.append('{}: {}'.format(disp, label)) if base_key == 'info': options.append(utils.get_string(32077)) elif base_key == 'art': options.append(utils.get_string(32078)) return options
def _warn(): choice = dialog.yesno('AutoWidget', utils.get_string(32058), yeslabel=utils.get_string(32059), nolabel=utils.get_string(32060)) if choice < 1: utils.set_setting('context.advanced', 'false') utils.set_setting('context.warning', 'true') advanced = False warning = True else: utils.set_setting('context.warning', 'true') warning = True
def _get_widget_options(edit_def): options = [] all_keys = sorted(edit_def.keys()) base_keys = [i for i in all_keys if i in widget_filter['include']] option_keys = [ i for i in (all_keys if advanced else base_keys) if i not in widget_filter['exclude'] ] for key in option_keys: if key in edit_def and (edit_def[key] and edit_def[key] != -1): formatted_key = '[COLOR goldenrod]{}[/COLOR]'.format( key) if key not in widget_filter['include'] else key _def = edit_def[key] label = _def if key == 'action': if label == 'random': label = utils.get_string(32079) elif label == 'next': label = utils.get_string(32080) elif label in ['merged', 'static']: continue elif key == 'refresh': hh = int(_def) mm = int((_def * 60) % 60) if hh and mm: label = '{}h {}m'.format(hh, mm) elif not mm: label = '{}h'.format(hh) elif not hh: label = '{}m'.format(mm) elif key == 'path': if edit_def['action'] not in ['static', 'merged']: continue paths = [] if isinstance(_def, list): for i in _def: paths.append(i['label']) label = ', '.join(paths) else: label = _def['label'] try: label = label.encode('utf-8') except: pass options.append('[B]{}[/B]: {}'.format(formatted_key, label)) return options
def _add_path(group_def, labels, over=False): if not over: if group_def['type'] == 'shortcut': heading = utils.get_string(32043) elif group_def['type'] == 'widget': heading = utils.get_string(32044) labels['label'] = dialog.input(heading=heading, defaultt=labels['label']) labels['id'] = utils.get_unique_id(labels['label']) labels['version'] = utils._addon_version manage.write_path(group_def, path_def=labels)
def _get_widget_value(edit_def, key): dialog = xbmcgui.Dialog() if key not in widget_safe: title = utils.get_string(32063).format(key.capitalize()) elif key in edit_def: title = key.capitalize() if key == 'action': actions = [utils.get_string(32079), utils.get_string(32080)] choice = dialog.select(utils.get_string(32081), actions) if choice < 0: return value = actions[choice].split(' ')[0].lower() elif key == 'refresh': durations = [] d = 0.25 while d <= 12: hh = int(d) mm = int((d * 60) % 60) if hh and mm: label = '{}h {}m'.format(hh, mm) elif not mm: label = '{}h'.format(hh) elif not hh: label = '{}m'.format(mm) durations.append(label) d = d + 0.25 choice = dialog.select('Refresh Duration', durations) if choice < 0: return duration = durations[choice].split(' ') if len(duration) > 1: value = float(duration[0][:-1]) + (float(duration[1][:-1]) / 60) else: if 'm' in duration[0]: value = float(duration[0][:-1]) / 60 elif 'h' in duration[0]: value = float(duration[0][:-1]) else: default = edit_def.get(key) value = dialog.input(title, defaultt=six.text_type(default)) if value: edit_def[key] = value return edit_def[key]
def _warn(): dialog = xbmcgui.Dialog() choice = dialog.yesno( "AutoWidget", utils.get_string(30039), yeslabel=utils.get_string(30040), nolabel=utils.get_string(30041), ) del dialog if choice < 1: settings.set_setting_bool("context.advanced", False) settings.set_setting_bool("context.warning", True) else: settings.set_setting_bool("context.warning", True)
def _remove_path(path_id, group_id, over=False): if not over: choice = dialog.yesno('AutoWidget', utils.get_string(32035)) if over or choice: group_def = manage.get_group_by_id(group_id) paths = group_def['paths'] for path_def in paths: if path_def['id'] == path_id: path_name = path_def['label'] group_def['paths'].remove(path_def) dialog.notification('AutoWidget', utils.get_string(32045).format(path_name)) manage.write_path(group_def)
def _remove_group(group_id, over=False): dialog = xbmcgui.Dialog() group_def = manage.get_group_by_id(group_id) group_name = group_def["label"] if not over: choice = dialog.yesno("AutoWidget", utils.get_string(30025)) if over or choice: file = os.path.join(_addon_data, "{}.group".format(group_id)) utils.remove_file(file) dialog.notification( "AutoWidget", utils.get_string(30030).format(six.text_type(group_name))) del dialog