Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add audio/video enable properties #113

Merged
merged 1 commit into from
Mar 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
define([VERSION_MAJOR], [1])
define([VERSION_MINOR], [2])
define([VERSION_FIX], [7])
define([VERSION_MINOR], [3])
define([VERSION_FIX], [0])
define([VERSION_NUMBER], VERSION_MAJOR[.]VERSION_MINOR[.]VERSION_FIX)
define([VERSION_SUFFIX], [_master])

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def readme():


setup(name='amcrest',
version='1.2.7',
version='1.3.0',
description='Python wrapper implementation for Amcrest cameras.',
long_description=readme(),
author='Douglas Schilling Landgraf, Marcelo Moreira de Mello',
Expand Down
12 changes: 12 additions & 0 deletions src/amcrest/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# vim:sw=4:ts=4:et
import shutil

from . import utils


class Audio(object):

Expand Down Expand Up @@ -113,3 +115,13 @@ def audio_stream_capture(self, httptype=None,
shutil.copyfileobj(ret.raw, out_file)

return ret.raw

@property
def audio_enabled(self):
"""Return if any audio stream enabled."""
return utils.extract_audio_video_enabled('Audio', self.encode_media)

@audio_enabled.setter
def audio_enabled(self, enable):
"""Enable/disable all audio streams."""
self.command(utils.enable_audio_video_cmd('Audio', enable))
19 changes: 19 additions & 0 deletions src/amcrest/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,22 @@ def to_unit(value, unit='B'):
return (float('{:.{prec}f}'.format(result, prec=PRECISION)), unit)

return value


def extract_audio_video_enabled(param, resp):
"""Extract if any audio/video stream enabled from response."""
return 'true' in [part.split('=')[1] for part in resp.split()
if '.{}Enable='.format(param) in part]


def enable_audio_video_cmd(param, enable):
"""Return command to enable/disable all audio/video streams."""
cmd = 'configManager.cgi?action=setConfig'
formats = [('Extra', 3), ('Main', 4)]
if param == 'Video':
formats.append(('Snap', 3))
for fmt, num in formats:
for i in range(num):
cmd += '&Encode[0].{}Format[{}].{}Enable={}'.format(
fmt, i, param, str(enable).lower())
return cmd
19 changes: 19 additions & 0 deletions src/amcrest/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# GNU General Public License for more details.
#
# vim:sw=4:ts=4:et
from . import utils


class Video(object):
Expand Down Expand Up @@ -134,3 +135,21 @@ def video_out_options(self):
'configManager.cgi?action=getConfig&name=VideoOut'
)
return ret.content.decode('utf-8')

@property
def video_enabled(self):
"""Return if any video stream enabled."""
return utils.extract_audio_video_enabled('Video', self.encode_media)

@video_enabled.setter
def video_enabled(self, enable):
"""Enable/disable all video streams."""
self.command(utils.enable_audio_video_cmd('Video', enable))
# It's not clear why from the HTTP API SDK doc, but setting InfraRed
# to false sets the Night Vision Mode to SmartIR, whereas setting it
# to true sets the Night Vision Mode to OFF. Night Vision Mode has a
# third setting of Manual, but that must be selected some other way
# via the HTTP API.
self.command(
'configManager.cgi?action=setConfig'
'&VideoInOptions[0].InfraRed={}'.format(str(not enable).lower()))