Automated recordings

Sample automation of recording start/stop.
#import necessary libraries
import urllib3,requests,json
import time

# quick and dirty method for looking up cameras from name
def getCamByName(jsonobj, name):
    for dict in jsonobj:
        if name in dict['Hostname']:
            return dict

# get the cam id # from name
def getCamIdByName(jsonobj, name):
    return getCamByName(jsonobj, name)['Id']

# (optional) Disable the "insecure requests" warning for https certs

# what watchtower url to control
watchtowerurl = 'https://localhost:4343'
cameraname = 'e3v8100'

# login and obtain API token
username = 'whitematter'
password = 'test'
r ='/api/login', data = {'username': username, 'password': password}, verify=False)
j = json.loads(r.text)
apit = j['apitoken']

# Start saving'/api/cameras/action', data = {'IdGroup[]': [camid], 'Action': 'RECORDGROUP', 'apitoken': apit}, verify=False)
print("Started saving, 30 seconds")


# Stop saving'/api/cameras/action', data = {'IdGroup[]': [camid], 'Action': 'STOPRECORDGROUP', 'apitoken': apit}, verify=False)
print("Stopped saving")

time.sleep(2) # let file writing on-disk clean-up
# normally this wait would not be necessary unless you're IMMEDIATELY disconnecting afterwards.

# Disconnect from camera'/api/cameras/action', data = {'Id': camid, 'Action': 'DISCONNECT', 'Iface': interface, 'apitoken': apit}, verify=False)
Last modified March 20, 2020