def backup_theme(self, themename): '''backup a colortheme to a zipfile''' import zipfile backup_path = xbmcgui.Dialog().browse( 3, self.addon.getLocalizedString(32029), "files").decode("utf-8") if backup_path: xbmc.executebuiltin("ActivateWindow(busydialog)") backup_name = u"%s ColorTheme - %s" % ( get_skin_name().capitalize(), themename) backupfile = os.path.join(backup_path, backup_name + u".zip") zip_temp = u'special://temp/%s.zip' % backup_name xbmcvfs.delete(zip_temp) xbmcvfs.delete(backupfile) zip_temp = xbmc.translatePath(zip_temp).decode("utf-8") zip_file = zipfile.ZipFile(zip_temp, "w", zipfile.ZIP_DEFLATED) abs_src = os.path.abspath( xbmc.translatePath(self.userthemes_path).decode("utf-8")) for filename in xbmcvfs.listdir(self.userthemes_path)[1]: if (filename.startswith("%s_" % themename) or filename.replace( ".theme", "").replace(".jpg", "") == themename): filename = filename.decode("utf-8") filepath = xbmc.translatePath(self.userthemes_path + filename).decode("utf-8") absname = os.path.abspath(filepath) arcname = absname[len(abs_src) + 1:] zip_file.write(absname, arcname) zip_file.close() xbmcvfs.copy(zip_temp, backupfile) xbmc.executebuiltin("Dialog.Close(busydialog)")
def get_backupfilename(self, promptfilename=False): '''get the filename for the new backup''' backupfile = "%s Skinbackup (%s)" % (get_skin_name().capitalize( ), datetime.now().strftime('%Y-%m-%d %H.%M.%S')) if promptfilename: header = self.addon.getLocalizedString(32003) backupfile = xbmcgui.Dialog().input(header, backupfile).decode("utf-8") backupfile += ".zip" return self.get_backuppath() + backupfile
def __init__(self): self.userthemes_path = u"special://profile/addon_data/%s/themes/" % xbmc.getSkinDir( ) if not xbmcvfs.exists(self.userthemes_path): xbmcvfs.mkdir(self.userthemes_path) self.skinthemes_path = u"special://skin/extras/skinthemes/" if xbmcvfs.exists( "special://home/addons/resource.skinthemes.%s/resources/" % get_skin_name()): self.skinthemes_path = u"special://home/addons/resource.skinthemes.%s/resources/" % get_skin_name( ) self.addon = xbmcaddon.Addon(ADDON_ID)
async def connect(connection: Connection): global choose_new print("Connected to LCU API") while True: try: req_type = "/lol-champ-select/v1/session" req = await connection.request("get", req_type) data = await req.json() if "errorCode" in data: menu_item._text = menu_item._wrap("Not in champ select") menu_item._enabled = menu_item._wrap(False) icon.update_menu() time.sleep(5) continue req_type = "/lol-champ-select/v1/skin-selector-info" req = await connection.request("get", req_type) data = await req.json() if data["selectedChampionId"] == 0: menu_item._text = menu_item._wrap("No champ selected") menu_item._enabled = menu_item._wrap(False) icon.update_menu() time.sleep(2) continue champ_id = data["selectedChampionId"] menu_item._text = menu_item._wrap("Randomize") menu_item._enabled = menu_item._wrap(True) icon.update_menu() if choose_new: choose_new = False list_skins = [] skin_names = [] req_type = "/lol-champ-select/v1/skin-carousel-skins" req = await connection.request("get", req_type) data = await req.json() for skin in data: if skin["unlocked"] and not skin["disabled"]: list_skins.append(skin["id"]) skin_names.append(skin["name"]) selected = random.choice(list_skins) pos = list_skins.index(selected) req_type = "/lol-champ-select/v1/session/my-selection" req_data = {"selectedSkinId": selected} req = await connection.request("patch", req_type, data=req_data) data = await req.json() print("Available", list_skins, skin_names, "Chosen", selected) easygui.msgbox("Skin selected: " + get_skin_name(selected, skin_names, list_skins, champ_id), "LoL random skin selector") time.sleep(1) except Exception as e: print(e) my_exit(icon)