-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaddon.py
120 lines (91 loc) · 3.88 KB
/
addon.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# This file is part of ExpressVPN For Kodi.
# ExpressVPN For Kodi is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# ExpressVPN For Kodi is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with ExpressVPN For Kodi. If not, see <http://www.gnu.org/licenses/>.
import resources.lib.expressvpn as expressvpn
import resources.lib.settings as settings
import resources.lib.utils as utils
import sys
_expressvpn = expressvpn.ExpressVPN()
_settings = settings.Settings()
_utils = utils.Utils()
if (__name__ == "__main__"):
parameterCount = _utils.getArgC()
# Usage: expressvpn or expressvpn connect or expressvpn connect server
if parameterCount == 1 or ((parameterCount == 2 or parameterCount == 3) and _utils.getArgV(1) == "connect"):
# If already connected, ask user if they want to disconnect (also show current server)
if _expressvpn.isConnected():
disconnect = _utils.showYesNo(_utils.getString(32101), _utils.getString(32102) % _expressvpn.currentServer(), "", _utils.getString(32103), _utils.getString(32104), _utils.getString(32105))
# If user wants to disconect, disconnect
if (disconnect):
disconnected = _expressvpn.disconnect()
# If disconnection is successful, notify user
if (disconnected):
_utils.showNotification(_utils.getString(32106))
else:
_utils.showNotification(_utils.getString(32107))
sys.exit()
else:
sys.exit()
# Usage: expressvpn connect [server]
if (parameterCount == 3):
server = _utils.getArgV(2)
# Haven't specified a server so work out which one to use
else:
defaultServer = _settings["default"]
# If default is the only server available then use it
if _settings["additional"] == "":
server = defaultServer
# Otherwise build list and prompt user
else:
serverList = _settings["additional"].split(",")
serverList = map(lambda x: x.strip(), serverList)
serverList.insert(0, defaultServer)
serverIndex = _utils.showSelect("Select Server", serverList)
# Has user tried to cancel out of the select box? If so, exit
if (serverIndex == -1):
sys.exit()
# Use server that user selected
server = serverList[serverIndex]
# Try connecting
_utils.showNotification(_utils.getString(32108))
connected = _expressvpn.connect(server)
# Notify user is successful or not
if connected:
_utils.showNotification(_utils.getString(32109) % server)
else:
_utils.showNotification(_utils.getString(32110), False)
# expressvpn disconnect, expressvpn status, expressvpn list etc...
elif parameterCount == 2:
if _utils.getArgV(1) == "disconnect":
# If not connected, tell user there is nothing to do and exit
if not _expressvpn.isConnected():
_utils.showNotification(_utils.getString(21111))
sys.exit()
# Try and disconnect
_utils.showNotification(_utils.getString(32112))
disconnected = _expressvpn.disconnect()
# Notify user if successful or not
if disconnected:
_utils.showNotification(_utils.getString(32106))
else:
_utils.showNotification(_utils.getString(32107), False)
# Show user which server they are connected to
elif _utils.getArgV(1) == "status":
_utils.showNotification(_expressvpn.status())
# Show user a list of available servers
elif _utils.getArgV(1) == "list":
_utils.showTextviewer(_expressvpn.serverList())
# Invalid command so show usage
else:
_expressvpn.showUsage()
# Invalid command so show usage
else:
_expressvpn.showUsage()