Merge pull request #20 from themoosman/add-getters

Update README (implemented methods), add more getters
This commit is contained in:
Alano Terblanche
2020-10-29 23:37:05 +02:00
committed by GitHub
17 changed files with 469 additions and 46 deletions

View File

@@ -32,36 +32,36 @@ This project intends to stick with [PEP8](https://www.python.org/dev/peps/pep-00
GET: GET:
- [X] Login - [X] Login
- [X] Logout - [X] Logout
- [ ] Display -> OSD - [X] Display -> OSD
- [ ] Recording -> Encode (Clear and Fluent Stream) - [X] Recording -> Encode (Clear and Fluent Stream)
- [ ] Recording -> Advance (Scheduling) - [X] Recording -> Advance (Scheduling)
- [X] Network -> General - [X] Network -> General
- [X] Network -> Advanced - [X] Network -> Advanced
- [ ] Network -> DDNS - [X] Network -> DDNS
- [ ] Network -> NTP - [X] Network -> NTP
- [ ] Network -> E-mail - [X] Network -> E-mail
- [ ] Network -> FTP - [X] Network -> FTP
- [ ] Network -> Push - [X] Network -> Push
- [X] Network -> WIFI - [X] Network -> WIFI
- [ ] Alarm -> Motion - [X] Alarm -> Motion
- [X] System -> General - [X] System -> General
- [ ] System -> DST - [X] System -> DST
- [ ] System -> Information - [X] System -> Information
- [ ] System -> Maintenance - [ ] System -> Maintenance
- [ ] System -> Performance - [X] System -> Performance
- [ ] System -> Reboot - [ ] System -> Reboot
- [ ] User -> Online User - [X] User -> Online User
- [ ] User -> Add User - [X] User -> Add User
- [ ] User -> Manage User - [X] User -> Manage User
- [ ] Device -> HDD/SD Card - [X] Device -> HDD/SD Card
- [ ] Zoom - [ ] Zoom
- [ ] Focus - [ ] Focus
- [ ] Image (Brightness, Contrass, Saturation, Hue, Sharp, Mirror, Rotate) - [ ] Image (Brightness, Contrast, Saturation, Hue, Sharp, Mirror, Rotate)
- [ ] Advanced Image (Anti-flicker, Exposure, White Balance, DayNight, Backlight, LED light, 3D-NR) - [ ] Advanced Image (Anti-flicker, Exposure, White Balance, DayNight, Backlight, LED light, 3D-NR)
- [ ] Image Data -> "Snap" Frame from Video Stream - [X] Image Data -> "Snap" Frame from Video Stream
SET: SET:
- [ ] Display -> OSD - [X] Display -> OSD
- [ ] Recording -> Encode (Clear and Fluent Stream) - [ ] Recording -> Encode (Clear and Fluent Stream)
- [ ] Recording -> Advance (Scheduling) - [ ] Recording -> Advance (Scheduling)
- [X] Network -> General - [X] Network -> General
@@ -73,15 +73,15 @@ SET:
- [ ] Network -> Push - [ ] Network -> Push
- [X] Network -> WIFI - [X] Network -> WIFI
- [ ] Alarm -> Motion - [ ] Alarm -> Motion
- [X] System -> General - [ ] System -> General
- [ ] System -> DST - [ ] System -> DST
- [X] System -> Reboot - [X] System -> Reboot
- [ ] User -> Online User - [X] User -> Online User
- [ ] User -> Add User - [X] User -> Add User
- [ ] User -> Manage User - [X] User -> Manage User
- [ ] Device -> HDD/SD Card - [X] Device -> HDD/SD Card (Format)
- [x] PTZ - [x] PTZ
- [x] Zoom - [x] Zoom
- [x] Focus - [x] Focus
- [ ] Image (Brightness, Contrass, Saturation, Hue, Sharp, Mirror, Rotate) - [ ] Image (Brightness, Contrast, Saturation, Hue, Sharp, Mirror, Rotate)
- [ ] Advanced Image (Anti-flicker, Exposure, White Balance, DayNight, Backlight, LED light, 3D-NR) - [ ] Advanced Image (Anti-flicker, Exposure, White Balance, DayNight, Backlight, LED light, 3D-NR)

View File

@@ -6,6 +6,7 @@ from .network import NetworkAPIMixin
from .system import SystemAPIMixin from .system import SystemAPIMixin
from .user import UserAPIMixin from .user import UserAPIMixin
from .ptz import PtzAPIMixin from .ptz import PtzAPIMixin
from .alarm import AlarmAPIMixin
from resthandle import Request from resthandle import Request
@@ -16,7 +17,8 @@ class APIHandler(SystemAPIMixin,
DisplayAPIMixin, DisplayAPIMixin,
RecordingAPIMixin, RecordingAPIMixin,
ZoomAPIMixin, ZoomAPIMixin,
PtzAPIMixin): PtzAPIMixin,
AlarmAPIMixin):
""" """
The APIHandler class is the backend part of the API, the actual API calls The APIHandler class is the backend part of the API, the actual API calls
are implemented in Mixins. are implemented in Mixins.

View File

@@ -1,4 +1,4 @@
from .APIHandler import APIHandler from .APIHandler import APIHandler
__version__ = "0.0.1" __version__ = "0.0.2"
VERSION = __version__ VERSION = __version__

11
api/alarm.py Normal file
View File

@@ -0,0 +1,11 @@
class AlarmAPIMixin:
"""API calls for getting device alarm information."""
def get_alarm_motion(self) -> object:
"""
Gets the device alarm motion
See examples/response/GetAlarmMotion.json for example response data.
:return: response json
"""
body = [{"cmd": "GetAlarm", "action": 1, "param": {"Alarm": {"channel": 0, "type": "md"}}}]
return self._execute_command('GetAlarm', body)

View File

@@ -36,6 +36,7 @@ class NetworkAPIMixin:
def get_net_ports(self) -> object: def get_net_ports(self) -> object:
""" """
Get network ports Get network ports
See examples/response/GetNetworkAdvanced.json for example response data.
:return: response json :return: response json
""" """
body = [{"cmd": "GetNetPort", "action": 1, "param": {}}, body = [{"cmd": "GetNetPort", "action": 1, "param": {}},
@@ -50,3 +51,65 @@ class NetworkAPIMixin:
def scan_wifi(self): def scan_wifi(self):
body = [{"cmd": "ScanWifi", "action": 1, "param": {}}] body = [{"cmd": "ScanWifi", "action": 1, "param": {}}]
return self._execute_command('ScanWifi', body) return self._execute_command('ScanWifi', body)
def get_network_general(self) -> object:
"""
Get the camera information
See examples/response/GetNetworkGeneral.json for example response data.
:return: response json
"""
body = [{"cmd": "GetLocalLink", "action": 0, "param": {}}]
return self._execute_command('GetLocalLink', body)
def get_network_ddns(self) -> object:
"""
Get the camera DDNS network information
See examples/response/GetNetworkDDNS.json for example response data.
:return: response json
"""
body = [{"cmd": "GetDdns", "action": 0, "param": {}}]
return self._execute_command('GetDdns', body)
def get_network_ntp(self) -> object:
"""
Get the camera NTP network information
See examples/response/GetNetworkNTP.json for example response data.
:return: response json
"""
body = [{"cmd": "GetNtp", "action": 0, "param": {}}]
return self._execute_command('GetNtp', body)
def get_network_email(self) -> object:
"""
Get the camera email network information
See examples/response/GetNetworkEmail.json for example response data.
:return: response json
"""
body = [{"cmd": "GetEmail", "action": 0, "param": {}}]
return self._execute_command('GetEmail', body)
def get_network_ftp(self) -> object:
"""
Get the camera FTP network information
See examples/response/GetNetworkFtp.json for example response data.
:return: response json
"""
body = [{"cmd": "GetFtp", "action": 0, "param": {}}]
return self._execute_command('GetFtp', body)
def get_network_push(self) -> object:
"""
Get the camera push network information
See examples/response/GetNetworkPush.json for example response data.
:return: response json
"""
body = [{"cmd": "GetPush", "action": 0, "param": {}}]
return self._execute_command('GetPush', body)
def get_network_status(self) -> object:
"""
Get the camera status network information
See examples/response/GetNetworkGeneral.json for example response data.
:return: response json
"""
return self.get_network_general()

View File

@@ -1,12 +1,10 @@
import io import requests
import random import random
import string import string
from urllib import request from urllib import parse
from io import BytesIO
from PIL import Image from PIL import Image
from RtspClient import RtspClient from RtspClient import RtspClient
from resthandle import Request
class RecordingAPIMixin: class RecordingAPIMixin:
@@ -43,25 +41,26 @@ class RecordingAPIMixin:
proxies={"host": "127.0.0.1", "port": 8000}) as rtsp_client: proxies={"host": "127.0.0.1", "port": 8000}) as rtsp_client:
rtsp_client.preview() rtsp_client.preview()
def get_snap(self, timeout: int = 3) -> Image or None: def get_snap(self, timeout: int = 3, proxies=None) -> Image or None:
""" """
Gets a "snap" of the current camera video data and returns a Pillow Image or None Gets a "snap" of the current camera video data and returns a Pillow Image or None
:param timeout: Request timeout to camera in seconds :param timeout: Request timeout to camera in seconds
:param proxies: http/https proxies to pass to the request object.
:return: Image or None :return: Image or None
""" """
randomstr = ''.join(random.choices(string.ascii_uppercase + string.digits, k=10)) data = {}
snap = self.url + "?cmd=Snap&channel=0&rs=" \ data['cmd'] = 'Snap'
+ randomstr \ data['channel'] = 0
+ "&user=" + self.username \ data['rs'] = ''.join(random.choices(string.ascii_uppercase + string.digits, k=10))
+ "&password=" + self.password data['user'] = self.username
data['password'] = self.password
parms = parse.urlencode(data).encode("utf-8")
try: try:
req = request.Request(snap) response = requests.get(self.url, proxies=proxies, params=parms, timeout=timeout)
req.set_proxy(Request.proxies, 'http') if response.status_code == 200:
reader = request.urlopen(req, timeout) return Image.open(BytesIO(response.content))
if reader.status == 200: print("Could not retrieve data from camera successfully. Status:", response.stats_code)
b = bytearray(reader.read())
return Image.open(io.BytesIO(b))
print("Could not retrieve data from camera successfully. Status:", reader.status)
return None return None
except Exception as e: except Exception as e:

View File

@@ -30,3 +30,12 @@ class SystemAPIMixin:
""" """
body = [{"cmd": "Reboot", "action": 0, "param": {}}] body = [{"cmd": "Reboot", "action": 0, "param": {}}]
return self._execute_command('Reboot', body) return self._execute_command('Reboot', body)
def get_dst(self) -> object:
"""
Get the camera DST information
See examples/response/GetDSTInfo.json for example response data.
:return: response json
"""
body = [{"cmd": "GetTime", "action": 0, "param": {}}]
return self._execute_command('GetTime', body)

View File

@@ -0,0 +1,150 @@
[
{
"cmd": "GetAlarm",
"code": 0,
"initial": {
"Alarm": {
"action": { "mail": 1, "push": 1, "recChannel": [0] },
"channel": 0,
"enable": 1,
"schedule": {
"table": "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"
},
"scope": {
"cols": 80,
"rows": 45,
"table": "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"
},
"sens": [
{
"beginHour": 0,
"beginMin": 0,
"endHour": 6,
"endMin": 0,
"sensitivity": 10
},
{
"beginHour": 6,
"beginMin": 0,
"endHour": 12,
"endMin": 0,
"sensitivity": 10
},
{
"beginHour": 12,
"beginMin": 0,
"endHour": 18,
"endMin": 0,
"sensitivity": 10
},
{
"beginHour": 18,
"beginMin": 0,
"endHour": 23,
"endMin": 59,
"sensitivity": 10
}
],
"type": "md"
}
},
"range": {
"Alarm": {
"action": { "mail": "boolean", "push": "boolean", "recChannel": [0] },
"channel": 0,
"enable": "boolean",
"schedule": { "table": { "maxLen": 168, "minLen": 168 } },
"scope": {
"cols": { "max": 80, "min": 80 },
"rows": { "max": 45, "min": 45 },
"table": { "maxLen": 8159 }
},
"sens": [
{
"beginHour": { "max": 23, "min": 0 },
"beginMin": { "max": 59, "min": 0 },
"endHour": { "max": 23, "min": 0 },
"endMin": { "max": 59, "min": 0 },
"id": 0,
"sensitivity": { "max": 50, "min": 1 }
},
{
"beginHour": { "max": 23, "min": 0 },
"beginMin": { "max": 59, "min": 0 },
"endHour": { "max": 23, "min": 0 },
"endMin": { "max": 59, "min": 0 },
"id": 1,
"sensitivity": { "max": 50, "min": 1 }
},
{
"beginHour": { "max": 23, "min": 0 },
"beginMin": { "max": 59, "min": 0 },
"endHour": { "max": 23, "min": 0 },
"endMin": { "max": 59, "min": 0 },
"id": 2,
"sensitivity": { "max": 50, "min": 1 }
},
{
"beginHour": { "max": 23, "min": 0 },
"beginMin": { "max": 59, "min": 0 },
"endHour": { "max": 23, "min": 0 },
"endMin": { "max": 59, "min": 0 },
"id": 3,
"sensitivity": { "max": 50, "min": 1 }
}
],
"type": "md"
}
},
"value": {
"Alarm": {
"action": { "mail": 1, "push": 1, "recChannel": [0] },
"channel": 0,
"enable": 1,
"schedule": {
"table": "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"
},
"scope": {
"cols": 80,
"rows": 45,
"table": "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"
},
"sens": [
{
"beginHour": 0,
"beginMin": 0,
"endHour": 6,
"endMin": 0,
"id": 0,
"sensitivity": 10
},
{
"beginHour": 6,
"beginMin": 0,
"endHour": 12,
"endMin": 0,
"id": 1,
"sensitivity": 10
},
{
"beginHour": 12,
"beginMin": 0,
"endHour": 18,
"endMin": 0,
"id": 2,
"sensitivity": 10
},
{
"beginHour": 18,
"beginMin": 0,
"endHour": 23,
"endMin": 59,
"id": 3,
"sensitivity": 10
}
],
"type": "md"
}
}
}
]

View File

@@ -0,0 +1,35 @@
[
{
"cmd": "GetTime",
"code": 0,
"value": {
"Dst": {
"enable": 1,
"endHour": 2,
"endMin": 0,
"endMon": 11,
"endSec": 0,
"endWeek": 1,
"endWeekday": 0,
"offset": 1,
"startHour": 2,
"startMin": 0,
"startMon": 3,
"startSec": 0,
"startWeek": 1,
"startWeekday": 0
},
"Time": {
"day": 27,
"hour": 18,
"hourFmt": 0,
"min": 50,
"mon": 10,
"sec": 46,
"timeFmt": "MM/DD/YYYY",
"timeZone": 21600,
"year": 2020
}
}
}
]

View File

@@ -0,0 +1,42 @@
[
{
"cmd": "GetNetPort",
"code": 0,
"initial": {
"NetPort": {
"httpPort": 80,
"httpsPort": 443,
"mediaPort": 9000,
"onvifPort": 8000,
"rtmpPort": 1935,
"rtspPort": 554
}
},
"range": {
"NetPort": {
"httpPort": { "max": 65535, "min": 1 },
"httpsPort": { "max": 65535, "min": 1 },
"mediaPort": { "max": 65535, "min": 1 },
"onvifPort": { "max": 65535, "min": 1 },
"rtmpPort": { "max": 65535, "min": 1 },
"rtspPort": { "max": 65535, "min": 1 }
}
},
"value": {
"NetPort": {
"httpPort": 80,
"httpsPort": 443,
"mediaPort": 9000,
"onvifPort": 8000,
"rtmpPort": 1935,
"rtspPort": 554
}
}
},
{ "cmd": "GetUpnp", "code": 0, "value": { "Upnp": { "enable": 0 } } },
{
"cmd": "GetP2p",
"code": 0,
"value": { "P2p": { "enable": 0, "uid": "99999999999999" } }
}
]

View File

@@ -0,0 +1,15 @@
[
{
"cmd": "GetDdns",
"code": 0,
"value": {
"Ddns": {
"domain": "",
"enable": 0,
"password": "",
"type": "no-ip",
"userName": ""
}
}
}
]

View File

@@ -0,0 +1,25 @@
[
{
"cmd": "GetEmail",
"code": 0,
"value": {
"Email": {
"addr1": "",
"addr2": "",
"addr3": "",
"attachment": "picture",
"interval": "5 Minutes",
"nickName": "",
"password": "",
"schedule": {
"enable": 1,
"table": "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"
},
"smtpPort": 465,
"smtpServer": "smtp.gmail.com",
"ssl": 1,
"userName": ""
}
}
}
]

View File

@@ -0,0 +1,24 @@
[
{
"cmd": "GetFtp",
"code": 0,
"value": {
"Ftp": {
"anonymous": 0,
"interval": 30,
"maxSize": 100,
"mode": 0,
"password": "",
"port": 21,
"remoteDir": "",
"schedule": {
"enable": 1,
"table": "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"
},
"server": "",
"streamType": 0,
"userName": ""
}
}
}
]

View File

@@ -0,0 +1,19 @@
[
{
"cmd": "GetLocalLink",
"code": 0,
"value": {
"LocalLink": {
"activeLink": "LAN",
"dns": { "auto": 1, "dns1": "192.168.255.4", "dns2": "192.168.255.4" },
"mac": "EC:71:DB:AA:59:CF",
"static": {
"gateway": "192.168.255.1",
"ip": "192.168.255.58",
"mask": "255.255.255.0"
},
"type": "DHCP"
}
}
}
]

View File

@@ -0,0 +1,14 @@
[
{
"cmd": "GetNtp",
"code": 0,
"value": {
"Ntp": {
"enable": 1,
"interval": 1440,
"port": 123,
"server": "ntp.moos.xyz"
}
}
}
]

View File

@@ -0,0 +1,14 @@
[
{
"cmd": "GetPush",
"code": 0,
"value": {
"Push": {
"schedule": {
"enable": 1,
"table": "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"
}
}
}
}
]

View File

@@ -65,6 +65,7 @@ setup(name=NAME,
'api.recording', 'api.recording',
'api.system', 'api.system',
'api.user', 'api.user',
'api.zoom' 'api.zoom',
'api.alarm'
] ]
) )