aboutsummaryrefslogtreecommitdiff
path: root/include/py/homekit/camera/types.py
blob: da0fcc6cd7e4528b1c1c4a51370b048aa8eb045c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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_264 = 'hik_264'
    HIKVISION_265 = 'hik_265'

    def get_channel_url(self, channel: int) -> str:
        if channel not in (1, 2):
            raise ValueError(f'channel {channel} is invalid')
        if channel == 1:
            return ''
        elif channel == 2:
            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}')

    def get_container(self) -> VideoContainerType:
        return VideoContainerType.MP4 if self.get_codec(1) == VideoCodecType.H264 else VideoContainerType.MOV


class TimeFilterType(Enum):
    FIX = 'fix'
    MOTION = 'motion'
    MOTION_START = 'motion_start'


class TelegramLinkType(Enum):
    FRAGMENT = 'fragment'
    ORIGINAL_FILE = 'original_file'


class CaptureType(Enum):
    HLS = 'hls'
    RECORD = 'record'