@@ -39,6 +39,186 @@ def UNPAD(s):
39
39
return s [0 :- ord (s [- 1 ])]
40
40
41
41
42
+ class Accounts :
43
+ """
44
+ Class that represents the accounts of a Device
45
+ """
46
+
47
+ def __init__ (self , device ):
48
+ self .device = device
49
+ self .url = "/accountsV2"
50
+
51
+ def add_account (self , premium_hoster , username , password ):
52
+ """
53
+ add an account.
54
+
55
+ :param account: Account
56
+ :return:
57
+ """
58
+ params = [premium_hoster , username , password ]
59
+ return self .device .action (self .url + "/addAccount" , params )
60
+
61
+ def add_basic_auth (self , type , hostmask , username , password ):
62
+ """
63
+ add a basic auth account.
64
+
65
+ :param type: Type of the account (either "FTP" or "HTTP")
66
+ :param hostmask: Hostmask of the account (string)
67
+ :param username: Username of the account (string)
68
+ :param password: Password of the account (string)
69
+ :return: account ID (int)
70
+ """
71
+ params = [type , hostmask , username , password ]
72
+ return self .device .action (self .url + "/addBasicAuth" , params )
73
+
74
+ def disable_accounts (self , account_ids ):
75
+ """
76
+ disable accounts with the corresponding account uuids.
77
+
78
+ :param account_ids: Account ID (list of int)
79
+ :return:
80
+ """
81
+ params = [account_ids ]
82
+ return self .device .action (self .url + "/disableAccounts" , params )
83
+
84
+ def enable_accounts (self , account_ids ):
85
+ """
86
+ enable an account with the corresponding account uuids.
87
+
88
+ :param account_ids: Account ID (list of int)
89
+ :return:
90
+ """
91
+ params = [account_ids ]
92
+ return self .device .action (self .url + "/enableAccounts" , params )
93
+
94
+ def get_premium_hoster_url (self , hoster ):
95
+ """
96
+ get the premium hoster url of an account.
97
+
98
+ :param account_id: Account ID (int)
99
+ :return: Premium hoster URL (string)
100
+ """
101
+ params = [hoster ]
102
+ return self .device .action (self .url + "/getPremiumHosterUrl" , params )
103
+
104
+ def list_accounts (
105
+ self ,
106
+ query = [
107
+ {
108
+ "startAt" : 0 ,
109
+ "maxResults" : - 1 ,
110
+ "userName" : True ,
111
+ "validUntil" : True ,
112
+ "trafficLeft" : True ,
113
+ "trafficMax" : True ,
114
+ "enabled" : True ,
115
+ "valid" : True ,
116
+ "error" : False ,
117
+ "UUIDList" : [],
118
+ }
119
+ ],
120
+ ):
121
+ """
122
+ list all accounts.
123
+
124
+ an account is a dictionary with the following schema:
125
+ {
126
+ "hostname": (String),
127
+ "infoMap": (dictionary),
128
+ "uuid": (int),
129
+ }
130
+ The infoMap is a dictionary with the following schema:
131
+
132
+ :return: List<Account>
133
+ """
134
+ return self .device .action (self .url + "/listAccounts" , params = query )
135
+
136
+ def list_basic_auth (self ):
137
+ """
138
+ list all basic auth accounts.
139
+
140
+ :return: List<BasicAuth>
141
+ """
142
+ return self .device .action (self .url + "/listBasicAuth" )
143
+
144
+ def list_premium_hoster (self ):
145
+ """
146
+ list all premium hosters.
147
+
148
+ :return: List<PremiumHoster>
149
+ """
150
+ return self .device .action (self .url + "/listPremiumHoster" )
151
+
152
+ def list_premium_hoster_urls (self ):
153
+ """
154
+ list all premium hoster urls.
155
+
156
+ :return: dict (hoster: url)
157
+ """
158
+ return self .device .action (self .url + "/listPremiumHosterUrls" )
159
+
160
+ def refresh_accounts (self , account_ids ):
161
+ """
162
+ refresh accounts with the corresponding account uuids.
163
+
164
+ :param account_ids: Account ID (list of int)
165
+ :return:
166
+ """
167
+ params = [account_ids ]
168
+ return self .device .action (self .url + "/refreshAccounts" , params )
169
+
170
+ def remove_accounts (self , account_ids ):
171
+ """
172
+ remove accounts with the corresponding account uuids.
173
+
174
+ :param account_ids: Account ID (list of int)
175
+ :return:
176
+ """
177
+ params = [account_ids ]
178
+ return self .device .action (self .url + "/removeAccounts" , params )
179
+
180
+ def remove_basic_auths (self , account_ids ):
181
+ """
182
+ remove basic auth accounts with the corresponding account uuids.
183
+
184
+ :param account_ids: Account ID (list of int)
185
+ :return:
186
+ """
187
+ params = [account_ids ]
188
+ return self .device .action (self .url + "/removeBasicAuths" , params )
189
+
190
+ def set_user_name_and_password (self , account_id , username , password ):
191
+ """
192
+ set the username and password of an account.
193
+
194
+ :param account_id: Account ID (int)
195
+ :param username: Username (string)
196
+ :param password: Password (string)
197
+ :return:
198
+ """
199
+ params = [account_id , username , password ]
200
+ return self .device .action (self .url + "/setUserNameAndPassword" , params )
201
+
202
+ def update_basic_auth (self , basic_auth ):
203
+ """
204
+ update a basic auth account.
205
+
206
+ :param basic_auth: dictionary with the following schema:
207
+ {
208
+ "created": (int),
209
+ "enabled": (boolean),
210
+ "hostmask": (string),
211
+ "id": (int),
212
+ "lastValidated": (int),
213
+ "password": (string),
214
+ "type": (string),
215
+ "username": (string)
216
+ }
217
+ :return: boolean
218
+ """
219
+ return self .device .action (self .url + "/updateBasicAuth" , params = basic_auth )
220
+
221
+
42
222
class System :
43
223
"""
44
224
Class that represents the system-functionality of a Device
@@ -942,6 +1122,24 @@ def solve(self, captcha_id, solution):
942
1122
return resp
943
1123
944
1124
1125
+ class Reconnect :
1126
+ """
1127
+ Class that can triger a reconnect of the internet connection in order to get a new IP address.
1128
+ """
1129
+
1130
+ def __init__ (self , device ):
1131
+ self .device = device
1132
+ self .url = "/reconnect"
1133
+
1134
+ def do_reconnect (self ):
1135
+ """
1136
+ This function triggers a reconnect of the internet connection in order to get a new IP address.
1137
+ :return: Response from the device
1138
+ """
1139
+ resp = self .device .action (self .url + "/doReconnect" )
1140
+ return resp
1141
+
1142
+
945
1143
class Jddevice :
946
1144
"""
947
1145
Class that represents a JDownloader device and it's functions
@@ -957,6 +1155,7 @@ def __init__(self, jd, device_dict):
957
1155
self .device_id = device_dict ["id" ]
958
1156
self .device_type = device_dict ["type" ]
959
1157
self .myjd = jd
1158
+ self .accounts = Accounts (self )
960
1159
self .config = Config (self )
961
1160
self .linkgrabber = Linkgrabber (self )
962
1161
self .captcha = Captcha (self )
@@ -965,6 +1164,7 @@ def __init__(self, jd, device_dict):
965
1164
self .downloadcontroller = DownloadController (self )
966
1165
self .extensions = Extension (self )
967
1166
self .dialogs = Dialog (self )
1167
+ self .reconnect = Reconnect (self )
968
1168
self .update = Update (self )
969
1169
self .system = System (self )
970
1170
self .__direct_connection_info = None
@@ -1022,7 +1222,7 @@ def action(self, path, params=(), http_action="POST"):
1022
1222
/example?param1=ex¶m2=ex2 [("param1","ex"),("param2","ex2")]
1023
1223
:param postparams: List of Params that are send in the post.
1024
1224
"""
1025
-
1225
+
1026
1226
if self .myjd .get_connection_type () == "remoteapi" :
1027
1227
action_url = None
1028
1228
else :
@@ -1491,4 +1691,3 @@ def __adapt_params_for_request(self, params):
1491
1691
else :
1492
1692
params_request += [str (param )]
1493
1693
return params_request
1494
-
0 commit comments