Skip to content

Commit 7bb1231

Browse files
committed
Add get_config, create destination
1 parent 46f7f43 commit 7bb1231

File tree

6 files changed

+73
-31
lines changed

6 files changed

+73
-31
lines changed

synology_dsm/api/download_station/__init__.py

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ def get_info(self):
3434
"""Return general informations about the Download Station instance."""
3535
return self._dsm.get(self.INFO_API_KEY, "GetInfo")
3636

37+
def get_config(self):
38+
"""Return configuration about the Download Station instance."""
39+
return self._dsm.get(self.INFO_API_KEY, "GetConfig")
40+
3741
# Downloads
3842
def get_all_tasks(self):
3943
"""Return a list of tasks."""
@@ -43,26 +47,49 @@ def get_task(self, task_id):
4347
"""Return task matching task_id."""
4448
return self._tasks_by_id[task_id]
4549

46-
def create(self, uri, unzip_password=None):
50+
def create(self, uri, unzip_password=None, destination=None):
4751
"""Create a new task (uri accepts HTTP/FTP/magnet/ED2K links)."""
48-
return self._dsm.post(
52+
res = self._dsm.post(
4953
self.TASK_API_KEY,
50-
"create",
51-
{"uri": ",".join(uri), "unzip_password": unzip_password},
54+
"Create",
55+
{
56+
"uri": ",".join(uri) if isinstance(uri, list) else uri,
57+
"unzip_password": unzip_password,
58+
"destination": destination,
59+
},
5260
)
61+
self.update()
62+
return res
5363

5464
def pause(self, task_id):
5565
"""Pause a download task."""
56-
return self._dsm.get(self.TASK_API_KEY, "pause", {"id": ",".join(task_id)})
66+
res = self._dsm.get(
67+
self.TASK_API_KEY,
68+
"Pause",
69+
{"id": ",".join(task_id) if isinstance(task_id, list) else task_id},
70+
)
71+
self.update()
72+
return res
5773

5874
def resume(self, task_id):
5975
"""Resume a paused download task."""
60-
return self._dsm.get(self.TASK_API_KEY, "resume", {"id": ",".join(task_id)})
76+
res = self._dsm.get(
77+
self.TASK_API_KEY,
78+
"Resume",
79+
{"id": ",".join(task_id) if isinstance(task_id, list) else task_id},
80+
)
81+
self.update()
82+
return res
6183

6284
def delete(self, task_id, force_complete=False):
6385
"""Delete a download task."""
64-
return self._dsm.get(
86+
res = self._dsm.get(
6587
self.TASK_API_KEY,
66-
"delete",
67-
{"id": ",".join(task_id), "force_complete": force_complete},
88+
"Delete",
89+
{
90+
"id": ",".join(task_id) if isinstance(task_id, list) else task_id,
91+
"force_complete": force_complete,
92+
},
6893
)
94+
self.update()
95+
return res

synology_dsm/synology_dsm.py

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,9 @@ def get(self, api, method, params=None, **kwargs):
185185
"""Handles API GET request."""
186186
return self._request("GET", api, method, params, **kwargs)
187187

188-
def post(self, api, method, params=None, data=None, json=None, **kwargs):
188+
def post(self, api, method, params=None, **kwargs):
189189
"""Handles API POST request."""
190-
return self._request(
191-
"POST", api, method, params, data=data, json=json, **kwargs
192-
)
190+
return self._request("POST", api, method, params, **kwargs)
193191

194192
def _request(
195193
self, request_method, api, method, params=None, retry_once=True, **kwargs
@@ -229,20 +227,6 @@ def _request(
229227

230228
url = self._build_url(api)
231229

232-
# If the request method is POST and the API is SynoCoreShare the params
233-
# to the request body. Used to support the weird Syno use of POST
234-
# to choose what fields to return. See ./api/core/share.py
235-
# for an example.
236-
if request_method == "POST" and api == SynoCoreShare.API_KEY:
237-
body = {}
238-
body.update(params)
239-
body.update(kwargs.pop("data"))
240-
body["mimeType"] = "application/json"
241-
# Request data via POST (excluding FileStation file uploads)
242-
self._debuglog("POST BODY: " + str(body))
243-
244-
kwargs["data"] = body
245-
246230
# Request data
247231
response = self._execute_request(request_method, url, params, **kwargs)
248232
self._debuglog("Request Method: " + request_method)
@@ -281,6 +265,13 @@ def _execute_request(self, method, url, params, **kwargs):
281265
url, params=encoded_params, timeout=self._timeout, **kwargs
282266
)
283267
elif method == "POST":
268+
data = {}
269+
data.update(params)
270+
data.update(kwargs.pop("data", {}))
271+
data["mimeType"] = "application/json"
272+
kwargs["data"] = data
273+
self._debuglog("POST data: " + str(data))
274+
284275
response = self._session.post(
285276
url, params=params, timeout=self._timeout, **kwargs
286277
)

tests/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
DSM_6_SURVEILLANCE_STATION_CAMERA_LIST,
4646
DSM_6_SURVEILLANCE_STATION_HOME_MODE_GET_INFO,
4747
DSM_6_SURVEILLANCE_STATION_HOME_MODE_SWITCH,
48-
DSM_6_DOWNLOAD_STATION_INFO,
48+
DSM_6_DOWNLOAD_STATION_INFO_INFO,
49+
DSM_6_DOWNLOAD_STATION_INFO_CONFIG,
4950
DSM_6_DOWNLOAD_STATION_TASK_LIST,
5051
)
5152
from .api_data.dsm_5 import (
@@ -217,7 +218,9 @@ def _execute_request(self, method, url, params, **kwargs):
217218

218219
if SynoDownloadStation.TASK_API_KEY in url:
219220
if "GetInfo" in url:
220-
return DSM_6_DOWNLOAD_STATION_INFO
221+
return DSM_6_DOWNLOAD_STATION_INFO_INFO
222+
if "GetConfig" in url:
223+
return DSM_6_DOWNLOAD_STATION_INFO_CONFIG
221224
if "List" in url:
222225
return DSM_6_DOWNLOAD_STATION_TASK_LIST
223226

tests/api_data/dsm_6/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
DSM_6_CORE_SECURITY,
1414
DSM_6_CORE_SECURITY_UPDATE_OUTOFDATE,
1515
)
16-
from .download_station.const_6_download_station_info import DSM_6_DOWNLOAD_STATION_INFO
16+
from .download_station.const_6_download_station_info import (
17+
DSM_6_DOWNLOAD_STATION_INFO_INFO,
18+
DSM_6_DOWNLOAD_STATION_INFO_CONFIG,
19+
)
1720
from .download_station.const_6_download_station_task import (
1821
DSM_6_DOWNLOAD_STATION_TASK_LIST,
1922
)
Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
11
# -*- coding: utf-8 -*-
22
"""DSM 6 SYNO.DownloadStation.Info data."""
33

4-
DSM_6_DOWNLOAD_STATION_INFO = {
4+
DSM_6_DOWNLOAD_STATION_INFO_INFO = {
55
"data": {"is_manager": True, "version": 3543, "version_string": "3.8-3543"},
66
"success": True,
77
}
8+
9+
DSM_6_DOWNLOAD_STATION_INFO_CONFIG = {
10+
"data": {
11+
"bt_max_download": 0,
12+
"bt_max_upload": 800,
13+
"default_destination": "downloads",
14+
"emule_default_destination": None,
15+
"emule_enabled": False,
16+
"emule_max_download": 0,
17+
"emule_max_upload": 20,
18+
"ftp_max_download": 0,
19+
"http_max_download": 0,
20+
"nzb_max_download": 0,
21+
"unzip_service_enabled": False,
22+
},
23+
"success": True,
24+
}

tests/test_synology_dsm.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,7 @@ def test_download_station(self):
704704
assert not self.api.download_station.get_all_tasks()
705705

706706
assert self.api.download_station.get_info()
707+
assert self.api.download_station.get_config()
707708
self.api.download_station.update()
708709
assert self.api.download_station.get_all_tasks()
709710
assert len(self.api.download_station.get_all_tasks()) == 8

0 commit comments

Comments
 (0)