def FlashXM(cmd): cam = DVRIPCam(GetIP(devices[cmd[1]]["HostIP"]), "admin", cmd[2]) if cam.login(): cmd[4](_("Auth success")) cam.upgrade(cmd[3], 0x4000, cmd[4]) else: cmd[4](_("Auth failed"))
def open_telnet(host_ip, port, **kwargs): make_telnet = kwargs.get('telnet', False) make_backup = kwargs.get('backup', False) user = kwargs.get('username', 'admin') password = kwargs.get('password', '') cam = DVRIPCam(host_ip, user=user, password=password) if not cam.login(): print(f"Cannot connect {host_ip}") return upinfo = cam.get_upgrade_info() hw = upinfo["Hardware"] print(f"Modifiying camera {hw}") sysinfo = cam.get_system_info() swver = extract_gen(sysinfo["SoftWareVersion"]) print(f"Firmware generation {swver}") desc = { "Hardware": hw, "DevID": f"{swver}1001000000000000", "CompatibleVersion": 2, "Vendor": "General", "CRC": "1ce6242100007636", } upcmd = [] if make_telnet: upcmd.append(cmd_telnetd(port)) elif make_backup: upcmd = cmd_backup() else: upcmd.append(cmd_armebenv(swver)) desc['UpgradeCommand'] = upcmd add_flashes(desc, swver) zipfname = "upgrade.bin" make_zip(zipfname, json.dumps(desc, indent=2)) cam.upgrade(zipfname) cam.close() os.remove(zipfname) if make_backup: print("Check backup") return if not make_telnet: port = 23 print("Waiting for camera is rebooting...") for i in range(10): time.sleep(4) if check_port(host_ip, port): tport = f" {port}" if port != 23 else '' print(f"Now use 'telnet {host_ip}{tport}' to login") return print("Something went wrong") return
def jobWrapper(): global cam log('Logging in to camera ' + camIp + '...') cam = DVRIPCam(camIp) if cam.login(): log('done') else: raise SomethingIsWrongWithCamera('Cannot login') syncTime() theActualJob()
class Camera: def __init__(self, address, user, password): self.dvrip = DVRIPCam(address, user, password) loginok = self.dvrip.login() if not loginok: raise ValueError('Login failed') self.onvif = ONVIFCamera(address, 8899, user, password, '../venv/lib/python3.7/site-packages/wsdl/') self.onvif_media = self.onvif.create_media_service() def step(self, direction, sleep=0.1): assert direction in ('DirectionUp', 'DirectionDown', 'DirectionLeft', 'DirectionRight') self.dvrip.ptz(direction, preset=65535) # move time.sleep(sleep) self.dvrip.ptz(direction, preset=-1) # Stop def get_snapshot_uri(self): for profile in ('000', '001', '002'): snapshot_uri = self.onvif.media.GetSnapshotUri('000').Uri logging.info("Snapshot uri is: %s for profile %s", snapshot_uri, profile) return snapshot_uri def acquire(self, filename=None): if filename is None: filename = datetime.datetime.now().isoformat() + '.jpg' logging.info('Saving file to %s', filename) hdr = {'Accept': '*/*'} with open(filename, 'wb') as fout: ''' r = requests.get(self.get_snapshot_uri(), stream=True, headers=hdr) if r.status_code == 200: with open(path, 'wb') as f: r.raw.decode_content = True shutil.copyfileobj(r.raw, fout) ''' response = urlopen(self.get_snapshot_uri()) data = response.read() fout.write(data) def close(self): self.dvrip.close()
#!/usr/bin/env python # -*- coding: UTF-8 -*- import sys from dvrip import DVRIPCam from time import sleep import json host_ip = "192.168.0.100" if len(sys.argv) > 1: host_ip = str(sys.argv[1]) cam = DVRIPCam(host_ip, user="******", password="******") if cam.login(): print("Success! Connected to " + host_ip) else: print("Failure. Could not connect.") info = cam.get_info("fVideo.OSDInfo") print(json.dumps(info, ensure_ascii=False)) info["OSDInfo"][0]["Info"] = [u"Тест00", "Test01", "Test02"] # info["OSDInfo"][0]["Info"][1] = "" # info["OSDInfo"][0]["Info"][2] = "" # info["OSDInfo"][0]["Info"][3] = "Test3" info["OSDInfo"][0]["OSDInfoWidget"]["EncodeBlend"] = True info["OSDInfo"][0]["OSDInfoWidget"]["PreviewBlend"] = True # info["OSDInfo"][0]["OSDInfoWidget"]["RelativePos"] = [6144,6144,8192,8192] cam.set_info("fVideo.OSDInfo", info) # enc_info = cam.get_info("Simplify.Encode") # Alarm example def alarm(content, ids):