def _update_properties(self): for property in _properties: setting = utils.get_setting(property) utils.log('{}: {}'.format(property, setting)) if setting is not None: utils.set_property(property, setting) utils.log('Property {0} set'.format(property)) else: utils.clear_property(property) utils.log('Property {0} cleared'.format(property)) self._reload_settings()
def build_labels(source, path_def=None, target=""): if source == "context" and not path_def and not target: labels = { "label": utils.get_infolabel("ListItem.Label"), "content": utils.get_infolabel("Container.Content"), } path_def = { "file": utils.get_infolabel("ListItem.FolderPath"), "filetype": "directory" if utils.get_condition("Container.ListItem.IsFolder") else "file", "art": {}, } # would be fun to set some "placeholder" art here for i in utils.info_types: info = utils.get_infolabel("ListItem.{}".format(i.capitalize())) if info and not info.startswith("ListItem"): path_def[i] = info for i in utils.art_types: art = utils.get_infolabel("ListItem.Art({})".format(i)) if art: path_def["art"][i] = utils.clean_artwork_url(art) for i in ["icon", "thumb"]: art = utils.clean_artwork_url( utils.get_infolabel("ListItem.{}".format(i))) if art: path_def["art"][i] = art elif source == "json" and path_def and target: labels = {"label": path_def["label"], "content": "", "target": target} labels["file"] = (path_def if path_def else { key: path_def[key] for key in path_def if path_def[key] }) path = labels["file"]["file"] if path != "addons://user/": path = path.replace("addons://user/", "plugin://") if "plugin://plugin.video.themoviedb.helper" in path and not "&widget=True" in path: path += "&widget=True" labels["file"]["file"] = path labels["color"] = utils.get_setting("ui.color") for _key in utils.windows: if any(i in path for i in utils.windows[_key]): labels["window"] = _key return labels
def _update_properties(self, window=10000): for property in _properties: setting = utils.get_setting(property) utils.log('{}: {}'.format(property, setting)) if setting is not None: xbmcgui.Window(window).setProperty(property, setting) utils.log('Property {0} set'.format(property)) else: xbmcgui.Window(window).clearProperty(property) utils.log('Property {0} cleared'.format(property)) self._reload_settings()
def build_labels(source, path_def=None, target=''): if source == 'context' and not path_def and not target: labels = {'label': utils.get_infolabel('ListItem.Label'), 'content': utils.get_infolabel('Container.Content')} path_def = {'file': utils.get_infolabel('ListItem.FolderPath'), 'filetype': 'directory' if utils.get_condition('Container.ListItem.IsFolder') else 'file', 'art': {}} # would be fun to set some "placeholder" art here for i in utils.info_types: info = utils.get_infolabel('ListItem.{}'.format(i.capitalize())) if info and not info.startswith('ListItem'): path_def[i] = info for i in utils.art_types: art = utils.get_infolabel('ListItem.Art({})'.format(i)) if art: path_def['art'][i] = utils.clean_artwork_url(art) for i in ['icon', 'thumb']: art = utils.clean_artwork_url(utils.get_infolabel('ListItem.{}'.format(i))) if art: path_def['art'][i] = art elif source == 'json' and path_def and target: labels = {'label': path_def['label'], 'content': '', 'target': target} labels['file'] = path_def if path_def else {key: path_def[key] for key in path_def if path_def[key]} path = labels['file']['file'] if path != 'addons://user/': path = path.replace('addons://user/', 'plugin://') if 'plugin://plugin.video.themoviedb.helper' in path and not '&widget=True' in path: path += '&widget=True' labels['file']['file'] = path labels['color'] = utils.get_setting('ui.color') for _key in utils.windows: if any(i in path for i in utils.windows[_key]): labels['window'] = _key return labels
def show_path(group_id, path_label, widget_id, path, idx=0, titles=None, num=1, merged=False): hide_watched = utils.get_setting_bool('widgets.hide_watched') show_next = utils.get_setting_int('widgets.show_next') paged_widgets = utils.get_setting_bool('widgets.paged') default_color = utils.get_setting('ui.color') widget_def = manage.get_widget_by_id(widget_id) if not widget_def: return True, 'AutoWidget' if not titles: titles = [] files = refresh.get_files_list(path, titles, widget_id) if not files: return titles, path_label utils.log('Loading items from {}'.format(path), 'debug') if isinstance(widget_def['path'], list): color = widget_def['path'][idx].get('color', default_color) elif isinstance(widget_def['path'], six.text_type): color = widget_def['stack'][0].get('color', default_color) else: color = widget_def['path'].get('color', default_color) stack = widget_def.get('stack', []) if stack: title = utils.get_string(32110).format(len(stack)) directory.add_menu_item(title=title, params={ 'mode': 'path', 'action': 'update', 'id': widget_id, 'path': '', 'target': 'back' }, art=utils.get_art('back', color), isFolder=num > 1, props={ 'specialsort': 'top', 'autoLabel': path_label }) for file in files: properties = {'autoLabel': path_label, 'autoID': widget_id} if 'customproperties' in file: for prop in file['customproperties']: properties[prop] = file['customproperties'][prop] clean_pattern = '[^\w \xC0-\xFF]' tag_pattern = '(\[[^\]]*\])' next_pattern = ( '(?:^(?:next)?\s*(?:(?:>>)|(?:\.*)$)?)\s*' '(?:page\s*(?:(?:\d+\D*\d?$)|(?:(?:>>)|(?:\.*)$)|(?:\(\d+|.*\)$))?)?$' ) prev_pattern = '^(?:previous(?: page)?)$|^(?:back)$' cleaned_title = re.sub(tag_pattern, '', file.get('label', '').lower()).strip() next_item = re.search(next_pattern, cleaned_title) prev_item = re.search(prev_pattern, cleaned_title) if (prev_item and stack) or (next_item and show_next == 0): continue elif next_item and show_next > 0: label = utils.get_string(32111) properties['specialsort'] = 'bottom' if num > 1: if show_next == 1: continue label = '{} - {}'.format(label, path_label) update_params = { 'mode': 'path', 'action': 'update', 'id': widget_id, 'path': file['file'], 'target': 'next' } directory.add_menu_item( title=label, params=update_params if paged_widgets and not merged else None, path=file['file'] if not paged_widgets or merged else None, art=utils.get_art('next_page', color), info=file, isFolder=not paged_widgets or merged, props=properties) else: dupe = False title = (file['label'], file.get('imdbnumber')) for t in titles: if t == title: dupe = True if (hide_watched and file.get('playcount', 0) > 0) or dupe: continue directory.add_menu_item(title=title[0], path=file['file'], art=file['art'], info=file, isFolder=file['filetype'] == 'directory', props=properties) titles.append(title) return titles, path_label
def show_path(group_id, path_label, widget_id, path, idx=0, titles=None, num=1, merged=False): hide_watched = utils.get_setting_bool("widgets.hide_watched") show_next = utils.get_setting_int("widgets.show_next") paged_widgets = utils.get_setting_bool("widgets.paged") default_color = utils.get_setting("ui.color") widget_def = manage.get_widget_by_id(widget_id) if not widget_def: return True, "AutoWidget" if not titles: titles = [] files = refresh.get_files_list(path, widget_id) if not files: return titles, path_label utils.log("Loading items from {}".format(path), "debug") if isinstance(widget_def["path"], list): color = widget_def["path"][idx].get("color", default_color) elif isinstance(widget_def["path"], six.text_type): color = widget_def["stack"][0].get("color", default_color) else: color = widget_def["path"].get("color", default_color) stack = widget_def.get("stack", []) if stack: title = utils.get_string(32110).format(len(stack)) directory.add_menu_item( title=title, params={ "mode": "path", "action": "update", "id": widget_id, "path": "", "target": "back", }, art=utils.get_art("back", color), isFolder=num > 1, props={ "specialsort": "top", "autoLabel": path_label }, ) for file in files: properties = {"autoLabel": path_label, "autoID": widget_id} if "customproperties" in file: for prop in file["customproperties"]: properties[prop] = file["customproperties"][prop] clean_pattern = "[^\w \xC0-\xFF]" tag_pattern = "(\[[^\]]*\])" next_pattern = ( "(?:^(?:next)?\s*(?:(?:>>)|(?:\.*)$)?)\s*" "(?:page\s*(?:(?:\d+\D*\d?$)|(?:(?:>>)|(?:\.*)$)|(?:\(\d+|.*\)$))?)?$" ) prev_pattern = "^(?:previous(?: page)?)$|^(?:back)$" cleaned_title = re.sub(tag_pattern, "", file.get("label", "").lower()).strip() next_item = re.search(next_pattern, cleaned_title) prev_item = re.search(prev_pattern, cleaned_title) if (prev_item and stack) or (next_item and show_next == 0): continue elif next_item and show_next > 0: label = utils.get_string(32111) properties["specialsort"] = "bottom" if num > 1: if show_next == 1: continue label = "{} - {}".format(label, path_label) update_params = { "mode": "path", "action": "update", "id": widget_id, "path": file["file"], "target": "next", } directory.add_menu_item( title=label, params=update_params if paged_widgets and not merged else None, path=file["file"] if not paged_widgets or merged else None, art=utils.get_art("next_page", color), info=file, isFolder=not paged_widgets or merged, props=properties, ) else: title = { "type": file.get("type"), "label": file.get("label"), "imdbnumber": file.get("imdbnumber"), "showtitle": file.get("showtitle"), } dupe = refresh.is_duplicate(title, titles) if (hide_watched and file.get("playcount", 0) > 0) or dupe: continue art = file.get("art", {}) if not art.get("landscape") and art.get("thumb"): art["landscape"] = art["thumb"] directory.add_menu_item( title=file["label"], path=file["file"], art=art, info=file, isFolder=file["filetype"] == "directory", props=properties, ) titles.append(title) return titles, path_label
import os import zipfile import six import xbmcgui from resources.lib.common import utils _backup_location = utils.translate_path(utils.get_setting('backup.location')) dialog = xbmcgui.Dialog() def location(): folder = dialog.browse(0, utils.get_string(32091), 'files', defaultt=backup_location) if folder: utils.set_setting('backup.location', folder) 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):
def show_path(group_id, path_label, widget_id, path, idx=0, titles=None, num=1, merged=False): hide_watched = utils.get_setting_bool("widgets.hide_watched") show_next = utils.get_setting_int("widgets.show_next") paged_widgets = utils.get_setting_bool("widgets.paged") default_color = utils.get_setting("ui.color") widget_def = manage.get_widget_by_id(widget_id) if not widget_def: return True, "AutoWidget" if not titles: titles = [] files = refresh.get_files_list(path, widget_id) if not files: return titles, path_label utils.log("Loading items from {}".format(path), "debug") if isinstance(widget_def["path"], list): color = widget_def["path"][idx].get("color", default_color) elif isinstance(widget_def["path"], six.text_type): color = widget_def["stack"][0].get("color", default_color) else: color = widget_def["path"].get("color", default_color) stack = widget_def.get("stack", []) if stack: title = _previous # title = utils.get_string(30085).format(len(stack)) directory.add_menu_item( title=title, params={ "mode": "path", "action": "update", "id": widget_id, "path": "", "target": "back", }, art=utils.get_art("back", color), isFolder=num > 1, props={ "specialsort": "top", "autoLabel": path_label }, ) for pos, file in enumerate(files): properties = {"autoLabel": path_label, "autoID": widget_id} next_item = False prev_item = False if "customproperties" in file: for prop in file["customproperties"]: properties[prop] = file["customproperties"][prop] if pos == len(files) - 1: next_item = _is_page_item(file.get("label", "")) elif pos == 0: prev_item = _is_page_item(file.get("label", ""), next=False) if (prev_item and stack) or (next_item and show_next == 0): continue elif next_item and show_next > 0: label = _next_page properties["specialsort"] = "bottom" if num > 1: if show_next == 1: continue label = "{} - {}".format(label, path_label) update_params = { "mode": "path", "action": "update", "id": widget_id, "path": file["file"], "target": "next", } directory.add_menu_item( title=label, params=update_params if paged_widgets and not merged else None, path=file["file"] if not paged_widgets or merged else None, art=utils.get_art("next_page", color), info=file, isFolder=not paged_widgets or merged, props=properties, ) else: title = { "type": file.get("type"), "label": file.get("label"), "imdbnumber": file.get("imdbnumber"), "showtitle": file.get("showtitle"), } dupe = refresh.is_duplicate(title, titles) if (hide_watched and file.get("playcount", 0) > 0) or dupe: continue art = file.get("art", {}) if not art.get("landscape") and art.get("thumb"): art["landscape"] = art["thumb"] directory.add_menu_item( title=file["label"], path=file["file"], art=art, info=file, isFolder=file["filetype"] == "directory", props=properties, ) titles.append(title) return titles, path_label