-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideo.py
90 lines (59 loc) · 2.66 KB
/
video.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import os
import shutil
import datetime
from .config import CONFIG
def camera_port(webcam: int) -> str:
"""
Get the USB port ID of the given webcam in the list of configured cameras
:return: USB port ID of the webcam
"""
return CONFIG["webcams"][webcam]
def all_cameras() -> list[int]:
"""
Get the list of all configured cameras
:return: List of all configured cameras
"""
return [cam for cam in CONFIG["webcams"].keys()]
def init_video(webcam: int) -> None:
"""
Initialize the video directory for the given webcam
:param webcam: Webcam id
"""
for path in [CONFIG["storage"]["video"]["path"], *CONFIG["storage"]["video"]["backups"]]:
if os.path.exists(f"{path}/cam{webcam}"):
shutil.rmtree(f"{path}/cam{webcam}", ignore_errors=True)
os.makedirs(f"{path}/cam{webcam}")
def new_video(webcam: int) -> str:
"""
Get the path for a new video file for the given webcam
:param webcam: Webcam id
:return: Path to the new video file
"""
if not os.path.exists(f"{CONFIG['storage']['video']['path']}/cam{webcam}"):
raise FileNotFoundError(f"Video directory cam{webcam} not found! Please initialize it with reset.sh.")
return os.path.abspath(f"{CONFIG['storage']['video']['path']}/cam{webcam}/video_{datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S')}.mp4")
def new_photo(webcam: int) -> str:
"""
Get the path for a new photo file for the given webcam
:param webcam: Webcam id
:return: Path to the new photo file
"""
if not os.path.exists(f"{CONFIG['storage']['video']['path']}/cam{webcam}"):
raise FileNotFoundError(f"Video directory cam{webcam} not found! Please initialize it with reset.sh.")
return os.path.abspath(f"{CONFIG['storage']['video']['path']}/cam{webcam}/photo_{datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S')}.jpg")
def new_photo_small(webcam: int) -> str:
"""
Get the path for a new small photo file for the given webcam
:param webcam: Webcam id
:return: Path to the new photo file
"""
if not os.path.exists(f"{CONFIG['storage']['video']['path']}/cam{webcam}"):
raise FileNotFoundError(f"Video directory cam{webcam} not found! Please initialize it with reset.sh.")
return os.path.abspath(f"{CONFIG['storage']['video']['path']}/cam{webcam}/photo_{datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S')}-small.jpg")
def photo_remote(webcam: int) -> (str):
"""
Get the path for remote photo files for the given webcam
:param webcam: Webcam id
:return: Path to the remote photo directory
"""
return f"{CONFIG['storage']['remote']}/cam{webcam}"