From 55c9f3949e5360d31fb30584d61b733e73caf1c0 Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Thu, 29 Feb 2024 09:32:37 -0700 Subject: [PATCH] Update formatting --- frigate/events/audio.py | 6 ++--- frigate/ffmpeg_presets.py | 18 ++++++------- frigate/http.py | 30 ++++++++++----------- frigate/ptz/autotrack.py | 18 ++++++------- frigate/ptz/onvif.py | 24 ++++++++--------- frigate/test/test_ffmpeg_presets.py | 42 ++++++++++++++--------------- 6 files changed, 69 insertions(+), 69 deletions(-) diff --git a/frigate/events/audio.py b/frigate/events/audio.py index c1b38cfb4..fc8f38dad 100644 --- a/frigate/events/audio.py +++ b/frigate/events/audio.py @@ -247,9 +247,9 @@ class AudioEventMaintainer(threading.Thread): def handle_detection(self, label: str, score: float) -> None: if self.detections.get(label): - self.detections[label][ - "last_detection" - ] = datetime.datetime.now().timestamp() + self.detections[label]["last_detection"] = ( + datetime.datetime.now().timestamp() + ) else: self.requestor.send_data(f"{self.config.name}/audio/{label}", "ON") diff --git a/frigate/ffmpeg_presets.py b/frigate/ffmpeg_presets.py index e86602840..d07ae369f 100644 --- a/frigate/ffmpeg_presets.py +++ b/frigate/ffmpeg_presets.py @@ -115,12 +115,12 @@ PRESETS_HW_ACCEL_ENCODE_BIRDSEYE = { "preset-rk-h265": "ffmpeg -hide_banner {0} -c:v hevc_rkmpp -profile:v high {1}", "default": "ffmpeg -hide_banner {0} -c:v libx264 -g 50 -profile:v high -level:v 4.1 -preset:v superfast -tune:v zerolatency {1}", } -PRESETS_HW_ACCEL_ENCODE_BIRDSEYE[ - "preset-nvidia-h264" -] = PRESETS_HW_ACCEL_ENCODE_BIRDSEYE[FFMPEG_HWACCEL_NVIDIA] -PRESETS_HW_ACCEL_ENCODE_BIRDSEYE[ - "preset-nvidia-h265" -] = PRESETS_HW_ACCEL_ENCODE_BIRDSEYE[FFMPEG_HWACCEL_NVIDIA] +PRESETS_HW_ACCEL_ENCODE_BIRDSEYE["preset-nvidia-h264"] = ( + PRESETS_HW_ACCEL_ENCODE_BIRDSEYE[FFMPEG_HWACCEL_NVIDIA] +) +PRESETS_HW_ACCEL_ENCODE_BIRDSEYE["preset-nvidia-h265"] = ( + PRESETS_HW_ACCEL_ENCODE_BIRDSEYE[FFMPEG_HWACCEL_NVIDIA] +) PRESETS_HW_ACCEL_ENCODE_TIMELAPSE = { "preset-rpi-64-h264": "ffmpeg -hide_banner {0} -c:v h264_v4l2m2m -pix_fmt yuv420p {1}", @@ -136,9 +136,9 @@ PRESETS_HW_ACCEL_ENCODE_TIMELAPSE = { "preset-rk-h265": "ffmpeg -hide_banner {0} -c:v hevc_rkmpp -profile:v high {1}", "default": "ffmpeg -hide_banner {0} -c:v libx264 -preset:v ultrafast -tune:v zerolatency {1}", } -PRESETS_HW_ACCEL_ENCODE_TIMELAPSE[ - "preset-nvidia-h264" -] = PRESETS_HW_ACCEL_ENCODE_TIMELAPSE[FFMPEG_HWACCEL_NVIDIA] +PRESETS_HW_ACCEL_ENCODE_TIMELAPSE["preset-nvidia-h264"] = ( + PRESETS_HW_ACCEL_ENCODE_TIMELAPSE[FFMPEG_HWACCEL_NVIDIA] +) # encoding of previews is only done on CPU due to comparable encode times and better quality from libx264 PRESETS_HW_ACCEL_ENCODE_PREVIEW = { diff --git a/frigate/http.py b/frigate/http.py index d47749edf..807a14659 100644 --- a/frigate/http.py +++ b/frigate/http.py @@ -917,9 +917,9 @@ def event_snapshot(id): else: response.headers["Cache-Control"] = "no-store" if download: - response.headers[ - "Content-Disposition" - ] = f"attachment; filename=snapshot-{id}.jpg" + response.headers["Content-Disposition"] = ( + f"attachment; filename=snapshot-{id}.jpg" + ) return response @@ -1106,9 +1106,9 @@ def event_clip(id): if download: response.headers["Content-Disposition"] = "attachment; filename=%s" % file_name response.headers["Content-Length"] = os.path.getsize(clip_path) - response.headers[ - "X-Accel-Redirect" - ] = f"/clips/{file_name}" # nginx: https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_ignore_headers + response.headers["X-Accel-Redirect"] = ( + f"/clips/{file_name}" # nginx: https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_ignore_headers + ) return response @@ -1404,9 +1404,9 @@ def config(): config["plus"] = {"enabled": current_app.plus_api.is_active()} for detector, detector_config in config["detectors"].items(): - detector_config["model"][ - "labelmap" - ] = current_app.frigate_config.model.merged_labelmap + detector_config["model"]["labelmap"] = ( + current_app.frigate_config.model.merged_labelmap + ) return jsonify(config) @@ -1811,9 +1811,9 @@ def get_recordings_storage_usage(): total_mb = recording_stats["total"] - camera_usages: dict[ - str, dict - ] = current_app.storage_maintainer.calculate_camera_usages() + camera_usages: dict[str, dict] = ( + current_app.storage_maintainer.calculate_camera_usages() + ) for camera_name in camera_usages.keys(): if camera_usages.get(camera_name, {}).get("usage"): @@ -2001,9 +2001,9 @@ def recording_clip(camera_name, start_ts, end_ts): if download: response.headers["Content-Disposition"] = "attachment; filename=%s" % file_name response.headers["Content-Length"] = os.path.getsize(path) - response.headers[ - "X-Accel-Redirect" - ] = f"/cache/{file_name}" # nginx: https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_ignore_headers + response.headers["X-Accel-Redirect"] = ( + f"/cache/{file_name}" # nginx: https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_ignore_headers + ) return response diff --git a/frigate/ptz/autotrack.py b/frigate/ptz/autotrack.py index 8266e4b87..44082a52e 100644 --- a/frigate/ptz/autotrack.py +++ b/frigate/ptz/autotrack.py @@ -297,12 +297,12 @@ class PtzAutoTracker: self.ptz_metrics[camera][ "ptz_max_zoom" ].value = camera_config.onvif.autotracking.movement_weights[1] - self.intercept[ - camera - ] = camera_config.onvif.autotracking.movement_weights[2] - self.move_coefficients[ - camera - ] = camera_config.onvif.autotracking.movement_weights[3:] + self.intercept[camera] = ( + camera_config.onvif.autotracking.movement_weights[2] + ) + self.move_coefficients[camera] = ( + camera_config.onvif.autotracking.movement_weights[3:] + ) else: camera_config.onvif.autotracking.enabled = False self.ptz_metrics[camera]["ptz_autotracker_enabled"].value = False @@ -603,9 +603,9 @@ class PtzAutoTracker: ) ** self.zoom_factor[camera] if "original_target_box" not in self.tracked_object_metrics[camera]: - self.tracked_object_metrics[camera][ - "original_target_box" - ] = self.tracked_object_metrics[camera]["target_box"] + self.tracked_object_metrics[camera]["original_target_box"] = ( + self.tracked_object_metrics[camera]["target_box"] + ) ( self.tracked_object_metrics[camera]["valid_velocity"], diff --git a/frigate/ptz/onvif.py b/frigate/ptz/onvif.py index 0e02d4521..a7f7f045e 100644 --- a/frigate/ptz/onvif.py +++ b/frigate/ptz/onvif.py @@ -126,9 +126,9 @@ class OnvifController: logger.debug(f"Onvif config for {camera_name}: {ptz_config}") service_capabilities_request = ptz.create_type("GetServiceCapabilities") - self.cams[camera_name][ - "service_capabilities_request" - ] = service_capabilities_request + self.cams[camera_name]["service_capabilities_request"] = ( + service_capabilities_request + ) fov_space_id = next( ( @@ -244,9 +244,9 @@ class OnvifController: supported_features.append("zoom-r") try: # get camera's zoom limits from onvif config - self.cams[camera_name][ - "relative_zoom_range" - ] = ptz_config.Spaces.RelativeZoomTranslationSpace[0] + self.cams[camera_name]["relative_zoom_range"] = ( + ptz_config.Spaces.RelativeZoomTranslationSpace[0] + ) except Exception: if ( self.config.cameras[camera_name].onvif.autotracking.zooming @@ -263,9 +263,9 @@ class OnvifController: supported_features.append("zoom-a") try: # get camera's zoom limits from onvif config - self.cams[camera_name][ - "absolute_zoom_range" - ] = ptz_config.Spaces.AbsoluteZoomPositionSpace[0] + self.cams[camera_name]["absolute_zoom_range"] = ( + ptz_config.Spaces.AbsoluteZoomPositionSpace[0] + ) self.cams[camera_name]["zoom_limits"] = configs.ZoomLimits except Exception: if self.config.cameras[camera_name].onvif.autotracking.zooming: @@ -282,9 +282,9 @@ class OnvifController: and configs.DefaultRelativePanTiltTranslationSpace is not None ): supported_features.append("pt-r-fov") - self.cams[camera_name][ - "relative_fov_range" - ] = ptz_config.Spaces.RelativePanTiltTranslationSpace[fov_space_id] + self.cams[camera_name]["relative_fov_range"] = ( + ptz_config.Spaces.RelativePanTiltTranslationSpace[fov_space_id] + ) self.cams[camera_name]["features"] = supported_features diff --git a/frigate/test/test_ffmpeg_presets.py b/frigate/test/test_ffmpeg_presets.py index 469c28f1f..ac5e30a2d 100644 --- a/frigate/test/test_ffmpeg_presets.py +++ b/frigate/test/test_ffmpeg_presets.py @@ -41,9 +41,9 @@ class TestFfmpegPresets(unittest.TestCase): assert self.default_ffmpeg == frigate_config.dict(exclude_unset=True) def test_ffmpeg_hwaccel_preset(self): - self.default_ffmpeg["cameras"]["back"]["ffmpeg"][ - "hwaccel_args" - ] = "preset-rpi-64-h264" + self.default_ffmpeg["cameras"]["back"]["ffmpeg"]["hwaccel_args"] = ( + "preset-rpi-64-h264" + ) frigate_config = FrigateConfig(**self.default_ffmpeg) frigate_config.cameras["back"].create_ffmpeg_cmds() assert "preset-rpi-64-h264" not in ( @@ -54,9 +54,9 @@ class TestFfmpegPresets(unittest.TestCase): ) def test_ffmpeg_hwaccel_not_preset(self): - self.default_ffmpeg["cameras"]["back"]["ffmpeg"][ - "hwaccel_args" - ] = "-other-hwaccel args" + self.default_ffmpeg["cameras"]["back"]["ffmpeg"]["hwaccel_args"] = ( + "-other-hwaccel args" + ) frigate_config = FrigateConfig(**self.default_ffmpeg) frigate_config.cameras["back"].create_ffmpeg_cmds() assert "-other-hwaccel args" in ( @@ -64,9 +64,9 @@ class TestFfmpegPresets(unittest.TestCase): ) def test_ffmpeg_hwaccel_scale_preset(self): - self.default_ffmpeg["cameras"]["back"]["ffmpeg"][ - "hwaccel_args" - ] = "preset-nvidia-h264" + self.default_ffmpeg["cameras"]["back"]["ffmpeg"]["hwaccel_args"] = ( + "preset-nvidia-h264" + ) self.default_ffmpeg["cameras"]["back"]["detect"] = { "height": 1920, "width": 2560, @@ -85,9 +85,9 @@ class TestFfmpegPresets(unittest.TestCase): def test_default_ffmpeg_input_arg_preset(self): frigate_config = FrigateConfig(**self.default_ffmpeg) - self.default_ffmpeg["cameras"]["back"]["ffmpeg"][ - "input_args" - ] = "preset-rtsp-generic" + self.default_ffmpeg["cameras"]["back"]["ffmpeg"]["input_args"] = ( + "preset-rtsp-generic" + ) frigate_preset_config = FrigateConfig(**self.default_ffmpeg) frigate_config.cameras["back"].create_ffmpeg_cmds() frigate_preset_config.cameras["back"].create_ffmpeg_cmds() @@ -98,9 +98,9 @@ class TestFfmpegPresets(unittest.TestCase): ) def test_ffmpeg_input_preset(self): - self.default_ffmpeg["cameras"]["back"]["ffmpeg"][ - "input_args" - ] = "preset-rtmp-generic" + self.default_ffmpeg["cameras"]["back"]["ffmpeg"]["input_args"] = ( + "preset-rtmp-generic" + ) frigate_config = FrigateConfig(**self.default_ffmpeg) frigate_config.cameras["back"].create_ffmpeg_cmds() assert "preset-rtmp-generic" not in ( @@ -131,9 +131,9 @@ class TestFfmpegPresets(unittest.TestCase): ) def test_ffmpeg_output_record_preset(self): - self.default_ffmpeg["cameras"]["back"]["ffmpeg"]["output_args"][ - "record" - ] = "preset-record-generic-audio-aac" + self.default_ffmpeg["cameras"]["back"]["ffmpeg"]["output_args"]["record"] = ( + "preset-record-generic-audio-aac" + ) frigate_config = FrigateConfig(**self.default_ffmpeg) frigate_config.cameras["back"].create_ffmpeg_cmds() assert "preset-record-generic-audio-aac" not in ( @@ -144,9 +144,9 @@ class TestFfmpegPresets(unittest.TestCase): ) def test_ffmpeg_output_record_not_preset(self): - self.default_ffmpeg["cameras"]["back"]["ffmpeg"]["output_args"][ - "record" - ] = "-some output" + self.default_ffmpeg["cameras"]["back"]["ffmpeg"]["output_args"]["record"] = ( + "-some output" + ) frigate_config = FrigateConfig(**self.default_ffmpeg) frigate_config.cameras["back"].create_ffmpeg_cmds() assert "-some output" in (