def connect_vpn(alias): location = expressVPN.get_location(alias) old_location = expressVPN.connected_location() old_alias = expressVPN.get_alias(old_location) addon_utils.notification("{0} {1}...".format(addon_utils.localize(30023), location), sound=_kodi_notify_sound, show=_kodi_notify) try: expressVPN.connect(alias, timeout=_timeout) addon_utils.notification("{0} {1}".format(addon_utils.localize(30024), location), sound=_kodi_notify_sound, show=_kodi_notify) except ExpressVPNError as vpe: if expressVPN.is_connected(): expressVPN.connected_location connect = dialog.yesno(addon_utils.name, "{0} {1} {2} {3} {4}" \ .format(addon_utils.localize(30025), expressVPN.connected_location(), addon_utils.localize(30026), location, addon_utils.localize(30027))) if connect: disconnect_vpn() connect_vpn(alias) else: dialog.ok(addon_utils.name, str(vpe)) except TimeoutExpired as te: retry = dialog.yesno(addon_utils.name, addon_utils.localize(30028)) if retry: connect_vpn(alias)
def main_menu(): exit_menu = False while not exit_menu: default_alias = settings_handler.get_setting("default_location") header = addon_utils.name if expressVPN.is_connected(): first_item = addon_utils.localize(30000) header = "{0} - {1} {2}".format(header, addon_utils.localize(30001), expressVPN.connected_location()) elif expressVPN.is_connecting(): header = "{0} - {1}".format(header, expressVPN.status()) else: try: first_item = "{0} {1}".format( addon_utils.localize(30002), expressVPN.get_location(default_alias)) except KeyError: first_item = "{0} {1}".format(addon_utils.localize(30002), default_alias) choice = xbmcgui.Dialog().select( header, [first_item] + addon_utils.localize(30003, 30004, 30005)) if choice == 0: if expressVPN.is_connected() or expressVPN.is_connecting(): disconnect_vpn() else: connect_vpn(default_alias) elif choice == 1: server_list_menu() elif choice == 2: infoVPN() else: exit_menu = True
def favourites_menu(): exit_menu = False while not exit_menu: server_list = favourites_handler.get_servers() if _show_alias: location_list = [ "{0} ({1})".format(server["location"], server["alias"]) for server in server_list ] else: location_list = [ "{0}".format(server["location"]) for server in server_list ] header = addon_utils.name if expressVPN.is_connected(): header = "{0} - {1} {2}".format(header, addon_utils.localize(30001), expressVPN.connected_location()) choice_list = [".."] + location_list choice = dialog.select(header, choice_list) if choice == 0: exit_menu = True elif choice == -1: sys.exit(0) else: favourites_context_menu(server_list[choice - 1]["alias"])
def server_list_country_menu(continent=None, recommended=True): exit_menu = False choice = 0 while not exit_menu: header = addon_utils.name if expressVPN.is_connected(): header = "{0} - {1} {2}".format(header, addon_utils.localize(30001), expressVPN.connected_location()) server_list = expressVPN.list_servers(recommended=recommended) alias_list = [ server["alias"] for server in server_list if server["alias"] != "smart" ] location_list = [ server["location"] for server in server_list if server["alias"] != "smart" ] if not recommended: # sort alphabetically server_list_sorted = sorted(zip(location_list, alias_list)) location_list = [ location for (location, alias) in server_list_sorted if country_to_continent(location) == continent ] alias_list = [ alias for (location, alias) in server_list_sorted if country_to_continent(location) == continent ] if _show_alias: location_list = [ "{0} ({1})".format(location, alias) for (location, alias) in zip(location_list, alias_list) ] choice_list = [".."] + location_list choice = dialog.select(header, choice_list, preselect=choice) if choice == 0: exit_menu = True elif choice == -1: sys.exit(0) else: server_list_context_menu(alias_list[choice - 1])
def server_list_continent_menu(): exit_menu = False while not exit_menu: header = addon_utils.name if expressVPN.is_connected(): header = "{0} - {1} {2}".format(header, addon_utils.localize(30001), expressVPN.connected_location()) choice_list = [".."] + addon_utils.localize(30016, 30017, 30018, 30019, 30020, 30021) choice = dialog.select(header, choice_list) if choice == 0: exit_menu = True elif choice == -1: sys.exit(0) else: server_list_country_menu(continent=choice_list[choice], recommended=False)
def server_list_menu(): exit_menu = False while not exit_menu: header = addon_utils.name if expressVPN.is_connected(): header = "{0} - {1} {2}".format(header, addon_utils.localize(30001), expressVPN.connected_location()) choice_list = [".."] + addon_utils.localize(30006, 30007, 30008, 30009) choice = dialog.select(header, choice_list) if choice == 0: exit_menu = True elif choice == 1: server_list_continent_menu() elif choice == 2: favourites_menu() elif choice == 3: server_list_country_menu(recommended=True) elif choice == 4: refreshVPN() else: sys.exit(0)