Start using warnings from stdlib.
[python_utils.git] / camera_utils.py
index acf760d55ca8b61d69871260ac55e18844f46acb..e69eddb7b3cec5faf915dd6bc23243b261d26858 100644 (file)
@@ -6,6 +6,7 @@ import logging
 import platform
 import subprocess
 from typing import NamedTuple, Optional
+import warnings
 
 import cv2  # type: ignore
 import numpy as np
@@ -81,7 +82,9 @@ def fetch_camera_image_from_video_server(
                 return raw
     except Exception as e:
         logger.exception(e)
-    logger.warning(f"Got a bad image or HTTP error from {url}")
+    msg = f"Got a bad image or HTTP error from {url}; returning None."
+    logger.warning(msg)
+    warnings.warn(msg)
     return None
 
 
@@ -106,6 +109,7 @@ def fetch_camera_image_from_rtsp_stream(
 ) -> Optional[bytes]:
     """Fetch the raw webcam image straight from the webcam's RTSP stream."""
     hostname = blue_iris_camera_name_to_hostname(camera_name)
+    stream = f"rtsp://camera:IaLaIok@{hostname}:554/live"
     try:
         cmd = [
             "/usr/bin/timeout",
@@ -114,7 +118,7 @@ def fetch_camera_image_from_rtsp_stream(
             "/usr/local/bin/ffmpeg",
             "-y",
             "-i",
-            f"rtsp://camera:IaLaIok@{hostname}:554/live",
+            f"{stream}",
             "-f",
             "singlejpeg",
             "-vframes",
@@ -130,7 +134,9 @@ def fetch_camera_image_from_rtsp_stream(
             return out
     except Exception as e:
         logger.exception(e)
-    logger.warning("Failed to retrieve image from RTSP stream")
+    msg = "Failed to retrieve image via RTSP {stream}, returning None."
+    warnings.warn(msg)
+    logger.warning(msg)
     return None
 
 
@@ -157,9 +163,9 @@ def _fetch_camera_image(
             jpg=jpg,
             hsv=hsv,
         )
-    logger.warning(
-        "Failed to retieve image from both video server and direct RTSP stream"
-    )
+    msg = "Failed to retieve image from both video server and direct RTSP stream"
+    logger.warning(msg)
+    warnings.warn(msg)
     return RawJpgHsv(None, None, None)