Skip to content

Commit ede4851

Browse files
neox387mmarquezs
authored andcommitted
Cleanup
1 parent f34d0bd commit ede4851

File tree

1 file changed

+42
-40
lines changed

1 file changed

+42
-40
lines changed

myjdapi/myjdapi.py

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ def update_available(self):
125125
resp = self.is_update_available()
126126
return resp
127127

128+
128129
class DownloadController:
129130
"""
130131
Class that represents the download-controller of a Device
@@ -203,15 +204,15 @@ def clear_list(self):
203204
resp = self.device.action(self.url + "/clearList", http_action="POST")
204205
return resp
205206

206-
def move_to_downloadlist(self, links_ids, packages_ids):
207+
def move_to_downloadlist(self, link_ids, package_ids):
207208
"""
208209
Moves packages and/or links to download list.
209210
210-
:param packages: Packages UUID.
211+
:param package_ids: Package UUID's.
211212
:type: list of strings.
212-
:param links: Links UUID.
213+
:param link_ids: Link UUID's.
213214
"""
214-
params = [links_ids, packages_ids]
215+
params = [link_ids, package_ids]
215216
resp = self.device.action(self.url + "/moveToDownloadlist", params)
216217
return resp
217218

@@ -280,15 +281,15 @@ def cleanup(self,
280281
action,
281282
mode,
282283
selection_type,
283-
links_ids=[],
284-
packages_ids=[]):
284+
link_ids=[],
285+
package_ids=[]):
285286
"""
286287
Clean packages and/or links of the linkgrabber list.
287-
Requires at least a packages_ids or links_ids list, or both.
288+
Requires at least a package_ids or link_ids list, or both.
288289
289-
:param packages_ids: Packages UUID.
290+
:param package_ids: Package UUID's.
290291
:type: list of strings.
291-
:param links_ids: Links UUID.
292+
:param link_ids: link UUID's.
292293
:type: list of strings
293294
:param action: Action to be done. Actions: DELETE_ALL, DELETE_DISABLED, DELETE_FAILED, DELETE_FINISHED, DELETE_OFFLINE, DELETE_DUPE, DELETE_MODE
294295
:type: str:
@@ -297,7 +298,7 @@ def cleanup(self,
297298
:param selection_type: Type of selection to use. Types: SELECTED, UNSELECTED, ALL, NONE
298299
:type: str:
299300
"""
300-
params = [links_ids, packages_ids]
301+
params = [link_ids, package_ids]
301302
params += [action, mode, selection_type]
302303
resp = self.device.action(self.url + "/cleanup", params)
303304
return resp
@@ -316,33 +317,33 @@ def add_container(self, type_, content):
316317
resp = self.device.action(self.url + "/addContainer", params)
317318
return resp
318319

319-
def get_download_urls(self, links_ids, packages_ids, url_display_type):
320+
def get_download_urls(self, link_ids, package_ids, url_display_type):
320321
"""
321322
Gets download urls from Linkgrabber.
322323
323-
:param packages_ids: Packages UUID.
324+
:param package_ids: Package UUID's.
324325
:type: List of strings.
325-
:param Links_ids: Links UUID.
326+
:param link_ids: link UUID's.
326327
:type: List of strings
327328
:param url_display_type: No clue. Not documented
328329
:type: Dictionary
329330
"""
330-
params = [packages_ids, links_ids, url_display_type]
331+
params = [package_ids, link_ids, url_display_type]
331332
resp = self.device.action(self.url + "/getDownloadUrls", params)
332333
return resp
333334

334-
def set_priority(self, priority, links_ids, packages_ids):
335+
def set_priority(self, priority, link_ids, package_ids):
335336
"""
336337
Sets the priority of links or packages.
337338
338-
:param packages_ids: Packages UUID.
339+
:param package_ids: Package UUID's.
339340
:type: list of strings.
340-
:param links_ids: Links UUID.
341+
:param link_ids: link UUID's.
341342
:type: list of strings
342343
:param priority: Priority to set. Priorities: HIGHEST, HIGHER, HIGH, DEFAULT, LOWER;
343344
:type: str:
344345
"""
345-
params = [priority, links_ids, packages_ids]
346+
params = [priority, link_ids, package_ids]
346347
resp = self.device.action(self.url + "/setPriority", params)
347348
return resp
348349

@@ -488,6 +489,7 @@ def add_variant_copy(self):
488489
"""
489490
pass
490491

492+
491493
class Toolbar:
492494
"""
493495
Class that represents the toolbar of a Device
@@ -518,6 +520,7 @@ def disable_downloadSpeedLimit(self):
518520
if self.limit_enabled:
519521
self.device.action(self.url + "/toggleDownloadSpeedLimit")
520522

523+
521524
class Downloads:
522525
"""
523526
Class that represents the downloads list of a Device
@@ -581,15 +584,15 @@ def cleanup(self,
581584
action,
582585
mode,
583586
selection_type,
584-
links_ids=[],
585-
packages_ids=[]):
587+
link_ids=[],
588+
package_ids=[]):
586589
"""
587590
Clean packages and/or links of the linkgrabber list.
588-
Requires at least a packages_ids or links_ids list, or both.
591+
Requires at least a package_ids or link_ids list, or both.
589592
590-
:param packages_ids: Packages UUID.
593+
:param package_ids: Package UUID's.
591594
:type: list of strings.
592-
:param links_ids: Links UUID.
595+
:param link_ids: link UUID's.
593596
:type: list of strings
594597
:param action: Action to be done. Actions: DELETE_ALL, DELETE_DISABLED, DELETE_FAILED, DELETE_FINISHED, DELETE_OFFLINE, DELETE_DUPE, DELETE_MODE
595598
:type: str:
@@ -598,7 +601,7 @@ def cleanup(self,
598601
:param selection_type: Type of selection to use. Types: SELECTED, UNSELECTED, ALL, NONE
599602
:type: str:
600603
"""
601-
params = [links_ids, packages_ids]
604+
params = [link_ids, package_ids]
602605
params += [action, mode, selection_type]
603606
resp = self.device.action(self.url + "/cleanup", params)
604607
return resp
@@ -635,9 +638,9 @@ def __refresh_direct_connections(self):
635638
response = self.myjd.request_api("/device/getDirectConnectionInfos",
636639
"POST", None, self.__action_url())
637640
if response is not None \
638-
and 'data' in response \
639-
and 'infos' in response["data"] \
640-
and len(response["data"]["infos"])!=0:
641+
and 'data' in response \
642+
and 'infos' in response["data"] \
643+
and len(response["data"]["infos"]) != 0:
641644
self.__update_direct_connections(response["data"]["infos"])
642645

643646
def __update_direct_connections(self, direct_info):
@@ -656,7 +659,7 @@ def __update_direct_connections(self, direct_info):
656659
tmp.remove(i)
657660
else:
658661
direct_info.remove(i['conn'])
659-
#We add new connections
662+
# We add new connections
660663
for conn in direct_info:
661664
tmp.append({'conn': conn, 'cooldown': 0})
662665
self.__direct_connection_info = tmp
@@ -680,7 +683,7 @@ def action(self, path, params=(), http_action="POST"):
680683
"""
681684
action_url = self.__action_url()
682685
if not self.__direct_connection_enabled or self.__direct_connection_info is None \
683-
or time.time() < self.__direct_connection_cooldown:
686+
or time.time() < self.__direct_connection_cooldown:
684687
# No direct connection available, we use My.JDownloader api.
685688
response = self.myjd.request_api(path, http_action, params,
686689
action_url)
@@ -691,7 +694,7 @@ def action(self, path, params=(), http_action="POST"):
691694
# My.JDownloader Api worked, lets refresh the direct connections and return
692695
# the response.
693696
if self.__direct_connection_enabled \
694-
and time.time() >= self.__direct_connection_cooldown:
697+
and time.time() >= self.__direct_connection_cooldown:
695698
self.__refresh_direct_connections()
696699
return response['data']
697700
else:
@@ -724,11 +727,10 @@ def action(self, path, params=(), http_action="POST"):
724727
if response is None:
725728
# My.JDownloader Api failed too.
726729
return False
727-
# My.JDownloader Api worked, lets refresh the direct connections and return
728-
# the response.
730+
# My.JDownloader Api worked, lets refresh the direct connections and return
731+
# the response.
729732
self.__refresh_direct_connections()
730733
return response['data']
731-
return False
732734

733735
def __action_url(self):
734736
return "/t_" + self.myjd.get_session_token() + "_" + self.device_id
@@ -992,14 +994,14 @@ def request_api(self,
992994
if self.__server_encryption_token is None:
993995
query += [
994996
"signature=" \
995-
+ str(self.__signature_create(self.__login_secret,
996-
query[0] + "&".join(query[1:])))
997+
+ str(self.__signature_create(self.__login_secret,
998+
query[0] + "&".join(query[1:])))
997999
]
9981000
else:
9991001
query += [
10001002
"signature=" \
1001-
+ str(self.__signature_create(self.__server_encryption_token,
1002-
query[0] + "&".join(query[1:])))
1003+
+ str(self.__signature_create(self.__server_encryption_token,
1004+
query[0] + "&".join(query[1:])))
10031005
]
10041006
query = query[0] + "&".join(query[1:])
10051007
encrypted_response = requests.get(api + query, timeout=3)
@@ -1047,9 +1049,9 @@ def request_api(self,
10471049
error_msg = json.loads(self.__decrypt(self.__device_encryption_token, encrypted_response.text))
10481050
except json.JSONDecodeError:
10491051
raise MYJDException("Failed to decode response: {}", encrypted_response.text)
1050-
msg="\n\tSOURCE: "+error_msg["src"]+"\n\tTYPE: "+ \
1051-
error_msg["type"]+"\n------\nREQUEST_URL: "+ \
1052-
api+path
1052+
msg = "\n\tSOURCE: " + error_msg["src"] + "\n\tTYPE: " + \
1053+
error_msg["type"] + "\n------\nREQUEST_URL: " + \
1054+
api + path
10531055
if http_method == "GET":
10541056
msg += query
10551057
msg += "\n"

0 commit comments

Comments
 (0)