diff options
author | Evgeny Sorokin <me@ch1p.io> | 2024-01-13 00:54:32 +0000 |
---|---|---|
committer | Evgeny Sorokin <me@ch1p.io> | 2024-01-13 00:54:32 +0000 |
commit | 57955b596485ecce1ffd4395e23c078358cc5ddd (patch) | |
tree | e4144cf595f9aaa7625b3d271483ddb38aa3bd45 | |
parent | d3a295872c49defb55fc8e4e43e55550991e0927 (diff) |
save something
-rwxr-xr-x | bin/ipcam_capture.py | 3 | ||||
-rw-r--r-- | include/py/homekit/camera/config.py | 42 | ||||
-rw-r--r-- | include/py/homekit/camera/types.py | 32 | ||||
-rw-r--r-- | requirements.txt | 2 | ||||
-rw-r--r-- | tasks/df_h.sh | 2 |
5 files changed, 49 insertions, 32 deletions
diff --git a/bin/ipcam_capture.py b/bin/ipcam_capture.py index 5de14af..226e12e 100755 --- a/bin/ipcam_capture.py +++ b/bin/ipcam_capture.py @@ -48,7 +48,8 @@ async def run_ffmpeg(cam: int, channel: int): else: debug_args = ['-nostats', '-loglevel', 'error'] - protocol = 'tcp' if ipcam_config.should_use_tcp_for_rtsp(cam) else 'udp' + # protocol = 'tcp' if ipcam_config.should_use_tcp_for_rtsp(cam) else 'udp' + protocol = 'tcp' user, pw = ipcam_config.get_rtsp_creds() ip = ipcam_config.get_camera_ip(cam) path = ipcam_config.get_camera_type(cam).get_channel_url(channel) diff --git a/include/py/homekit/camera/config.py b/include/py/homekit/camera/config.py index c7dbc38..8e9bfd5 100644 --- a/include/py/homekit/camera/config.py +++ b/include/py/homekit/camera/config.py @@ -23,17 +23,13 @@ class IpcamConfig(ConfigUnit): @classmethod def schema(cls) -> Optional[dict]: return { - 'cams': { + 'cameras': { 'type': 'dict', 'keysrules': {'type': ['string', 'integer']}, 'valuesrules': { 'type': 'dict', 'schema': { 'type': {'type': 'string', 'allowed': [t.value for t in CameraType], 'required': True}, - 'codec': {'type': 'string', 'allowed': [t.value for t in VideoCodecType], 'required': True}, - 'container': {'type': 'string', 'allowed': [t.value for t in VideoContainerType], 'required': True}, - 'server': {'type': 'string', 'allowed': list(_lbc.get().keys()), 'required': True}, - 'disk': {'type': 'integer', 'required': True}, 'motion': { 'type': 'dict', 'schema': { @@ -44,10 +40,18 @@ class IpcamConfig(ConfigUnit): } } }, - 'rtsp_tcp': {'type': 'boolean'} } } }, + 'areas': { + 'type': 'dict', + 'keysrules': {'type': 'string'}, + 'valuesrules': { + 'type': 'list', + 'schema': {'type': ['string', 'integer']} # same type as for 'cameras' keysrules + } + }, + 'camera_ip_template': {'type': 'string', 'required': True}, 'motion_padding': {'type': 'integer', 'required': True}, 'motion_telegram': {'type': 'boolean', 'required': True}, 'fix_interval': {'type': 'integer', 'required': True}, @@ -94,6 +98,7 @@ class IpcamConfig(ConfigUnit): } } + # FIXME def get_all_cam_names(self, filter_by_server: Optional[str] = None, filter_by_disk: Optional[int] = None) -> list[int]: @@ -106,25 +111,22 @@ class IpcamConfig(ConfigUnit): cams.append(int(cam)) return cams - def get_all_cam_names_for_this_server(self, - filter_by_disk: Optional[int] = None): - return self.get_all_cam_names(filter_by_server=socket.gethostname(), - filter_by_disk=filter_by_disk) + # def get_all_cam_names_for_this_server(self, + # filter_by_disk: Optional[int] = None): + # return self.get_all_cam_names(filter_by_server=socket.gethostname(), + # filter_by_disk=filter_by_disk) - def get_cam_server_and_disk(self, cam: int) -> tuple[str, int]: - return self['cams'][cam]['server'], self['cams'][cam]['disk'] + # def get_cam_server_and_disk(self, cam: int) -> tuple[str, int]: + # return self['cams'][cam]['server'], self['cams'][cam]['disk'] - def get_camera_container(self, cam: int) -> VideoContainerType: - return VideoContainerType(self['cams'][cam]['container']) + def get_camera_container(self, camera: int) -> VideoContainerType: + return self.get_camera_type(camera).get_container() - def get_camera_type(self, cam: int) -> CameraType: - return CameraType(self['cams'][cam]['type']) + def get_camera_type(self, camera: int) -> CameraType: + return CameraType(self['cams'][camera]['type']) def get_rtsp_creds(self) -> tuple[str, str]: return self['rtsp_creds']['login'], self['rtsp_creds']['password'] - def should_use_tcp_for_rtsp(self, cam: int) -> bool: - return 'rtsp_tcp' in self['cams'][cam] and self['cams'][cam]['rtsp_tcp'] - def get_camera_ip(self, camera: int) -> str: - return f'192.168.5.{camera}' + return self['camera_ip_template'] % (str(camera),) diff --git a/include/py/homekit/camera/types.py b/include/py/homekit/camera/types.py index c313b58..da0fcc6 100644 --- a/include/py/homekit/camera/types.py +++ b/include/py/homekit/camera/types.py @@ -1,10 +1,21 @@ from enum import Enum +class VideoContainerType(Enum): + MP4 = 'mp4' + MOV = 'mov' + + +class VideoCodecType(Enum): + H264 = 'h264' + H265 = 'h265' + + class CameraType(Enum): ESP32 = 'esp32' ALIEXPRESS_NONAME = 'ali' - HIKVISION = 'hik' + HIKVISION_264 = 'hik_264' + HIKVISION_265 = 'hik_265' def get_channel_url(self, channel: int) -> str: if channel not in (1, 2): @@ -12,22 +23,23 @@ class CameraType(Enum): if channel == 1: return '' elif channel == 2: - if self.value == CameraType.HIKVISION: + if self.value in (CameraType.HIKVISION_264, CameraType.HIKVISION_265): return '/Streaming/Channels/2' elif self.value == CameraType.ALIEXPRESS_NONAME: return '/?stream=1.sdp' else: raise ValueError(f'unsupported camera type {self.value}') + def get_codec(self, channel: int) -> VideoCodecType: + if channel == 1: + return VideoCodecType.H264 if self.value == CameraType.HIKVISION_264 else VideoCodecType.H265 + elif channel == 2: + return VideoCodecType.H265 if self.value == CameraType.ALIEXPRESS_NONAME else VideoCodecType.H264 + else: + raise ValueError(f'unexpected channel {channel}') -class VideoContainerType(Enum): - MP4 = 'mp4' - MOV = 'mov' - - -class VideoCodecType(Enum): - H264 = 'h264' - H265 = 'h265' + def get_container(self) -> VideoContainerType: + return VideoContainerType.MP4 if self.get_codec(1) == VideoCodecType.H264 else VideoContainerType.MOV class TimeFilterType(Enum): diff --git a/requirements.txt b/requirements.txt index 521ae41..6067436 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,7 +6,7 @@ Werkzeug==2.3.6 uwsgi~=2.0.20 python-telegram-bot==20.3 requests==2.31.0 -aiohttp~=3.8.1 +aiohttp~=3.9.1 pytz==2023.3 PyYAML~=6.0 apscheduler==3.10.1 diff --git a/tasks/df_h.sh b/tasks/df_h.sh new file mode 100644 index 0000000..eaa10fe --- /dev/null +++ b/tasks/df_h.sh @@ -0,0 +1,2 @@ +#!/bin/sh +df -h
\ No newline at end of file |