feature: added max_size (MB) to 'media' config section

pull/106/head
Jeff Culverhouse 3 months ago
parent 8e12793ae0
commit 1d8c622603

@ -5,7 +5,6 @@ mqtt:
password: password password: password
qos: 0 qos: 0
prefix: amcrest2mqtt prefix: amcrest2mqtt
homeassistant: True
discovery_prefix: homeassistant discovery_prefix: homeassistant
tls_enabled: False tls_enabled: False
tls_ca_cert: filename tls_ca_cert: filename
@ -33,4 +32,5 @@ amcrest:
media: media:
path: /media path: /media
max_size: 25 # per recording, in MB; default is 25
media_source: media-source://media_source/local/videos media_source: media-source://media_source/local/videos

@ -147,6 +147,7 @@ class AmcrestMixin:
"avty_t": self.mqtt_helper.avty_t(device_id), "avty_t": self.mqtt_helper.avty_t(device_id),
"clip_url": f"media-source://media_source/local/Videos/amcrest/{device["device_name"]}-latest.mp4", "clip_url": f"media-source://media_source/local/Videos/amcrest/{device["device_name"]}-latest.mp4",
"icon": "mdi:web", "icon": "mdi:web",
"enabled_by_default": False,
"via_device": self.mqtt_helper.service_slug, "via_device": self.mqtt_helper.service_slug,
"device": device_block, "device": device_block,
} }

@ -168,7 +168,8 @@ class HelpersMixin:
if os.path.exists(media_path) and os.access(media_path, os.W_OK): if os.path.exists(media_path) and os.access(media_path, os.W_OK):
media["path"] = media_path media["path"] = media_path
self.logger.info(f"storing recordings in {media_path}, watch that it doesn't fill up the file system") media.setdefault("max_size", 25)
self.logger.info(f"storing recordings in {media_path} up to {media["max_size"]} MB per file. Watch that it doesn't fill up the file system")
else: else:
self.logger.info("media_path not configured, not found, or is not writable. Will not be saving recordings") self.logger.info("media_path not configured, not found, or is not writable. Will not be saving recordings")
@ -240,6 +241,11 @@ class HelpersMixin:
file_name = f"{name}-{time}.mp4" file_name = f"{name}-{time}.mp4"
file_path = Path(f"{path}/{file_name}") file_path = Path(f"{path}/{file_name}")
# last chance to skip the recording
if self.b_to_mb(len(recording)) > self.config["media"]["max_size"]:
self.logger.info(f"Skipping saving recording to {path} because {self.b_to_mb(len(recording))} > {self.config["media"]["max_size"]} MB")
return None
try: try:
file_path.write_bytes(recording.encode("latin-1")) file_path.write_bytes(recording.encode("latin-1"))
except IOError as err: except IOError as err:

Loading…
Cancel
Save