forked from wrp1002/Motion-Detection-Server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VideoManager.py
64 lines (52 loc) · 1.53 KB
/
VideoManager.py
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
59
60
61
62
63
64
from VideoDevice import VideoDevice
from Log import Log
import ConfigManager as config
import sys
import os
self = sys.modules[__name__]
self.cams = []
self.nextCamID = 0
self.name = "VideoManager"
def Init():
Log("Initializing Video Device Manager...", self)
self.cams = []
self.nextCamID = 0
def InitCams():
self.cams = []
self.nextCamID = 0
for cam in config.GetValue("cams"):
try:
c = VideoDevice(cam["name"], cam["url"], 1.5, self.nextCamID)
self.cams.append(c)
self.nextCamID += 1
except KeyError as e:
print("================================================================")
print("Error reading config value:")
print(cam)
print("Error reading key:", e)
print("================================================================")
Log("Cameras loaded", self)
def Cleanup():
Log("Cleaning preview directory...", self)
for file in os.listdir(os.path.join(config.scriptDir, "web/static/previews/")):
os.remove(os.path.join(config.scriptDir, "web/static/previews/", file))
Log("Done", self)
def Stop():
Log("Shutting down...")
for c in self.cams:
Log("Stopping", c)
c.Stop()
Cleanup()
def Restart():
Stop()
InitCams()
def GetCamInfo():
camInfo = []
for cam in self.cams:
info = {
"name": cam.name,
"id": cam.ID,
"connected": cam.IsConnected(),
}
camInfo.append(info)
return camInfo