Skip to content

Commit 0c89cfd

Browse files
committed
implemented accounts and reconnect endpoints
Accounts class controls premium hoster accounts (including free accounts that increase bandwidth) Reconnect class allows to trigger reconnect in order to get a fresh IP address
1 parent 9877607 commit 0c89cfd

File tree

1 file changed

+201
-2
lines changed

1 file changed

+201
-2
lines changed

myjdapi/myjdapi.py

Lines changed: 201 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,186 @@ def UNPAD(s):
3939
return s[0:-ord(s[-1])]
4040

4141

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+
42222
class System:
43223
"""
44224
Class that represents the system-functionality of a Device
@@ -942,6 +1122,24 @@ def solve(self, captcha_id, solution):
9421122
return resp
9431123

9441124

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+
9451143
class Jddevice:
9461144
"""
9471145
Class that represents a JDownloader device and it's functions
@@ -957,6 +1155,7 @@ def __init__(self, jd, device_dict):
9571155
self.device_id = device_dict["id"]
9581156
self.device_type = device_dict["type"]
9591157
self.myjd = jd
1158+
self.accounts = Accounts(self)
9601159
self.config = Config(self)
9611160
self.linkgrabber = Linkgrabber(self)
9621161
self.captcha = Captcha(self)
@@ -965,6 +1164,7 @@ def __init__(self, jd, device_dict):
9651164
self.downloadcontroller = DownloadController(self)
9661165
self.extensions = Extension(self)
9671166
self.dialogs = Dialog(self)
1167+
self.reconnect = Reconnect(self)
9681168
self.update = Update(self)
9691169
self.system = System(self)
9701170
self.__direct_connection_info = None
@@ -1022,7 +1222,7 @@ def action(self, path, params=(), http_action="POST"):
10221222
/example?param1=ex&param2=ex2 [("param1","ex"),("param2","ex2")]
10231223
:param postparams: List of Params that are send in the post.
10241224
"""
1025-
1225+
10261226
if self.myjd.get_connection_type() == "remoteapi":
10271227
action_url = None
10281228
else:
@@ -1491,4 +1691,3 @@ def __adapt_params_for_request(self, params):
14911691
else:
14921692
params_request += [str(param)]
14931693
return params_request
1494-

0 commit comments

Comments
 (0)