def call_path(group_id, path_id): path_def = manage.get_path_by_id(path_id, group_id=group_id) if not path_def: return xbmc.executebuiltin('Dialog.Close(busydialog)') final_path = '' if path_def['target'] == 'shortcut' and path_def['is_folder'] == 0 \ and path_def['content'] != 'addons': if path_def['path'] == 'addons://install/': final_path = 'InstallFromZip' elif 'plugin.video.youtube' in path_def['path']: final_path = 'RunPlugin({})'.format(path_def['path']) elif path_def['path'].startswith('androidapp://sources/apps/'): final_path = 'StartAndroidActivity({})'.format( path_def['path'].replace('androidapp://sources/apps/', '')) elif all(i in path_def['path'] for i in ['(', ')']) and '://' not in path_def['path']: final_path = path_def['path'] else: final_path = 'PlayMedia({})'.format(path_def['path']) elif path_def['target'] == 'widget' or path_def['is_folder'] == 1 \ or path_def['content'] == 'addons': final_path = 'ActivateWindow({},{},return)'.format( path_def['window'], path_def['path']) elif path_def['target'] == 'settings': final_path = 'Addon.OpenSettings({})'.format(path_def['path'].replace( 'plugin://', '')) if final_path: xbmc.executebuiltin(final_path)
def update_path(widget_id, target, path=None): widget_def = manage.get_widget_by_id(widget_id) if not widget_def: return stack = widget_def.get("stack", []) if target == "next" and path: utils.log("Next Page selected from {}".format(widget_id), "debug") path_def = manage.get_path_by_id(widget_def["path"], widget_def["group"]) if isinstance(path_def, dict): widget_def["label"] = path_def["label"] stack.append(path) widget_def["stack"] = stack elif target == "back" and widget_def.get("stack"): utils.log("Previous Page selected from {}".format(widget_id), "debug") widget_def["stack"] = widget_def["stack"][:-1] elif target == "reset": if len(stack) > 0: # simple compatibility with pre-3.3.0 widgets if isinstance(stack[0], dict): widget_def["path"] = stack[0].get("id", "") widget_def["stack"] = [] manage.save_path_details(widget_def) _update_strings(widget_def) utils.update_container(True) back_to_top(target)
def refresh(widget_id, widget_def=None, paths=None, force=False, single=False): if not widget_def: widget_def = manage.get_widget_by_id(widget_id) if widget_def["action"] in ["static", "merged"]: return paths current_time = time.time() updated_at = widget_def.get("updated", 0) default_refresh = settings.get_setting_float("service.refresh_duration") refresh_duration = float(widget_def.get("refresh", default_refresh)) if updated_at <= current_time - (3600 * refresh_duration) or force: group_id = widget_def["group"] action = widget_def.get("action") current = int(widget_def.get("current", 0)) widget_def["stack"] = [] if not paths: cycle_paths = widget_def.get("cycle_paths") if cycle_paths is None: cycle_paths = [ p.get("id") for p in manage.find_defined_paths(group_id) ] widget_def["cycle_paths"] = cycle_paths paths = [p for p in cycle_paths] if action: if len(paths) > 0: next = 0 if action == "next": next = (current + 1) % len(paths) elif action == "random": random.shuffle(paths) next = random.randrange(len(paths)) widget_def["current"] = next path_id = paths[next] paths.remove(paths[next]) widget_def["path"] = path_id if widget_def["path"]: path_label = manage.get_path_by_id(path_id, group_id).get( "label", "") widget_def["label"] = path_label widget_def["updated"] = 0 if force else current_time manage.save_path_details(widget_def) _update_strings(widget_def) if single: utils.update_container(True) return paths
def merged_path(group_id, widget_id): _window = utils.get_active_window() group_def = manage.get_group_by_id(group_id) group_name = group_def.get("label", "") paths = group_def.get("paths", []) if len(paths) == 0: directory.add_menu_item(title=30019, art=utils.get_art("alert"), isFolder=False) return True, group_name, None widget_def = manage.get_widget_by_id(widget_id, group_id) if widget_def and _window != "dialog": paths = widget_def["path"] elif not widget_def: idxs = manage.choose_paths(utils.get_string(30089), paths, 5) if idxs is not None: if len(idxs) > 0: widget_def = manage.initialize(group_def, "merged", widget_id, keep=idxs) paths = widget_def["path"] if widget_def: titles = [] for idx, path in enumerate(paths): # simple compatibility with pre-3.3.0 widgets if isinstance(path, dict): path = path.get("id", "") paths[idx] = path widget_def["path"] = paths manage.save_path_details(widget_def) path_def = manage.get_path_by_id(path, group_id) titles, cat, type = show_path( group_id, path_def["label"], widget_id, path_def, idx=idx, titles=titles, num=len(paths), merged=True, ) return titles, cat, type else: directory.add_menu_item(title=30045, art=info, isFolder=True) return True, group_name, None
def call_path(path_id): path_def = manage.get_path_by_id(path_id) if not path_def: return utils.call_builtin("Dialog.Close(busydialog)", 500) final_path = "" if path_def["target"] == "settings": final_path = "Addon.OpenSettings({})".format( path_def["file"]["file"] .replace("plugin://", "") .replace("script://", "") .split("/")[0] ) elif ( path_def["target"] == "shortcut" and path_def["file"]["filetype"] == "file" and path_def["content"] != "addons" ): if path_def["file"]["file"] == "addons://install/": final_path = "InstallFromZip" elif not path_def["content"] or path_def["content"] == "files": if path_def["file"]["file"].startswith("androidapp://sources/apps/"): final_path = "StartAndroidActivity({})".format( path_def["file"]["file"].replace("androidapp://sources/apps/", "") ) elif path_def["file"]["file"].startswith("pvr://"): final_path = "PlayMedia({})".format(path_def["file"]["file"]) else: final_path = "RunPlugin({})".format(path_def["file"]["file"]) elif ( all(i in path_def["file"]["file"] for i in ["(", ")"]) and "://" not in path_def["file"]["file"] ): final_path = path_def["file"]["file"] else: final_path = "PlayMedia({})".format(path_def["file"]["file"]) elif ( path_def["target"] == "widget" or path_def["file"]["filetype"] == "directory" or path_def["content"] == "addons" ): final_path = "ActivateWindow({},{},return)".format( path_def.get("window", "Videos"), path_def["file"]["file"] ) if final_path: utils.log("Calling path from {} using {}".format(path_id, final_path), "debug") utils.call_builtin(final_path)
def edit_dialog(group_id, path_id=None, base_key=None): updated = False if advanced and not warning_shown: _warn() group_def = manage.get_group_by_id(group_id) path_def = manage.get_path_by_id(path_id, group_id) if not group_def or path_id and not path_def: return updated = _show_options(group_def, path_def) if updated: manage.write_path(group_def, path_def=path_def, update=path_id) utils.update_container(group_def['type'] == 'shortcut') edit_dialog(group_id, path_id)
def edit_dialog(group_id, path_id=''): dialog = xbmcgui.Dialog() updated = False if advanced and not warning_shown: _warn() group_def = manage.get_group_by_id(group_id) if not group_def: return if path_id: path_def = manage.get_path_by_id(path_id, group_id) if not path_def: return edit_def = path_def if path_id else group_def options = _get_options(edit_def) remove_label = utils.get_string(32025) if path_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: if path_id: _remove_path(path_id, group_id) utils.update_container(group_def['type']) else: _remove_group(group_id) utils.update_container(group_def['type']) return else: key = _clean_key(options[idx]) updated = _get_value(edit_def, key) utils.log(updated, xbmc.LOGNOTICE) if updated: if path_id: manage.write_path(group_def, path_def=path_def, update=path_id) else: manage.write_path(group_def) utils.update_container(group_def['type']) edit_dialog(group_id, path_id)
def call_path(path_id): path_def = manage.get_path_by_id(path_id) if not path_def: return utils.call_builtin('Dialog.Close(busydialog)', 500) final_path = '' if path_def['target'] == 'shortcut' and path_def['file']['filetype'] == 'file' \ and path_def['content'] != 'addons': if path_def['file']['file'] == 'addons://install/': final_path = 'InstallFromZip' elif not path_def['content'] or path_def['content'] == 'files': if path_def['file']['file'].startswith( 'androidapp://sources/apps/'): final_path = 'StartAndroidActivity({})'.format( path_def['file']['file'].replace( 'androidapp://sources/apps/', '')) elif path_def['file']['file'].startswith('pvr://'): final_path = 'PlayMedia({})'.format(path_def['file']['file']) else: final_path = 'RunPlugin({})'.format(path_def['file']['file']) elif all( i in path_def['file']['file'] for i in ['(', ')']) and '://' not in path_def['file']['file']: final_path = path_def['file']['file'] else: final_path = 'PlayMedia({})'.format(path_def['file']['file']) elif path_def['target'] == 'widget' or path_def['file']['filetype'] == 'directory' \ or path_def['content'] == 'addons': final_path = 'ActivateWindow({},{},return)'.format( path_def.get('window', 'Videos'), path_def['file']['file']) elif path_def['target'] == 'settings': final_path = 'Addon.OpenSettings({})'.format( path_def['file']['file'].replace('plugin://', '')) if final_path: utils.log('Calling path from {} using {}'.format(path_id, final_path), 'debug') utils.call_builtin(final_path) return False, path_def['label']
def active_widgets_menu(): widgets = manage.find_defined_widgets() if len(widgets) > 0: for widget_def in widgets: _id = widget_def.get('id', '') action = widget_def.get('action', '') group = widget_def.get('group', '') path = widget_def.get('path', '') updated = widget_def.get('updated', '') path_def = manage.get_path_by_id(path, group) group_def = manage.get_group_by_id(group) title = '' if path_def and group_def: try: path_def['label'] = path_def['label'].encode('utf-8') group_def['label'] = group_def['label'].encode('utf-8') except: pass title = '{} - {}'.format(path_def['label'], group_def['label']) elif group_def: title = group_def.get('label') art = {} params = {} if not action: art = folder_shortcut params = { 'mode': 'group', 'group': group, 'target': 'shortcut', 'id': six.text_type(_id) } title = utils.get_string(32030).format(title) elif action in ['random', 'next']: art = folder_sync if action == 'random' else folder_next params = { 'mode': 'group', 'group': group, 'target': 'widget', 'id': six.text_type(_id) } cm = [(utils.get_string(32069), ('RunPlugin(' 'plugin://plugin.program.autowidget/' '?mode=refresh' '&target={})').format(_id)), (utils.get_string(32070), ('RunPlugin(' 'plugin://plugin.program.autowidget/' '?mode=manage' '&action=edit_widget' '&target={})').format(_id))] if not group_def: title = '{} - [COLOR firebrick]{}[/COLOR]'.format( _id, utils.get_string(32071)) directory.add_menu_item(title=title, art=art, params=params, cm=cm[1:] if not action else cm, isFolder=True) else: directory.add_menu_item(title=32072, art=alert, isFolder=False) return True, utils.get_string(32074)
def path_menu(group_id, action, widget_id): group_def = manage.get_group_by_id(group_id) if not group_def: directory.add_menu_item( title=30051, info={"plot": utils.get_string(30053)}, art=utils.get_art("alert"), isFolder=True, ) return True, "AutoWidget", None group_name = group_def.get("label", "") paths = group_def.get("paths", []) if len(paths) == 0: directory.add_menu_item(title=30019, art=utils.get_art("alert"), isFolder=True) return True, group_name, None widget_def = manage.get_widget_by_id(widget_id, group_id) if not widget_def: dialog = xbmcgui.Dialog() if action == "static": idx = manage.choose_paths(utils.get_string(30088), paths, indices=True, single=True) if idx == -1: return True, "AutoWidget", None widget_def = manage.initialize(group_def, action, widget_id, keep=idx) elif action == "cycling": idx = dialog.select( utils.get_string(30059), [utils.get_string(30057), utils.get_string(30058)], ) if idx == -1: del dialog return True, "AutoWidget", None _action = "random" if idx == 0 else "next" cycle_paths = manage.choose_paths(utils.get_string(30123), paths, threshold=-1, indices=True) widget_def = manage.initialize(group_def, _action, widget_id, keep=cycle_paths) del dialog if widget_def: widget_path = widget_def.get("path", "") # simple compatibility with pre-3.3.0 widgets if isinstance(widget_path, dict): widget_path = widget_def.get("path", {}).get("id", "") widget_def["path"] = widget_path manage.save_path_details(widget_def) widget_path = manage.get_path_by_id(widget_path, group_id) _label = "" if isinstance(widget_path, dict): _label = widget_path.get("label", "") utils.log("Showing widget {}".format(widget_id), "debug") titles, cat, type = show_path(group_id, _label, widget_id, widget_path) return titles, cat, type else: directory.add_menu_item(title=30045, art=info, isFolder=True) return True, group_name, None
def active_widgets_menu(): widgets = sorted(manage.clean(all=True), key=lambda x: x.get("updated", 0), reverse=True) if len(widgets) > 0: for widget_def in widgets: widget_id = widget_def.get("id", "") action = widget_def.get("action", "") group = widget_def.get("group", "") path_id = widget_def.get("path", {}) group_def = manage.get_group_by_id(group) path_def = manage.get_path_by_id(path_id, group) title = "" label = group_def.get("label", "") if path_def and group_def: try: if action != "merged": label = path_def.get("label", "").encode("utf-8") else: label = utils.get_string(30102).format(len(path_id)) except: pass title = "{} - {}".format( six.ensure_text(label), six.ensure_text(group_def.get("label", ""))) elif group_def: title = group_def.get("label") art = {} params = {} cm = [] if not action: art = folder_shortcut title = utils.get_string(30018).format(title) else: if action in ["random", "next"]: art = shuffle cm.append(( utils.get_string(30047), ("RunPlugin(" "plugin://plugin.program.autowidget/" "?mode=refresh" "&id={})").format(widget_id), )) elif action == "merged": art = merge elif action == "static": art = utils.get_art("folder") cm.append(( utils.get_string(30048), ("RunPlugin(" "plugin://plugin.program.autowidget/" "?mode=manage" "&action=edit_widget" "&id={})").format(widget_id), )) if not group_def: title = "{} - [COLOR firebrick]{}[/COLOR]".format( widget_id, utils.get_string(30049)) directory.add_menu_item( title=title, art=art, params={ "mode": "group", "group": group }, cm=cm[1:] if not action else cm, isFolder=True, ) else: directory.add_menu_item( title=30050, art=utils.get_art("alert"), isFolder=False, props={"specialsort": "bottom"}, ) return True, utils.get_string(30052), None