def check_screensaver(self): '''Allow user to disable screensaver on fullscreen music playback''' if xbmc.getCondVisibility( "Window.IsActive(visualisation) + Skin.HasSetting(SkinHelper.DisableScreenSaverOnFullScreenMusic)" ): if not self.screensaver_disabled: # disable screensaver when fullscreen music active self.screensaver_disabled = True screensaver_setting = kodi_json( 'Settings.GetSettingValue', '{"setting":"screensaver.mode"}') if screensaver_setting: self.screensaver_setting = screensaver_setting kodi_json('Settings.SetSettingValue', { "setting": "screensaver.mode", "value": None }) log_msg( "Disabled screensaver while fullscreen music playback - previous setting: %s" % self.screensaver_setting, xbmc.LOGNOTICE) elif self.screensaver_disabled and self.screensaver_setting: # enable screensaver again after fullscreen music playback was ended kodi_json('Settings.SetSettingValue', { "setting": "screensaver.mode", "value": self.screensaver_setting }) self.screensaver_disabled = False self.screensaver_setting = None log_msg( "fullscreen music playback ended - restoring screensaver: %s" % self.screensaver_setting, xbmc.LOGNOTICE)
def plugin_widgetlisting(pluginpath, sublevel=""): """get all nodes in a plugin listing""" widgets = [] if sublevel: media_array = kodi_json('Files.GetDirectory', { "directory": pluginpath, "media": "files" }) else: if not getCondVisibility("System.HasAddon(%s)" % pluginpath): return [] media_array = kodi_json('Files.GetDirectory', { "directory": "plugin://%s" % pluginpath, "media": "files" }) for item in media_array: log_msg("skinshortcuts widgets processing: %s" % (item["file"])) content = item["file"] label = item["label"] # extendedinfo has some login-required widgets, skip those if ("script.extendedinfo" in pluginpath and not EXTINFO_CREDS and ("info=starred" in content or "info=rated" in content or "info=account" in content)): continue if item.get("filetype", "") == "file": continue mutils = MetadataUtils() media_type = mutils.detect_plugin_content(item["file"]) del mutils if media_type == "empty": continue if media_type == "folder": content = "plugin://script.skin.helper.service?action=widgets&path=%s&sublevel=%s" % ( urlencode(item["file"]), label) # add reload param for widgets if "reload=" not in content: if "movies" in content: reloadstr = "&reload=$INFO[Window(Home).Property(widgetreload-movies)]" elif "episodes" in content: reloadstr = "&reload=$INFO[Window(Home).Property(widgetreload-episodes)]" elif "tvshows" in content: reloadstr = "&reload=$INFO[Window(Home).Property(widgetreload-tvshows)]" elif "musicvideos" in content: reloadstr = "&reload=$INFO[Window(Home).Property(widgetreload-musicvideos)]" elif "albums" in content or "songs" in content or "artists" in content: reloadstr = "&reload=$INFO[Window(Home).Property(widgetreload-music)]" else: reloadstr = "&reload=$INFO[Window(Home).Property(widgetreload)]"\ "$INFO[Window(Home).Property(widgetreload2)]" content = content + reloadstr content = content.replace("&limit=100", "&limit=25") widgets.append([label, content, media_type]) if pluginpath == "script.extendedinfo" and not sublevel: # some additional entrypoints for extendedinfo... widgets += extendedinfo_youtube_widgets() return widgets
def playlists_widgets(): '''skin provided playlists''' widgets = [] import xml.etree.ElementTree as xmltree for playlist_path in ["special://skin/playlists/", "special://skin/extras/widgetplaylists/", "special://skin/extras/playlists/"]: if xbmcvfs.exists(playlist_path): log_msg("skinshortcuts widgets processing: %s" % playlist_path) media_array = kodi_json('Files.GetDirectory', {"directory": playlist_path, "media": "files"}) for item in media_array: if item["file"].endswith(".xsp"): playlist = item["file"] contents = xbmcvfs.File(item["file"], 'r') contents_data = contents.read().decode('utf-8') contents.close() xmldata = xmltree.fromstring(contents_data.encode('utf-8')) media_type = "" label = item["label"] for line in xmldata.getiterator(): if line.tag == "smartplaylist": media_type = line.attrib['type'] if line.tag == "name": label = line.text try: languageid = int(label) label = xbmc.getLocalizedString(languageid) except Exception: pass if not media_type: mutils = MetadataUtils() media_type = mutils.detect_plugin_content(playlist) del mutils widgets.append([label, playlist, media_type]) return widgets
def favourites_widgets(): """widgets from favourites""" favourites = kodi_json( 'Favourites.GetFavourites', { "type": None, "properties": ["path", "thumbnail", "window", "windowparameter"] }) widgets = [] if favourites: for fav in favourites: if "windowparameter" in fav: content = fav["windowparameter"] # check if this is a valid path with content if ("script://" not in content.lower() and "mode=9" not in content.lower() and "search" not in content.lower() and "play" not in content.lower()): label = fav["title"] log_msg("skinshortcuts widgets processing favourite: %s" % label) mutils = MetadataUtils() mediatype = mutils.detect_plugin_content(content) del mutils if mediatype and mediatype != "empty": widgets.append([label, content, mediatype]) return widgets
def check_screensaver(self): '''Allow user to disable screensaver on fullscreen music playback''' if xbmc.getCondVisibility( "Window.IsActive(visualisation) + Skin.HasSetting(SkinHelper.DisableScreenSaverOnFullScreenMusic)"): if not self.screensaver_disabled: # disable screensaver when fullscreen music active self.screensaver_setting = kodi_json('Settings.GetSettingValue', '{"setting":"screensaver.mode"}') kodi_json('Settings.SetSettingValue', {"setting": "screensaver.mode", "value": None}) self.screensaver_disabled = True log_msg( "Disabled screensaver while fullscreen music playback - previous setting: %s" % self.screensaver_setting) elif self.screensaver_setting and self.screensaver_disabled: # enable screensaver again after fullscreen music playback was ended kodi_json('Settings.SetSettingValue', {"setting": "screensaver.mode", "value": self.screensaver_setting}) self.screensaver_disabled = False log_msg("fullscreen music playback ended - restoring screensaver: %s" % self.screensaver_setting)
def setkodisetting(self): '''set kodi setting''' settingname = self.params.get("setting", "") value = self.params.get("value", "") is_int = False try: valueint = int(value) is_int = True del valueint except Exception: pass if value.lower() in ["true", "false"]: value = value.lower() elif is_int: value = '"%s"' % value params = {"setting": settingname, "value": value} kodi_json("Settings.SetSettingValue", params)
def get_resourceaddons(filterstr=""): '''helper to retrieve all installed resource addons''' result = [] params = {"type": "kodi.resource.images", "properties": ["name", "thumbnail", "path", "author"]} for item in kodi_json("Addons.GetAddons", params, "addons"): if not filterstr or item['addonid'].lower().startswith(filterstr.lower()): item["path"] = "resource://%s/" % item["addonid"] result.append(item) return result
def set_generic_props(self): '''set some generic window props with item counts''' # GET TOTAL ADDONS COUNT addons_count = len(kodi_json('Addons.GetAddons')) self.win.setProperty("SkinHelper.TotalAddons", "%s" % addons_count) addontypes = [] addontypes.append(("executable", "SkinHelper.TotalProgramAddons")) addontypes.append(("video", "SkinHelper.TotalVideoAddons")) addontypes.append(("audio", "SkinHelper.TotalAudioAddons")) addontypes.append(("image", "SkinHelper.TotalPicturesAddons")) for addontype in addontypes: media_array = kodi_json('Addons.GetAddons', {"content": addontype[0]}) self.win.setProperty(addontype[1], str(len(media_array))) # GET FAVOURITES COUNT favs = kodi_json('Favourites.GetFavourites') if favs: self.win.setProperty("SkinHelper.TotalFavourites", "%s" % len(favs)) if self.exit: return # GET TV CHANNELS COUNT if getCondVisibility("Pvr.HasTVChannels"): tv_channels = kodi_json('PVR.GetChannels', {"channelgroupid": "alltv"}) self.win.setProperty("SkinHelper.TotalTVChannels", "%s" % len(tv_channels)) if self.exit: return # GET MOVIE SETS COUNT movieset_movies_count = 0 moviesets = kodi_json('VideoLibrary.GetMovieSets') for item in moviesets: for item in kodi_json('VideoLibrary.GetMovieSetDetails', {"setid": item["setid"]}): movieset_movies_count += 1 self.win.setProperty("SkinHelper.TotalMovieSets", "%s" % len(moviesets)) self.win.setProperty("SkinHelper.TotalMoviesInSets", "%s" % movieset_movies_count) if self.exit: return # GET RADIO CHANNELS COUNT if getCondVisibility("Pvr.HasRadioChannels"): radio_channels = kodi_json('PVR.GetChannels', {"channelgroupid": "allradio"}) self.win.setProperty("SkinHelper.TotalRadioChannels", "%s" % len(radio_channels))
def set_generic_props(self): '''set some genric window props with item counts''' # GET TOTAL ADDONS COUNT addons_count = len(kodi_json('Addons.GetAddons')) self.win.setProperty("SkinHelper.TotalAddons", "%s" % addons_count) addontypes = [] addontypes.append(("executable", "SkinHelper.TotalProgramAddons")) addontypes.append(("video", "SkinHelper.TotalVideoAddons")) addontypes.append(("audio", "SkinHelper.TotalAudioAddons")) addontypes.append(("image", "SkinHelper.TotalPicturesAddons")) for addontype in addontypes: media_array = kodi_json('Addons.GetAddons', {"content": addontype[0]}) self.win.setProperty(addontype[1], str(len(media_array))) # GET FAVOURITES COUNT favs = kodi_json('Favourites.GetFavourites') if favs: self.win.setProperty("SkinHelper.TotalFavourites", "%s" % len(favs)) # GET TV CHANNELS COUNT if xbmc.getCondVisibility("Pvr.HasTVChannels"): tv_channels = kodi_json('PVR.GetChannels', {"channelgroupid": "alltv"}) self.win.setProperty("SkinHelper.TotalTVChannels", "%s" % len(tv_channels)) # GET MOVIE SETS COUNT movieset_movies_count = 0 moviesets = kodi_json('VideoLibrary.GetMovieSets') for item in moviesets: for item in kodi_json('VideoLibrary.GetMovieSetDetails', {"setid": item["setid"]}): movieset_movies_count += 1 self.win.setProperty("SkinHelper.TotalMovieSets", "%s" % len(moviesets)) self.win.setProperty("SkinHelper.TotalMoviesInSets", "%s" % movieset_movies_count) # GET RADIO CHANNELS COUNT if xbmc.getCondVisibility("Pvr.HasRadioChannels"): radio_channels = kodi_json('PVR.GetChannels', {"channelgroupid": "allradio"}) self.win.setProperty("SkinHelper.TotalRadioChannels", "%s" % len(radio_channels))
def create_colortheme(self): '''create a colortheme from current skin color settings''' try: current_skinfont = None json_response = kodi_json("Settings.GetSettingValue", {"setting": "lookandfeel.font"}) if json_response: current_skinfont = json_response current_skincolors = None json_response = kodi_json("Settings.GetSettingValue", {"setting": "lookandfeel.skincolors"}) if json_response: current_skincolors = json_response # user has to enter name for the theme themename = xbmcgui.Dialog().input( self.addon.getLocalizedString(32023), type=xbmcgui.INPUT_ALPHANUM).decode("utf-8") if not themename: return xbmc.executebuiltin("ActivateWindow(busydialog)") xbmc.executebuiltin( "Skin.SetString(SkinHelper.LastColorTheme,%s)" % themename.encode("utf-8")) # add screenshot custom_thumbnail = xbmcgui.Dialog().browse( 2, self.addon.getLocalizedString(32024), 'files') if custom_thumbnail: xbmcvfs.copy(custom_thumbnail, self.userthemes_path + themename + ".jpg") # read the guisettings file to get all skin settings from backuprestore import BackupRestore skinsettingslist = BackupRestore().get_skinsettings([ "color", "opacity", "texture", "panel", "colour", "background", "image" ]) newlist = [] if skinsettingslist: newlist.append(("THEMENAME", themename)) newlist.append( ("DESCRIPTION", self.addon.getLocalizedString(32025))) newlist.append( ("SKINTHEME", xbmc.getInfoLabel("Skin.CurrentTheme"))) newlist.append(("SKINFONT", current_skinfont)) newlist.append(("SKINCOLORS", current_skincolors)) # look for any images in the skin settings and translate them so they can # be included in the theme backup for skinsetting in skinsettingslist: setting_type = skinsetting[0] setting_name = skinsetting[1] setting_value = skinsetting[2] if setting_type == "string" and setting_value: if (setting_value and (setting_value.endswith(".png") or setting_value.endswith(".gif") or setting_value.endswith(".jpg")) and "resource://" not in setting_value): image = get_clean_image(setting_value) extension = image.split(".")[-1] newimage = "%s_%s.%s" % ( themename, normalize_string(setting_name), extension) newimage_path = self.userthemes_path + newimage if xbmcvfs.exists(image): xbmcvfs.copy(image, newimage_path) skinsetting = (setting_type, setting_name, newimage_path) newlist.append(skinsetting) # save guisettings text_file_path = self.userthemes_path + themename + ".theme" text_file = xbmcvfs.File(text_file_path, "w") text_file.write(repr(newlist)) text_file.close() xbmc.executebuiltin("Dialog.Close(busydialog)") xbmcgui.Dialog().ok(self.addon.getLocalizedString(32026), self.addon.getLocalizedString(32027)) except Exception as exc: xbmc.executebuiltin("Dialog.Close(busydialog)") log_exception(__name__, exc) xbmcgui.Dialog().ok(self.addon.getLocalizedString(32028), self.addon.getLocalizedString(32030), str(exc))
def load_colortheme(filename): '''load colortheme from themefile''' xbmc.executebuiltin("ActivateWindow(busydialog)") xbmcfile = xbmcvfs.File(filename) data = xbmcfile.read() xbmcfile.close() importstring = eval(data) skintheme = None skincolor = None skinfont = None current_skintheme = xbmc.getInfoLabel("Skin.CurrentTheme").decode( "utf-8") current_skinfont = None json_response = kodi_json("Settings.GetSettingValue", {"setting": "lookandfeel.font"}) if json_response: current_skinfont = json_response current_skincolors = None json_response = kodi_json("Settings.GetSettingValue", {"setting": "lookandfeel.skincolors"}) if json_response: current_skincolors = json_response settingslist = set() for skinsetting in importstring: if skinsetting[0] == "SKINTHEME": skintheme = skinsetting[1].decode('utf-8') elif skinsetting[0] == "SKINCOLORS": skincolor = skinsetting[1] elif skinsetting[0] == "SKINFONT": skinfont = skinsetting[1] elif skinsetting[0] == "THEMENAME": xbmc.executebuiltin( "Skin.SetString(SkinHelper.LastColorTheme,%s)" % skinsetting[1]) elif skinsetting[0] == "DESCRIPTION": xbmc.executebuiltin( "Skin.SetString(SkinHelper.LastColorTheme.Description,%s)" % skinsetting[1]) elif skinsetting[1].startswith("SkinHelper.ColorTheme"): continue else: setting = skinsetting[1] if isinstance(setting, unicode): setting = setting.encode("utf-8") if setting not in settingslist: settingslist.add(setting) if skinsetting[0] == "string": if skinsetting[2] is not "": xbmc.executebuiltin("Skin.SetString(%s,%s)" % (setting, skinsetting[2])) else: xbmc.executebuiltin("Skin.Reset(%s)" % setting) elif skinsetting[0] == "bool": if skinsetting[2] == "true": xbmc.executebuiltin("Skin.SetBool(%s)" % setting) else: xbmc.executebuiltin("Skin.Reset(%s)" % setting) xbmc.sleep(30) # change the skintheme, color and font if needed if skintheme and current_skintheme != skintheme: kodi_json("Settings.SetSettingValue", { "setting": "lookandfeel.skintheme", "value": skintheme }) if skincolor and current_skincolors != skincolor: kodi_json("Settings.SetSettingValue", { "setting": "lookandfeel.skincolors", "value": skincolor }) if skinfont and current_skinfont != skinfont and current_skinfont.lower( ) != "arial": kodi_json("Settings.SetSettingValue", { "setting": "lookandfeel.font", "value": skinfont }) xbmc.executebuiltin("Dialog.Close(busydialog)")