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.
 
 
 
 
 
 

45 lines
1.3 KiB

from datetime import datetime
from dvrip import DVRIPCam
from nvr_types import File as NvrFile
START = "2024-08-04 6:22:34"
END = "2024-08-04 23:23:09"
CHANNEL = 0
def date_today(begin = True):
if begin:
return datetime.now().strftime("%Y-%m-%d 00:00:00")
else:
return datetime.now().strftime("%Y-%m-%d 23:59:59")
class NVR:
def __init__(self, client) -> None:
self.client:DVRIPCam = client
def login(self):
self.client.login()
def logout(self):
self.client.close()
@property
def channels(self):
return self.client.get_channel_titles()
def files(self, channel, start = None, end = None, ftype = "h264"):
if not start:
start = date_today()
if not end:
start = date_today(False)
for raw_file in self.client.list_local_files(startTime=start, endTime=end, filetype=ftype, channel=channel):
yield NvrFile(raw_file)
def download_test(self, filename = "testfile.unknown"):
download_file = list(self.files(0))[0]
downloaded_bytes = 0
with open(filename, "wb") as f:
for byte in download_file.download_stream(self.client):
downloaded_bytes += len(byte)
f.write(byte)
print("\r", downloaded_bytes, "/", download_file.size)