From 82f12e70839cdacfe8b8370d432902d6984d6f1c Mon Sep 17 00:00:00 2001 From: PavelMuhortov Date: Wed, 23 Jun 2021 01:00:19 +0300 Subject: [PATCH] add camsutil --- camsutil/__init__.py | 0 camsutil/ptz.py | 144 ++++++++++++++++++ .../templates/Hikvision_GetCapabilities.html | 3 + camsutil/templates/Hikvision_GetJPEG.html | 3 + camsutil/templates/Hikvision_GetPosition.html | 3 + camsutil/templates/Hikvision_GetReboot.html | 3 + camsutil/templates/Hikvision_GoAbsolute.xml | 12 ++ camsutil/templates/Hikvision_GoContinuous.xml | 12 ++ .../templates/Hikvision_GoHomeposition.xml | 5 + camsutil/templates/Hikvision_GoMomentary.xml | 13 ++ camsutil/templates/Hikvision_PtzDown.html | 4 + camsutil/templates/Hikvision_PtzLeft.html | 4 + camsutil/templates/Hikvision_PtzPreset.html | 4 + camsutil/templates/Hikvision_PtzRight.html | 4 + camsutil/templates/Hikvision_PtzStop.html | 3 + camsutil/templates/Hikvision_PtzUp.html | 4 + camsutil/templates/Hikvision_PtzZoomIn.html | 4 + camsutil/templates/Hikvision_PtzZoomOut.html | 4 + .../templates/Hikvision_SetHomeposition.xml | 5 + .../templates/Hikvision_SetTextOverlay.xml | 13 ++ 20 files changed, 247 insertions(+) create mode 100644 camsutil/__init__.py create mode 100644 camsutil/ptz.py create mode 100644 camsutil/templates/Hikvision_GetCapabilities.html create mode 100644 camsutil/templates/Hikvision_GetJPEG.html create mode 100644 camsutil/templates/Hikvision_GetPosition.html create mode 100644 camsutil/templates/Hikvision_GetReboot.html create mode 100644 camsutil/templates/Hikvision_GoAbsolute.xml create mode 100644 camsutil/templates/Hikvision_GoContinuous.xml create mode 100644 camsutil/templates/Hikvision_GoHomeposition.xml create mode 100644 camsutil/templates/Hikvision_GoMomentary.xml create mode 100644 camsutil/templates/Hikvision_PtzDown.html create mode 100644 camsutil/templates/Hikvision_PtzLeft.html create mode 100644 camsutil/templates/Hikvision_PtzPreset.html create mode 100644 camsutil/templates/Hikvision_PtzRight.html create mode 100644 camsutil/templates/Hikvision_PtzStop.html create mode 100644 camsutil/templates/Hikvision_PtzUp.html create mode 100644 camsutil/templates/Hikvision_PtzZoomIn.html create mode 100644 camsutil/templates/Hikvision_PtzZoomOut.html create mode 100644 camsutil/templates/Hikvision_SetHomeposition.xml create mode 100644 camsutil/templates/Hikvision_SetTextOverlay.xml diff --git a/camsutil/__init__.py b/camsutil/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/camsutil/ptz.py b/camsutil/ptz.py new file mode 100644 index 0000000..b791769 --- /dev/null +++ b/camsutil/ptz.py @@ -0,0 +1,144 @@ +#!/usr/bin/env python3 + + +import urllib.request +from os import path, sep + + +class API: + """ + Creation of a request to the camera API based on the prepared template. + """ + def __init__(self, host: str, user: str, password: str, template: str, + protocol: str = 'http', port: int = 80, channel: int = 101, vid: int = 1, + x: int = 0, y: int = 0, z: int = 0, speed: int = 1, time: int = 100000, + text: str = '', enabled: str = 'true'): + """ + Object constructor + :param host: hostname or ip address + :param user: valid user + :param password: valid password + :param template: the name of an existing template + :param protocol: http, https, etc. + :param port: port number + :param channel: ptz channel number + :param vid: video channel id + :param x: horizontal positioning: azimuth, pan + :param y: vertical positioning: elevation, tilt + :param z: zoom direction, absolute zoom + :param speed: positioning speed: from 1 to 7 + :param time: momentary duration, max 100000ms + :param text: overlay text content + :param enabled: enabled (true) or disabled (false) overlay text + """ + self._host = host + self._user = user + self._pswd = password + self._temp = path.dirname(path.abspath(__file__)) + sep + 'templates' + sep + template + self._protocol = protocol + self._port = port + self._channel = channel + self._id = vid + self._x = x + self._y = y + self._z = z + self._speed = speed + self._time = time + self._message = text + self._enabledMessage = enabled + self._data = '' + self._type = '' + self._url = self._protocol + '://' + self._host + ':' + str(self._port) + self._method = '' + + with open(self._temp) as file: + content = file.read() \ + .replace('@CHANNEL@', str(self._channel)) \ + .replace('@ID@', str(self._id)) \ + .replace('@XXXX@', str(self._x)) \ + .replace('@YYYY@', str(self._y)) \ + .replace('@ZZZZ@', str(self._z)) \ + .replace('@TTTT@', str(self._time)) \ + .replace('@SSSS@', str(self._speed)) \ + .replace('@MSG@', str(self._message)) \ + .replace('@ENABLED@', str(self._enabledMessage)) + for line in content.splitlines(): + if not (' + + diff --git a/camsutil/templates/Hikvision_GetJPEG.html b/camsutil/templates/Hikvision_GetJPEG.html new file mode 100644 index 0000000..bcacc98 --- /dev/null +++ b/camsutil/templates/Hikvision_GetJPEG.html @@ -0,0 +1,3 @@ + + + diff --git a/camsutil/templates/Hikvision_GetPosition.html b/camsutil/templates/Hikvision_GetPosition.html new file mode 100644 index 0000000..df9b2ec --- /dev/null +++ b/camsutil/templates/Hikvision_GetPosition.html @@ -0,0 +1,3 @@ + + + diff --git a/camsutil/templates/Hikvision_GetReboot.html b/camsutil/templates/Hikvision_GetReboot.html new file mode 100644 index 0000000..8d5b0cf --- /dev/null +++ b/camsutil/templates/Hikvision_GetReboot.html @@ -0,0 +1,3 @@ + + + diff --git a/camsutil/templates/Hikvision_GoAbsolute.xml b/camsutil/templates/Hikvision_GoAbsolute.xml new file mode 100644 index 0000000..b7318cf --- /dev/null +++ b/camsutil/templates/Hikvision_GoAbsolute.xml @@ -0,0 +1,12 @@ + + + + @YYYY@ + @XXXX@ + @ZZZZ@ + + + + + + diff --git a/camsutil/templates/Hikvision_GoContinuous.xml b/camsutil/templates/Hikvision_GoContinuous.xml new file mode 100644 index 0000000..7c283ef --- /dev/null +++ b/camsutil/templates/Hikvision_GoContinuous.xml @@ -0,0 +1,12 @@ + + + @XXXX@ + @YYYY@ + @ZZZZ@ + + + + + + + diff --git a/camsutil/templates/Hikvision_GoHomeposition.xml b/camsutil/templates/Hikvision_GoHomeposition.xml new file mode 100644 index 0000000..314b1d2 --- /dev/null +++ b/camsutil/templates/Hikvision_GoHomeposition.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/camsutil/templates/Hikvision_GoMomentary.xml b/camsutil/templates/Hikvision_GoMomentary.xml new file mode 100644 index 0000000..c2e4fc9 --- /dev/null +++ b/camsutil/templates/Hikvision_GoMomentary.xml @@ -0,0 +1,13 @@ + + + @XXXX@ + @YYYY@ + @ZZZZ@ + + @TTTT@ + + + + + + diff --git a/camsutil/templates/Hikvision_PtzDown.html b/camsutil/templates/Hikvision_PtzDown.html new file mode 100644 index 0000000..e95385d --- /dev/null +++ b/camsutil/templates/Hikvision_PtzDown.html @@ -0,0 +1,4 @@ + + + + diff --git a/camsutil/templates/Hikvision_PtzLeft.html b/camsutil/templates/Hikvision_PtzLeft.html new file mode 100644 index 0000000..7303db5 --- /dev/null +++ b/camsutil/templates/Hikvision_PtzLeft.html @@ -0,0 +1,4 @@ + + + + diff --git a/camsutil/templates/Hikvision_PtzPreset.html b/camsutil/templates/Hikvision_PtzPreset.html new file mode 100644 index 0000000..3b9a78c --- /dev/null +++ b/camsutil/templates/Hikvision_PtzPreset.html @@ -0,0 +1,4 @@ + + + + diff --git a/camsutil/templates/Hikvision_PtzRight.html b/camsutil/templates/Hikvision_PtzRight.html new file mode 100644 index 0000000..73fcfbc --- /dev/null +++ b/camsutil/templates/Hikvision_PtzRight.html @@ -0,0 +1,4 @@ + + + + diff --git a/camsutil/templates/Hikvision_PtzStop.html b/camsutil/templates/Hikvision_PtzStop.html new file mode 100644 index 0000000..a40b049 --- /dev/null +++ b/camsutil/templates/Hikvision_PtzStop.html @@ -0,0 +1,3 @@ + + + diff --git a/camsutil/templates/Hikvision_PtzUp.html b/camsutil/templates/Hikvision_PtzUp.html new file mode 100644 index 0000000..9673bcb --- /dev/null +++ b/camsutil/templates/Hikvision_PtzUp.html @@ -0,0 +1,4 @@ + + + + diff --git a/camsutil/templates/Hikvision_PtzZoomIn.html b/camsutil/templates/Hikvision_PtzZoomIn.html new file mode 100644 index 0000000..9e7996b --- /dev/null +++ b/camsutil/templates/Hikvision_PtzZoomIn.html @@ -0,0 +1,4 @@ + + + + diff --git a/camsutil/templates/Hikvision_PtzZoomOut.html b/camsutil/templates/Hikvision_PtzZoomOut.html new file mode 100644 index 0000000..308ac0f --- /dev/null +++ b/camsutil/templates/Hikvision_PtzZoomOut.html @@ -0,0 +1,4 @@ + + + + diff --git a/camsutil/templates/Hikvision_SetHomeposition.xml b/camsutil/templates/Hikvision_SetHomeposition.xml new file mode 100644 index 0000000..69b0b9b --- /dev/null +++ b/camsutil/templates/Hikvision_SetHomeposition.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/camsutil/templates/Hikvision_SetTextOverlay.xml b/camsutil/templates/Hikvision_SetTextOverlay.xml new file mode 100644 index 0000000..968941e --- /dev/null +++ b/camsutil/templates/Hikvision_SetTextOverlay.xml @@ -0,0 +1,13 @@ + + + + @ID@ + @ENABLED@ + @XXXX@ + @YYYY@ + @MSG@ + + + + +