cctvql 1.0.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cctvql/__init__.py +11 -0
- cctvql/__main__.py +119 -0
- cctvql/_bootstrap.py +285 -0
- cctvql/adapters/__init__.py +22 -0
- cctvql/adapters/base.py +182 -0
- cctvql/adapters/dahua.py +573 -0
- cctvql/adapters/demo.py +680 -0
- cctvql/adapters/frigate.py +409 -0
- cctvql/adapters/hikvision.py +645 -0
- cctvql/adapters/milestone.py +418 -0
- cctvql/adapters/onvif.py +377 -0
- cctvql/adapters/onvif_discovery.py +252 -0
- cctvql/adapters/scrypted.py +399 -0
- cctvql/adapters/synology.py +424 -0
- cctvql/core/__init__.py +29 -0
- cctvql/core/alerts.py +378 -0
- cctvql/core/anomaly.py +331 -0
- cctvql/core/auth.py +193 -0
- cctvql/core/database.py +231 -0
- cctvql/core/health_monitor.py +217 -0
- cctvql/core/multi_query.py +269 -0
- cctvql/core/nlp_engine.py +210 -0
- cctvql/core/query_router.py +550 -0
- cctvql/core/schema.py +216 -0
- cctvql/core/session_store.py +44 -0
- cctvql/core/user_store.py +190 -0
- cctvql/core/vision.py +268 -0
- cctvql/interfaces/__init__.py +3 -0
- cctvql/interfaces/cli.py +173 -0
- cctvql/interfaces/rest_api.py +1282 -0
- cctvql/interfaces/voice.py +308 -0
- cctvql/llm/__init__.py +14 -0
- cctvql/llm/anthropic_backend.py +177 -0
- cctvql/llm/base.py +112 -0
- cctvql/llm/ollama_backend.py +147 -0
- cctvql/llm/openai_backend.py +161 -0
- cctvql/notifications/__init__.py +20 -0
- cctvql/notifications/base.py +37 -0
- cctvql/notifications/email_notifier.py +87 -0
- cctvql/notifications/ntfy.py +53 -0
- cctvql/notifications/registry.py +56 -0
- cctvql/notifications/slack.py +61 -0
- cctvql/notifications/telegram.py +48 -0
- cctvql/notifications/webhook.py +50 -0
- cctvql/py.typed +0 -0
- cctvql-1.0.2.dist-info/METADATA +515 -0
- cctvql-1.0.2.dist-info/RECORD +51 -0
- cctvql-1.0.2.dist-info/WHEEL +5 -0
- cctvql-1.0.2.dist-info/entry_points.txt +2 -0
- cctvql-1.0.2.dist-info/licenses/LICENSE +21 -0
- cctvql-1.0.2.dist-info/top_level.txt +1 -0
cctvql/__init__.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"""
|
|
2
|
+
cctvQL — Conversational Query Layer for CCTV Systems
|
|
3
|
+
=====================================================
|
|
4
|
+
Ask your cameras anything in plain English.
|
|
5
|
+
|
|
6
|
+
GitHub: https://github.com/arunrajiah/cctvql
|
|
7
|
+
License: MIT
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
__version__ = "0.1.0"
|
|
11
|
+
__author__ = "arunrajiah"
|
cctvql/__main__.py
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"""
|
|
2
|
+
cctvQL entry point.
|
|
3
|
+
Run as: python -m cctvql or cctvql (after pip install)
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
import argparse
|
|
9
|
+
import sys
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def main() -> None:
|
|
13
|
+
parser = argparse.ArgumentParser(
|
|
14
|
+
prog="cctvql",
|
|
15
|
+
description="cctvQL — Conversational query layer for CCTV systems",
|
|
16
|
+
)
|
|
17
|
+
subparsers = parser.add_subparsers(dest="command")
|
|
18
|
+
|
|
19
|
+
# ---- chat subcommand ----
|
|
20
|
+
chat_parser = subparsers.add_parser("chat", help="Start interactive CLI chat")
|
|
21
|
+
chat_parser.add_argument("--config", default="config/config.yaml", help="Path to config file")
|
|
22
|
+
chat_parser.add_argument("--adapter", help="Adapter name (frigate, onvif, ...)")
|
|
23
|
+
chat_parser.add_argument("--llm", help="LLM backend name (ollama, openai, anthropic)")
|
|
24
|
+
chat_parser.add_argument("--verbose", "-v", action="store_true", help="Show intent debug info")
|
|
25
|
+
|
|
26
|
+
# ---- serve subcommand ----
|
|
27
|
+
serve_parser = subparsers.add_parser("serve", help="Start REST API server")
|
|
28
|
+
serve_parser.add_argument("--config", default="config/config.yaml")
|
|
29
|
+
serve_parser.add_argument("--host", default="0.0.0.0")
|
|
30
|
+
serve_parser.add_argument("--port", type=int, default=8000)
|
|
31
|
+
serve_parser.add_argument("--reload", action="store_true", help="Auto-reload on code changes")
|
|
32
|
+
|
|
33
|
+
# ---- discover subcommand ----
|
|
34
|
+
discover_parser = subparsers.add_parser(
|
|
35
|
+
"discover", help="Discover ONVIF cameras on the local network"
|
|
36
|
+
)
|
|
37
|
+
discover_parser.add_argument(
|
|
38
|
+
"--timeout", type=float, default=3.0, help="Probe timeout in seconds (default: 3.0)"
|
|
39
|
+
)
|
|
40
|
+
discover_parser.add_argument(
|
|
41
|
+
"--interface", default="", help="Local interface IP to bind to (default: all)"
|
|
42
|
+
)
|
|
43
|
+
discover_parser.add_argument(
|
|
44
|
+
"--yaml", action="store_true", help="Output as config.yaml adapter snippet"
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
args = parser.parse_args()
|
|
48
|
+
|
|
49
|
+
if args.command == "chat":
|
|
50
|
+
from cctvql._bootstrap import bootstrap
|
|
51
|
+
|
|
52
|
+
bootstrap(args.config)
|
|
53
|
+
from cctvql.interfaces.cli import run_cli
|
|
54
|
+
|
|
55
|
+
run_cli(
|
|
56
|
+
adapter_name=args.adapter,
|
|
57
|
+
llm_name=args.llm,
|
|
58
|
+
verbose=args.verbose,
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
elif args.command == "serve":
|
|
62
|
+
from cctvql._bootstrap import bootstrap
|
|
63
|
+
|
|
64
|
+
bootstrap(args.config)
|
|
65
|
+
import uvicorn
|
|
66
|
+
|
|
67
|
+
uvicorn.run(
|
|
68
|
+
"cctvql.interfaces.rest_api:app",
|
|
69
|
+
host=args.host,
|
|
70
|
+
port=args.port,
|
|
71
|
+
reload=args.reload,
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
elif args.command == "discover":
|
|
75
|
+
import asyncio
|
|
76
|
+
|
|
77
|
+
from cctvql.adapters.onvif_discovery import discover_onvif_devices
|
|
78
|
+
|
|
79
|
+
print(f"Scanning for ONVIF cameras (timeout={args.timeout}s) …\n")
|
|
80
|
+
devices = asyncio.run(
|
|
81
|
+
discover_onvif_devices(timeout=args.timeout, interface=args.interface)
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
if not devices:
|
|
85
|
+
print("No ONVIF devices found.")
|
|
86
|
+
print("Make sure your cameras are on the same subnet and support WS-Discovery.")
|
|
87
|
+
sys.exit(0)
|
|
88
|
+
|
|
89
|
+
print(f"Found {len(devices)} device(s):\n")
|
|
90
|
+
for i, d in enumerate(devices, 1):
|
|
91
|
+
print(f" [{i}] {d.name}")
|
|
92
|
+
print(f" Address : {d.address}")
|
|
93
|
+
print(f" Host : {d.host} Port: {d.port}")
|
|
94
|
+
if d.hardware:
|
|
95
|
+
print(f" Hardware: {d.hardware}")
|
|
96
|
+
print()
|
|
97
|
+
|
|
98
|
+
if args.yaml:
|
|
99
|
+
print("─── config.yaml adapter snippet ───")
|
|
100
|
+
print("adapters:")
|
|
101
|
+
print(" active: onvif")
|
|
102
|
+
print(" systems:")
|
|
103
|
+
for d in devices:
|
|
104
|
+
safe_name = (d.name or "onvif").lower().replace(" ", "_")
|
|
105
|
+
print(f" {safe_name}:")
|
|
106
|
+
print(" type: onvif")
|
|
107
|
+
print(f" host: {d.host}")
|
|
108
|
+
print(f" port: {d.port}")
|
|
109
|
+
print(" username: admin")
|
|
110
|
+
print(' password: ""')
|
|
111
|
+
print("───────────────────────────────────")
|
|
112
|
+
|
|
113
|
+
else:
|
|
114
|
+
parser.print_help()
|
|
115
|
+
sys.exit(1)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
if __name__ == "__main__":
|
|
119
|
+
main()
|
cctvql/_bootstrap.py
ADDED
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
"""
|
|
2
|
+
cctvQL Bootstrap
|
|
3
|
+
-----------------
|
|
4
|
+
Loads config.yaml and wires up adapters + LLM backends into their registries.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import logging
|
|
10
|
+
import os
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
from typing import Any
|
|
13
|
+
|
|
14
|
+
import yaml
|
|
15
|
+
|
|
16
|
+
from cctvql.adapters.base import AdapterRegistry
|
|
17
|
+
from cctvql.llm.base import LLMRegistry
|
|
18
|
+
|
|
19
|
+
logger = logging.getLogger(__name__)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def bootstrap(config_path: str = "config/config.yaml") -> None:
|
|
23
|
+
"""
|
|
24
|
+
Read config file and register all configured adapters and LLM backends.
|
|
25
|
+
Sets the active adapter and LLM as specified in config.
|
|
26
|
+
"""
|
|
27
|
+
path = Path(config_path)
|
|
28
|
+
if not path.exists():
|
|
29
|
+
logger.warning("Config file not found: %s — using defaults", config_path)
|
|
30
|
+
_bootstrap_defaults()
|
|
31
|
+
return
|
|
32
|
+
|
|
33
|
+
with open(path) as f:
|
|
34
|
+
config: dict[str, Any] = yaml.safe_load(f) or {}
|
|
35
|
+
|
|
36
|
+
_setup_logging(config.get("logging", {}))
|
|
37
|
+
_setup_llms(config.get("llm", {}))
|
|
38
|
+
_setup_adapters(config.get("adapters", {}))
|
|
39
|
+
_setup_notifications(config.get("notifications", {}))
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _bootstrap_defaults() -> None:
|
|
43
|
+
"""Register default Ollama + Frigate for zero-config startup."""
|
|
44
|
+
from cctvql.adapters.frigate import FrigateAdapter
|
|
45
|
+
from cctvql.llm.ollama_backend import OllamaBackend
|
|
46
|
+
|
|
47
|
+
llm = OllamaBackend()
|
|
48
|
+
LLMRegistry.register(llm)
|
|
49
|
+
LLMRegistry.set_active("ollama")
|
|
50
|
+
|
|
51
|
+
adapter = FrigateAdapter()
|
|
52
|
+
AdapterRegistry.register(adapter)
|
|
53
|
+
AdapterRegistry.set_active("frigate")
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _setup_llms(llm_config: dict) -> None:
|
|
57
|
+
active = llm_config.get("active", "ollama")
|
|
58
|
+
|
|
59
|
+
backends = llm_config.get("backends", {})
|
|
60
|
+
if not backends:
|
|
61
|
+
# Sensible defaults if no backends configured
|
|
62
|
+
backends = {"ollama": {"provider": "ollama"}}
|
|
63
|
+
|
|
64
|
+
for name, cfg in backends.items():
|
|
65
|
+
provider = cfg.get("provider", name)
|
|
66
|
+
try:
|
|
67
|
+
backend = _create_llm(provider, cfg)
|
|
68
|
+
LLMRegistry.register(backend)
|
|
69
|
+
logger.debug("Registered LLM backend: %s", backend.name)
|
|
70
|
+
except Exception as exc:
|
|
71
|
+
logger.warning("Could not register LLM '%s': %s", name, exc)
|
|
72
|
+
|
|
73
|
+
if LLMRegistry.available():
|
|
74
|
+
try:
|
|
75
|
+
LLMRegistry.set_active(active)
|
|
76
|
+
except ValueError:
|
|
77
|
+
first = LLMRegistry.available()[0]
|
|
78
|
+
logger.warning("Active LLM '%s' not found, falling back to '%s'", active, first)
|
|
79
|
+
LLMRegistry.set_active(first)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def _create_llm(provider: str, cfg: dict):
|
|
83
|
+
if provider == "ollama":
|
|
84
|
+
from cctvql.llm.ollama_backend import OllamaBackend
|
|
85
|
+
|
|
86
|
+
return OllamaBackend(
|
|
87
|
+
host=cfg.get("host", "http://localhost:11434"),
|
|
88
|
+
model=cfg.get("model", "llama3"),
|
|
89
|
+
)
|
|
90
|
+
elif provider == "openai":
|
|
91
|
+
from cctvql.llm.openai_backend import OpenAIBackend
|
|
92
|
+
|
|
93
|
+
return OpenAIBackend(
|
|
94
|
+
api_key=cfg.get("api_key") or os.environ.get("OPENAI_API_KEY"),
|
|
95
|
+
model=cfg.get("model", "gpt-4o-mini"),
|
|
96
|
+
base_url=cfg.get("base_url"),
|
|
97
|
+
)
|
|
98
|
+
elif provider == "anthropic":
|
|
99
|
+
from cctvql.llm.anthropic_backend import AnthropicBackend
|
|
100
|
+
|
|
101
|
+
return AnthropicBackend(
|
|
102
|
+
api_key=cfg.get("api_key") or os.environ.get("ANTHROPIC_API_KEY"),
|
|
103
|
+
model=cfg.get("model", "claude-haiku-4-5-20251001"),
|
|
104
|
+
)
|
|
105
|
+
else:
|
|
106
|
+
raise ValueError(f"Unknown LLM provider: {provider}")
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def _setup_adapters(adapters_config: dict) -> None:
|
|
110
|
+
active = adapters_config.get("active", "frigate")
|
|
111
|
+
systems = adapters_config.get("systems", {})
|
|
112
|
+
|
|
113
|
+
if not systems:
|
|
114
|
+
systems = {"frigate": {"type": "frigate"}}
|
|
115
|
+
|
|
116
|
+
for name, cfg in systems.items():
|
|
117
|
+
adapter_type = cfg.get("type", name)
|
|
118
|
+
try:
|
|
119
|
+
adapter = _create_adapter(adapter_type, cfg)
|
|
120
|
+
AdapterRegistry.register(adapter)
|
|
121
|
+
logger.debug("Registered adapter: %s", adapter.name)
|
|
122
|
+
except Exception as exc:
|
|
123
|
+
logger.warning("Could not register adapter '%s': %s", name, exc)
|
|
124
|
+
|
|
125
|
+
if AdapterRegistry.available():
|
|
126
|
+
try:
|
|
127
|
+
AdapterRegistry.set_active(active)
|
|
128
|
+
except ValueError:
|
|
129
|
+
first = AdapterRegistry.available()[0]
|
|
130
|
+
logger.warning("Active adapter '%s' not found, falling back to '%s'", active, first)
|
|
131
|
+
AdapterRegistry.set_active(first)
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def _create_adapter(adapter_type: str, cfg: dict):
|
|
135
|
+
if adapter_type == "frigate":
|
|
136
|
+
from cctvql.adapters.frigate import FrigateAdapter
|
|
137
|
+
|
|
138
|
+
return FrigateAdapter(
|
|
139
|
+
host=cfg.get("host", "http://localhost:5000"),
|
|
140
|
+
mqtt_host=cfg.get("mqtt_host"),
|
|
141
|
+
mqtt_port=cfg.get("mqtt_port", 1883),
|
|
142
|
+
)
|
|
143
|
+
elif adapter_type == "onvif":
|
|
144
|
+
from cctvql.adapters.onvif import ONVIFAdapter
|
|
145
|
+
|
|
146
|
+
return ONVIFAdapter(
|
|
147
|
+
host=cfg.get("host", "192.168.1.100"),
|
|
148
|
+
port=cfg.get("port", 80),
|
|
149
|
+
username=cfg.get("username", "admin"),
|
|
150
|
+
password=cfg.get("password", ""),
|
|
151
|
+
)
|
|
152
|
+
elif adapter_type == "demo":
|
|
153
|
+
from cctvql.adapters.demo import DemoAdapter
|
|
154
|
+
|
|
155
|
+
return DemoAdapter()
|
|
156
|
+
elif adapter_type == "hikvision":
|
|
157
|
+
from cctvql.adapters.hikvision import HikvisionAdapter
|
|
158
|
+
|
|
159
|
+
return HikvisionAdapter(
|
|
160
|
+
host=cfg.get("host", "192.168.1.100"),
|
|
161
|
+
username=cfg.get("username", "admin"),
|
|
162
|
+
password=cfg.get("password", ""),
|
|
163
|
+
channel_count=cfg.get("channel_count"),
|
|
164
|
+
)
|
|
165
|
+
elif adapter_type == "dahua":
|
|
166
|
+
from cctvql.adapters.dahua import DahuaAdapter
|
|
167
|
+
|
|
168
|
+
return DahuaAdapter(
|
|
169
|
+
host=cfg.get("host", "192.168.1.100"),
|
|
170
|
+
port=cfg.get("port", 80),
|
|
171
|
+
username=cfg.get("username", "admin"),
|
|
172
|
+
password=cfg.get("password", ""),
|
|
173
|
+
channel_count=cfg.get("channel_count", 4),
|
|
174
|
+
)
|
|
175
|
+
elif adapter_type == "synology":
|
|
176
|
+
from cctvql.adapters.synology import SynologyAdapter
|
|
177
|
+
|
|
178
|
+
return SynologyAdapter(
|
|
179
|
+
host=cfg.get("host", "http://192.168.1.10:5000"),
|
|
180
|
+
username=cfg.get("username", "admin"),
|
|
181
|
+
password=cfg.get("password", ""),
|
|
182
|
+
session=cfg.get("session", "SurveillanceStation"),
|
|
183
|
+
ssl_verify=cfg.get("ssl_verify", True),
|
|
184
|
+
)
|
|
185
|
+
elif adapter_type == "milestone":
|
|
186
|
+
from cctvql.adapters.milestone import MilestoneAdapter
|
|
187
|
+
|
|
188
|
+
return MilestoneAdapter(
|
|
189
|
+
host=cfg.get("host", "https://vms.example.com"),
|
|
190
|
+
username=cfg.get("username", "admin"),
|
|
191
|
+
password=cfg.get("password", ""),
|
|
192
|
+
client_id=cfg.get("client_id", "GrantValidatorClient"),
|
|
193
|
+
grant_type=cfg.get("grant_type", "password"),
|
|
194
|
+
ssl_verify=cfg.get("ssl_verify", True),
|
|
195
|
+
)
|
|
196
|
+
elif adapter_type == "scrypted":
|
|
197
|
+
from cctvql.adapters.scrypted import ScryptedAdapter
|
|
198
|
+
|
|
199
|
+
return ScryptedAdapter(
|
|
200
|
+
host=cfg.get("host", "https://scrypted.local:10443"),
|
|
201
|
+
api_token=cfg.get("api_token", ""),
|
|
202
|
+
username=cfg.get("username", ""),
|
|
203
|
+
password=cfg.get("password", ""),
|
|
204
|
+
ssl_verify=cfg.get("ssl_verify", True),
|
|
205
|
+
)
|
|
206
|
+
else:
|
|
207
|
+
raise ValueError(f"Unknown adapter type: {adapter_type}")
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def _setup_notifications(notif_config: dict) -> None:
|
|
211
|
+
"""Register notification channels from config."""
|
|
212
|
+
if not notif_config:
|
|
213
|
+
return
|
|
214
|
+
|
|
215
|
+
from cctvql.notifications.registry import NotifierRegistry
|
|
216
|
+
|
|
217
|
+
# Webhook
|
|
218
|
+
for wh in notif_config.get("webhooks", []):
|
|
219
|
+
url = wh.get("url")
|
|
220
|
+
if url:
|
|
221
|
+
from cctvql.notifications.webhook import WebhookNotifier
|
|
222
|
+
|
|
223
|
+
NotifierRegistry.register(WebhookNotifier(url=url))
|
|
224
|
+
logger.debug("Registered webhook notifier: %s", url)
|
|
225
|
+
|
|
226
|
+
# Telegram
|
|
227
|
+
tg = notif_config.get("telegram", {})
|
|
228
|
+
if tg.get("bot_token") and tg.get("chat_id"):
|
|
229
|
+
from cctvql.notifications.telegram import TelegramNotifier
|
|
230
|
+
|
|
231
|
+
NotifierRegistry.register(
|
|
232
|
+
TelegramNotifier(bot_token=tg["bot_token"], chat_id=str(tg["chat_id"]))
|
|
233
|
+
)
|
|
234
|
+
logger.debug("Registered Telegram notifier")
|
|
235
|
+
|
|
236
|
+
# Slack
|
|
237
|
+
sl = notif_config.get("slack", {})
|
|
238
|
+
if sl.get("webhook_url"):
|
|
239
|
+
from cctvql.notifications.slack import SlackNotifier
|
|
240
|
+
|
|
241
|
+
NotifierRegistry.register(SlackNotifier(webhook_url=sl["webhook_url"]))
|
|
242
|
+
logger.debug("Registered Slack notifier")
|
|
243
|
+
|
|
244
|
+
# ntfy
|
|
245
|
+
nt = notif_config.get("ntfy", {})
|
|
246
|
+
if nt.get("topic"):
|
|
247
|
+
from cctvql.notifications.ntfy import NtfyNotifier
|
|
248
|
+
|
|
249
|
+
NotifierRegistry.register(
|
|
250
|
+
NtfyNotifier(
|
|
251
|
+
topic=nt["topic"],
|
|
252
|
+
server=nt.get("server", "https://ntfy.sh"),
|
|
253
|
+
)
|
|
254
|
+
)
|
|
255
|
+
logger.debug("Registered ntfy notifier: %s", nt["topic"])
|
|
256
|
+
|
|
257
|
+
# Email
|
|
258
|
+
em = notif_config.get("email", {})
|
|
259
|
+
if em.get("smtp_host") and em.get("from_addr") and em.get("to_addrs"):
|
|
260
|
+
from cctvql.notifications.email_notifier import EmailNotifier
|
|
261
|
+
|
|
262
|
+
NotifierRegistry.register(
|
|
263
|
+
EmailNotifier(
|
|
264
|
+
smtp_host=em["smtp_host"],
|
|
265
|
+
smtp_port=int(em.get("smtp_port", 587)),
|
|
266
|
+
username=em.get("username", ""),
|
|
267
|
+
password=em.get("password", ""),
|
|
268
|
+
from_addr=em["from_addr"],
|
|
269
|
+
to_addrs=em["to_addrs"] if isinstance(em["to_addrs"], list) else [em["to_addrs"]],
|
|
270
|
+
use_tls=bool(em.get("use_tls", True)),
|
|
271
|
+
)
|
|
272
|
+
)
|
|
273
|
+
logger.debug("Registered email notifier → %s", em["to_addrs"])
|
|
274
|
+
|
|
275
|
+
registered = len(NotifierRegistry.all())
|
|
276
|
+
if registered:
|
|
277
|
+
logger.info("Notifications: %d channel(s) registered", registered)
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
def _setup_logging(log_config: dict) -> None:
|
|
281
|
+
level = getattr(logging, log_config.get("level", "INFO").upper(), logging.INFO)
|
|
282
|
+
logging.basicConfig(
|
|
283
|
+
level=level,
|
|
284
|
+
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
|
|
285
|
+
)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
from .base import AdapterRegistry, BaseAdapter
|
|
2
|
+
from .dahua import DahuaAdapter
|
|
3
|
+
from .demo import DemoAdapter
|
|
4
|
+
from .frigate import FrigateAdapter
|
|
5
|
+
from .hikvision import HikvisionAdapter
|
|
6
|
+
from .milestone import MilestoneAdapter
|
|
7
|
+
from .onvif import ONVIFAdapter
|
|
8
|
+
from .scrypted import ScryptedAdapter
|
|
9
|
+
from .synology import SynologyAdapter
|
|
10
|
+
|
|
11
|
+
__all__ = [
|
|
12
|
+
"BaseAdapter",
|
|
13
|
+
"AdapterRegistry",
|
|
14
|
+
"FrigateAdapter",
|
|
15
|
+
"ONVIFAdapter",
|
|
16
|
+
"DemoAdapter",
|
|
17
|
+
"HikvisionAdapter",
|
|
18
|
+
"DahuaAdapter",
|
|
19
|
+
"SynologyAdapter",
|
|
20
|
+
"MilestoneAdapter",
|
|
21
|
+
"ScryptedAdapter",
|
|
22
|
+
]
|
cctvql/adapters/base.py
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"""
|
|
2
|
+
cctvQL Adapter Base
|
|
3
|
+
--------------------
|
|
4
|
+
Abstract interface that every CCTV system adapter must implement.
|
|
5
|
+
This is the contract between cctvQL's core and any vendor-specific system.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from abc import ABC, abstractmethod
|
|
11
|
+
from datetime import datetime
|
|
12
|
+
|
|
13
|
+
from cctvql.core.schema import Camera, Clip, Event, SystemInfo, Zone
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class BaseAdapter(ABC):
|
|
17
|
+
"""
|
|
18
|
+
Abstract base class for CCTV system adapters.
|
|
19
|
+
|
|
20
|
+
To add support for a new system:
|
|
21
|
+
1. Subclass BaseAdapter
|
|
22
|
+
2. Implement all abstract methods
|
|
23
|
+
3. Register via AdapterRegistry or in config.yaml
|
|
24
|
+
|
|
25
|
+
Each method should return normalized cctvQL schema objects —
|
|
26
|
+
never vendor-specific raw data.
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
@property
|
|
30
|
+
@abstractmethod
|
|
31
|
+
def name(self) -> str:
|
|
32
|
+
"""Human-readable adapter name (e.g. 'frigate', 'onvif')."""
|
|
33
|
+
...
|
|
34
|
+
|
|
35
|
+
@abstractmethod
|
|
36
|
+
async def connect(self) -> bool:
|
|
37
|
+
"""
|
|
38
|
+
Establish connection to the CCTV system.
|
|
39
|
+
Returns True if successful.
|
|
40
|
+
"""
|
|
41
|
+
...
|
|
42
|
+
|
|
43
|
+
@abstractmethod
|
|
44
|
+
async def disconnect(self) -> None:
|
|
45
|
+
"""Gracefully disconnect from the CCTV system."""
|
|
46
|
+
...
|
|
47
|
+
|
|
48
|
+
@abstractmethod
|
|
49
|
+
async def list_cameras(self) -> list[Camera]:
|
|
50
|
+
"""Return all cameras in the system."""
|
|
51
|
+
...
|
|
52
|
+
|
|
53
|
+
@abstractmethod
|
|
54
|
+
async def get_camera(
|
|
55
|
+
self,
|
|
56
|
+
camera_id: str | None = None,
|
|
57
|
+
camera_name: str | None = None,
|
|
58
|
+
) -> Camera | None:
|
|
59
|
+
"""Retrieve a single camera by id or name."""
|
|
60
|
+
...
|
|
61
|
+
|
|
62
|
+
@abstractmethod
|
|
63
|
+
async def get_events(
|
|
64
|
+
self,
|
|
65
|
+
camera_id: str | None = None,
|
|
66
|
+
camera_name: str | None = None,
|
|
67
|
+
label: str | None = None,
|
|
68
|
+
zone: str | None = None,
|
|
69
|
+
start_time: datetime | None = None,
|
|
70
|
+
end_time: datetime | None = None,
|
|
71
|
+
limit: int = 20,
|
|
72
|
+
) -> list[Event]:
|
|
73
|
+
"""
|
|
74
|
+
Fetch detection/motion events with optional filters.
|
|
75
|
+
|
|
76
|
+
All parameters are optional — omitting them returns all recent events.
|
|
77
|
+
"""
|
|
78
|
+
...
|
|
79
|
+
|
|
80
|
+
@abstractmethod
|
|
81
|
+
async def get_event(self, event_id: str) -> Event | None:
|
|
82
|
+
"""Retrieve a single event by its ID."""
|
|
83
|
+
...
|
|
84
|
+
|
|
85
|
+
@abstractmethod
|
|
86
|
+
async def get_clips(
|
|
87
|
+
self,
|
|
88
|
+
camera_id: str | None = None,
|
|
89
|
+
camera_name: str | None = None,
|
|
90
|
+
start_time: datetime | None = None,
|
|
91
|
+
end_time: datetime | None = None,
|
|
92
|
+
limit: int = 20,
|
|
93
|
+
) -> list[Clip]:
|
|
94
|
+
"""Fetch recorded video clips."""
|
|
95
|
+
...
|
|
96
|
+
|
|
97
|
+
@abstractmethod
|
|
98
|
+
async def get_snapshot_url(
|
|
99
|
+
self,
|
|
100
|
+
camera_id: str | None = None,
|
|
101
|
+
camera_name: str | None = None,
|
|
102
|
+
) -> str | None:
|
|
103
|
+
"""Return a URL to the latest snapshot for the given camera."""
|
|
104
|
+
...
|
|
105
|
+
|
|
106
|
+
@abstractmethod
|
|
107
|
+
async def get_system_info(self) -> SystemInfo | None:
|
|
108
|
+
"""Return high-level system health and storage info."""
|
|
109
|
+
...
|
|
110
|
+
|
|
111
|
+
# Optional — adapters can override for richer functionality
|
|
112
|
+
|
|
113
|
+
async def list_zones(self, camera_id: str | None = None) -> list[Zone]:
|
|
114
|
+
"""List configured zones/regions. Override for full support."""
|
|
115
|
+
return []
|
|
116
|
+
|
|
117
|
+
async def health_check(self) -> bool:
|
|
118
|
+
"""Return True if the system is reachable."""
|
|
119
|
+
return True
|
|
120
|
+
|
|
121
|
+
async def ptz_move(self, camera_name: str, action: str, speed: int = 50) -> bool:
|
|
122
|
+
"""
|
|
123
|
+
Pan/tilt/zoom a camera.
|
|
124
|
+
|
|
125
|
+
Args:
|
|
126
|
+
camera_name: Camera to control.
|
|
127
|
+
action: One of left|right|up|down|zoom_in|zoom_out|stop.
|
|
128
|
+
speed: Movement speed 1–100 (default: 50).
|
|
129
|
+
|
|
130
|
+
Returns:
|
|
131
|
+
True if the command was accepted, False if PTZ is not supported.
|
|
132
|
+
"""
|
|
133
|
+
return False
|
|
134
|
+
|
|
135
|
+
async def ptz_preset(self, camera_name: str, preset_id: int) -> bool:
|
|
136
|
+
"""
|
|
137
|
+
Move camera to a named PTZ preset.
|
|
138
|
+
|
|
139
|
+
Args:
|
|
140
|
+
camera_name: Camera to control.
|
|
141
|
+
preset_id: Numeric preset identifier.
|
|
142
|
+
|
|
143
|
+
Returns:
|
|
144
|
+
True if the command was accepted, False if PTZ is not supported.
|
|
145
|
+
"""
|
|
146
|
+
return False
|
|
147
|
+
|
|
148
|
+
async def get_ptz_presets(self, camera_name: str) -> list[dict]:
|
|
149
|
+
"""
|
|
150
|
+
Return available PTZ presets for a camera.
|
|
151
|
+
|
|
152
|
+
Returns:
|
|
153
|
+
list of {"id": int, "name": str} dicts.
|
|
154
|
+
"""
|
|
155
|
+
return []
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
class AdapterRegistry:
|
|
159
|
+
"""Maps adapter names to instances for multi-system setups."""
|
|
160
|
+
|
|
161
|
+
_adapters: dict[str, BaseAdapter] = {}
|
|
162
|
+
_active: str | None = None
|
|
163
|
+
|
|
164
|
+
@classmethod
|
|
165
|
+
def register(cls, adapter: BaseAdapter) -> None:
|
|
166
|
+
cls._adapters[adapter.name] = adapter
|
|
167
|
+
|
|
168
|
+
@classmethod
|
|
169
|
+
def set_active(cls, name: str) -> None:
|
|
170
|
+
if name not in cls._adapters:
|
|
171
|
+
raise ValueError(f"Adapter '{name}' not registered.")
|
|
172
|
+
cls._active = name
|
|
173
|
+
|
|
174
|
+
@classmethod
|
|
175
|
+
def get_active(cls) -> BaseAdapter:
|
|
176
|
+
if not cls._active or cls._active not in cls._adapters:
|
|
177
|
+
raise RuntimeError("No active adapter configured.")
|
|
178
|
+
return cls._adapters[cls._active]
|
|
179
|
+
|
|
180
|
+
@classmethod
|
|
181
|
+
def available(cls) -> list[str]:
|
|
182
|
+
return list(cls._adapters.keys())
|