Skip to content

Commit c16189a

Browse files
committed
add nvrdownload command
1 parent f151711 commit c16189a

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

reolinkapi/handlers/api_handler.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from reolinkapi.mixins.system import SystemAPIMixin
1515
from reolinkapi.mixins.user import UserAPIMixin
1616
from reolinkapi.mixins.zoom import ZoomAPIMixin
17+
from reolinkapi.mixins.nvrdownload import NvrDownloadAPIMixin
1718

1819

1920
class APIHandler(AlarmAPIMixin,
@@ -28,7 +29,8 @@ class APIHandler(AlarmAPIMixin,
2829
SystemAPIMixin,
2930
UserAPIMixin,
3031
ZoomAPIMixin,
31-
StreamAPIMixin):
32+
StreamAPIMixin,
33+
NvrDownloadAPIMixin):
3234
"""
3335
The APIHandler class is the backend part of the API, the actual API calls
3436
are implemented in Mixins.

reolinkapi/mixins/nvrdownload.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
from datetime import datetime as dt
2+
3+
class NvrDownloadAPIMixin:
4+
"""API calls for NvrDownload."""
5+
def get_playback_files(self, start: dt, end: dt = dt.now(), channel: int = 0,
6+
streamtype: str = 'sub'):
7+
"""
8+
Get the filenames of the videos for the time range provided.
9+
10+
Args:
11+
start: the starting time range to examine
12+
end: the end time of the time range to examine
13+
channel: which channel to download from
14+
streamtype: 'main' or 'sub' - the stream to examine
15+
:return: response json
16+
"""
17+
search_params = {
18+
'NvrDownload': {
19+
'channel': channel,
20+
'iLogicChannel': 0,
21+
'streamType': streamtype,
22+
'StartTime': {
23+
'year': start.year,
24+
'mon': start.month,
25+
'day': start.day,
26+
'hour': start.hour,
27+
'min': start.minute,
28+
'sec': start.second
29+
},
30+
'EndTime': {
31+
'year': end.year,
32+
'mon': end.month,
33+
'day': end.day,
34+
'hour': end.hour,
35+
'min': end.minute,
36+
'sec': end.second
37+
}
38+
}
39+
}
40+
body = [{"cmd": "NvrDownload", "action": 1, "param": search_params}]
41+
42+
resp = self._execute_command('NvrDownload', body)[0]
43+
if 'value' not in resp:
44+
return []
45+
values = resp['value']
46+
if 'fileList' not in values:
47+
return []
48+
files = values['fileList']
49+
if len(files) > 0:
50+
return [file['fileName'] for file in files]
51+
return []

0 commit comments

Comments
 (0)