def build_labels(source, path_def=None, target=""): if source == "context" and not path_def and not target: content = utils.get_infolabel("Container.Content") labels = { "label": utils.get_infolabel("ListItem.Label"), "content": content if content else "videos", } 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.get_info_keys(): 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": "videos", "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"] = settings.get_setting_string("ui.color") for _key in utils.windows: if any(i in path for i in utils.windows[_key]): labels["window"] = _key return labels
def get_files_list(path, titles=None, widget_id=None): if not titles: titles = [] hash = utils.path2hash(path) _, files, _ = utils.cache_expiry(hash, widget_id) if files is None: # We had no old content so have to block and get it now utils.log("Blocking cache path read: {}".format(hash[:5]), "info") files, changed = utils.cache_files(path, widget_id) new_files = [] if 'error' not in files: files = files.get('result').get('files') if not files: utils.log('No items found for {}'.format(path)) return filtered_files = [x for x in files if x['title'] not in titles] for file in filtered_files: new_file = { k: v for k, v in file.items() if v not in [None, '', -1, [], {}] } if 'art' in new_file: for art in new_file['art']: new_file['art'][art] = utils.clean_artwork_url( file['art'][art]) new_files.append(new_file) return new_files
def get_files_list(path, widget_id=None): hash = utils.path2hash(path) _, files, _ = utils.cache_expiry(hash, widget_id) if files is None: # We had no old content so have to block and get it now utils.log("Blocking cache path read: {}".format(hash[:5]), "info") files, changed = utils.cache_files(path, widget_id) new_files = [] if "error" not in files: files = files.get("result").get("files") if not files: utils.log("No items found for {}".format(path)) return for file in files: new_file = { k: v for k, v in file.items() if v not in [None, "", -1, [], {}] } if "art" in new_file: for art in new_file["art"]: new_file["art"][art] = utils.clean_artwork_url( file["art"][art]) new_files.append(new_file) return new_files
def get_files_list(path, label=None, widget_id=None, background=True): hash = cache.path2hash(path) _, files, _ = cache.cache_expiry(path, widget_id, background=background) if files is None: # Should only happen now when background is False utils.log("Blocking cache path read: {}".format(hash[:5]), "info") files, changed = cache.cache_files(path, widget_id) new_files = [] if "result" in files: files = files.get("result", {}).get("files", []) elif "error" in files: utils.log("Error processing {}".format(hash), "error") error_tile = utils.make_holding_path( utils.get_string(30139).format(label), "alert", hash=hash ) files = error_tile.get("result", {}).get("files", []) cache_path = os.path.join(_addon_data, "{}.cache".format(hash)) if os.path.exists(cache_path): os.remove(cache_path) utils.log("Invalid cache file removed for {}".format(hash)) if not files: utils.log("No items found for {}".format(hash)) empty_tile = utils.make_holding_path( utils.get_string(30140).format(label), "information-outline", hash=hash ) files = empty_tile.get("result", {}).get("files", []) for file in files: new_file = {k: v for k, v in file.items() if v is not None} if "art" in new_file: for art in new_file["art"]: new_file["art"][art] = utils.clean_artwork_url(file["art"][art]) if "cast" in new_file: for idx, cast in enumerate(new_file["cast"]): new_file["cast"][idx]["thumbnail"] = utils.clean_artwork_url( cast.get("thumbnail", "") ) new_files.append(new_file) return new_files, hash
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 get_files_list(path, widget_id=None): hash = utils.path2hash(path) _, files, _ = utils.cache_expiry(hash, widget_id) if files is None: # We had no old content so have to block and get it now utils.log("Blocking cache path read: {}".format(hash[:5]), "info") files, changed = utils.cache_files(path, widget_id) new_files = [] if "result" in files: files = files.get("result", {}).get("files", []) if not files: utils.log("No items found for {}".format(path)) return [], hash for file in files: new_file = {k: v for k, v in file.items() if v is not None} if "art" in new_file: for art in new_file["art"]: new_file["art"][art] = utils.clean_artwork_url( file["art"][art]) if "cast" in new_file: for idx, cast in enumerate(new_file["cast"]): new_file["cast"][idx][ "thumbnail"] = utils.clean_artwork_url( cast.get("thumbnail", "")) new_files.append(new_file) return new_files, hash elif "error" in files: os.remove(os.path.join(_addon_data, "{}.cache".format(hash))) utils.log("Invalid cache file removed for {}".format(hash)) return None, hash else: utils.log("Error processing {}".format(hash), "error") return None, hash
def _get_value(edit_def, key): if isinstance(edit_def[_clean_key(key)], dict): is_art = key == 'art' label = utils.get_string(32117) if is_art else utils.get_string(32118) options = _get_options(edit_def[key], useThumbs=is_art) idx = dialog.select(label, options, useDetails=is_art) if idx < 0: return elif idx == len(options) - 1: keys = utils.info_types if key == 'file' else utils.art_types add_options = [ i for i in keys if (i not in edit_def[key] or edit_def[key][i] in [None, "", -1]) ] add_idx = dialog.select( utils.get_string(32120) if key == 'file' else utils.get_string(32119), add_options) if add_idx < 0: return if key == 'file': value = dialog.input( utils.get_string(32121).format(add_options[add_idx])) if value is not None: edit_def[key][add_options[add_idx]] = value return edit_def[key][add_options[add_idx]] elif key == 'art': value = dialog.browse(2, utils.get_string(32049).format( add_options[add_idx].capitalize()), shares='files', mask='.jpg|.png', useThumbs=True) if value is not None: edit_def[key][ add_options[add_idx]] = utils.clean_artwork_url(value) return edit_def[key] else: subkey = _clean_key(options[idx]) value = _get_value(edit_def[key], _clean_key(options[idx])) if value is not None: edit_def[key][subkey] = value return edit_def[key] else: default = edit_def[key] if key in utils.art_types: value = dialog.browse(2, utils.get_string(32049).format( key.capitalize()), shares='files', mask='.jpg|.png', useThumbs=True, defaultt=default) elif key == 'filetype': options = ['file', 'directory'] type = dialog.select(utils.get_string(32122), options, preselect=options.index(default)) value = options[type] elif key == 'color': value = utils.set_color() else: value = dialog.input(utils.get_string(32121).format(key), defaultt=default) if value == default: clear = dialog.yesno( 'AutoWidget', utils.get_string(32123).format( 'art' if key in utils.art_types else 'value', key, default), yeslabel=utils.get_string(32124), nolabel=utils.get_string(32125)) if clear: value = '' if value is not None: edit_def[key] = utils.clean_artwork_url(value) return value
def _get_value(edit_def, key): if isinstance(edit_def[_clean_key(key)], dict): is_art = key == "art" label = utils.get_string(30091) if is_art else utils.get_string(30092) options = _get_options(edit_def[key], useThumbs=is_art) idx = dialog.select(label, options, useDetails=is_art) if idx < 0: return elif idx == len(options) - 1: keys = utils.info_types if key == "file" else utils.art_types add_options = [ i for i in keys if (i not in edit_def[key] or edit_def[key][i] in [None, "", -1]) ] add_idx = dialog.select( utils.get_string(30094) if key == "file" else utils.get_string(30093), add_options, ) if add_idx < 0: return if key == "file": value = dialog.input( utils.get_string(30095).format(add_options[add_idx])) if value is not None: edit_def[key][add_options[add_idx]] = value return edit_def[key][add_options[add_idx]] elif key == "art": value = dialog.browse( 2, utils.get_string(30032).format( add_options[add_idx].capitalize()), shares="files", mask=".jpg|.png", useThumbs=True, ) if value is not None: edit_def[key][ add_options[add_idx]] = utils.clean_artwork_url(value) return edit_def[key] else: subkey = _clean_key(options[idx]) value = _get_value(edit_def[key], _clean_key(options[idx])) if value is not None: edit_def[key][subkey] = value return edit_def[key] else: default = edit_def[key] if key in utils.art_types: value = dialog.browse( 2, utils.get_string(30032).format(key.capitalize()), shares="files", mask=".jpg|.png", useThumbs=True, defaultt=default, ) elif key == "filetype": options = ["file", "directory"] type = dialog.select(utils.get_string(30096), options, preselect=options.index(default)) value = options[type] elif key == "color": value = utils.set_color() else: value = dialog.input(utils.get_string(30095).format(key), defaultt=default) if value == default: clear = dialog.yesno( "AutoWidget", utils.get_string(30097).format( "art" if key in utils.art_types else "value", key, default), yeslabel=utils.get_string(30098), nolabel=utils.get_string(30099), ) if clear: value = "" if value is not None: if key in utils.art_types: edit_def[key] = utils.clean_artwork_url(value) else: edit_def[key] = value return value
def _get_value(edit_def, key): dialog = xbmcgui.Dialog() if isinstance(edit_def[_clean_key(key)], dict): is_art = key == "art" label = utils.get_string(30091) if is_art else utils.get_string(30092) options = _get_options(edit_def[key], useThumbs=is_art) idx = dialog.select(label, options, useDetails=is_art) if idx < 0: del dialog return elif idx == len(options) - 1: keys = utils.info_types if key == "file" else utils.art_types add_options = [ i for i in keys if (i not in edit_def[key] or edit_def[key][i] in [None, "", -1]) ] add_idx = dialog.select( utils.get_string(30094) if key == "file" else utils.get_string(30093), add_options, ) if add_idx < 0: del dialog return if key == "file": value = dialog.input( utils.get_string(30095).format(add_options[add_idx])) if value is not None: edit_def[key][add_options[add_idx]] = value del dialog return edit_def[key][add_options[add_idx]] elif key == "art": value = dialog.browse( 2, utils.get_string(30032).format( add_options[add_idx].capitalize()), shares="files", mask=".jpg|.png", useThumbs=True, ) if value is not None: edit_def[key][ add_options[add_idx]] = utils.clean_artwork_url(value) del dialog return edit_def[key] else: subkey = _clean_key(options[idx]) value = _get_value(edit_def[key], _clean_key(options[idx])) if value is not None: edit_def[key][subkey] = value del dialog return edit_def[key] else: default = edit_def[key] if key in utils.art_types: value = dialog.browse( 2, utils.get_string(30032).format(key.capitalize()), shares="files", mask=".jpg|.png", useThumbs=True, defaultt=default, ) elif key == "filetype": options = ["file", "directory"] type = dialog.select(utils.get_string(30096), options, preselect=options.index(default)) value = options[type] elif key == "color": value = utils.set_color() elif key == "content": options = [ "none", "files", "movies", "tvshows", "episodes", "videos", "artists", "albums", "songs", "musicvideos", "images", "games", "genres", "years", "actors", "playlists", "plugins", "studios", "directors", "sets", "tags", "countries", "roles", "images", "addons", "livetv", ] type = dialog.select( utils.get_string(30119), options, preselect=options.index(default if default in options else "none"), ) value = options[type] else: value = dialog.input(utils.get_string(30095).format(key), defaultt=default) if value == default: clear = dialog.yesno( "AutoWidget", utils.get_string(30097).format( "art" if key in utils.art_types else "value", key, default), yeslabel=utils.get_string(30098), nolabel=utils.get_string(30099), ) if clear: value = "" del dialog if value is not None: if key in utils.art_types: edit_def[key] = utils.clean_artwork_url(value) else: edit_def[key] = value return value