You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

72 lines
2.2 KiB

import os, sys
from json import loads
from dvrip import DVRIPCam
from nvr_core import NVR
def app_dir():
return os.path.dirname(os.path.abspath(__file__))
def load_config():
try:
path = os.path.join(app_dir(),"config.json")
print("Looking config file", path)
with open(path, "r", encoding="utf8") as f:
return loads(f.read())
except Exception as e:
print("cannot find or parse config.json", e)
sys.exit(1)
class Recorder:
def __init__(self, address, port, username, password):
self.address = address
self.port = int(port)
self.username = username
self.password = password
@property
def client(self) -> DVRIPCam:
return DVRIPCam(self.address, port = self.port, user = self.username, password = self.password)
@property
def nvr(self) -> NVR:
return NVR(self.client)
def __str__(self) -> str:
return f"{self.address}:{self.port}"
class Config:
def __init__(self) -> None:
raw = load_config()
self.listen_address = raw.get("backend", {}).get("address", "0.0.0.0")
self.listen_port = int(raw.get("backend", {}).get("port", "8080"))
self.recorders = []
for raw_server in raw.get("recorders", []):
self.recorders.append(Recorder(raw_server.get("ip"), raw_server.get("port"), raw_server.get("user"), raw_server.get("password")))
if (self.recorders.__len__() == 0):
print("Recorders not find")
else:
for recorder in self.recorders:
print(recorder)
def getRecorder(self, index = 0):
return self.recorders[index]
if __name__ == "__main__":
print(app_dir())
config = Config()
recorder: Recorder = config.getRecorder()
nvr: NVR = recorder.nvr
nvr.login()
print(nvr.download_test())
nvr.logout()
#client: DVRIPCam = recorder.client
#client.debug()
#if not client.login():
# print("can't login")
# sys.exit(2)
#print(client.get_system_info())
#print(client.get_channel_titles())
#print(client.get_channel_statuses())
#print(client.list_local_files(START, END, "h264", channel=3))
#client.close()