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.
81 lines
2.9 KiB
81 lines
2.9 KiB
import os, sys
|
|
from json import loads
|
|
from dvrip import DVRIPCam
|
|
from nvr_core import NVR
|
|
from nvr_types import File
|
|
|
|
def app_dir():
|
|
return os.path.dirname(os.path.abspath(__file__))
|
|
|
|
def load_config(config_name):
|
|
try:
|
|
path = os.path.join(app_dir(), config_name)
|
|
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, name = ""):
|
|
self.address = address
|
|
self.port = int(port)
|
|
self.username = username
|
|
self.password = password
|
|
self.name = name
|
|
|
|
@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:
|
|
if not self.name:
|
|
return f"{self.address}:{self.port}"
|
|
else:
|
|
return self.name
|
|
|
|
class Config:
|
|
def __init__(self, config_name = "config.json") -> None:
|
|
raw = load_config(config_name)
|
|
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"), raw_server.get("name", "")))
|
|
if (self.recorders.__len__() == 0):
|
|
print("Recorders not find")
|
|
else:
|
|
for recorder in self.recorders:
|
|
print(recorder)
|
|
|
|
def getRecorder(self, index = 0) -> Recorder:
|
|
return self.recorders[index]
|
|
|
|
def getRecorders(self):
|
|
return [str(r) for r in self.recorders]
|
|
|
|
if __name__ == "__main__":
|
|
print(app_dir())
|
|
config = Config()
|
|
recorder: Recorder = config.getRecorder()
|
|
nvr: NVR = recorder.nvr
|
|
nvr.login()
|
|
f: File = File.from_b64("eyJiZWdpbiI6ICIyMDI0LTA4LTA2IDAyOjI3OjQxIiwgImVuZCI6ICIyMDI0LTA4LTA2IDAyOjI5OjQxIiwgIkRpc2tObyI6IDAsICJTZXJpYWxObyI6IDAsICJzaXplIjogMTI2NTMzNjMyLCAiZmlsZW5hbWUiOiAiL2lkZWEwLzIwMjQtMDgtMDYvMDAxLzAyLjI3LjQxLTAyLjI5LjQxW01dW0A3NjRlXVswXS5oMjY0IiwgImZpbGVuYW1lX2NsZWFyZWQiOiAiMDIuMjcuNDEtMDIuMjkuNDFfTV9fXzc2NGVfXzBfLmgyNjQiLCAiY2hhbm5lbCI6IDAsICJzdHJlYW0iOiAwfQ==")
|
|
nvr.save_file(f)
|
|
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()
|