-
Notifications
You must be signed in to change notification settings - Fork 1
/
settings.py
102 lines (84 loc) · 2.76 KB
/
settings.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
91
92
93
94
95
96
97
98
99
100
101
102
import os
with open("variables.txt", "r") as f:
for variable in f.readlines():
value = variable.split(":")[1].strip()
if value.isdigit():
value = int(value)
key = variable.split(":")[0]
vars()[key.upper()] = value
REQUIRED_VARIABLES = ["mapbox_username", "mapbox_key", "mapbox_username"]
for var in REQUIRED_VARIABLES:
if var.upper() not in vars():
raise ValueError(f"Mapbox {var} missing in the variables.txt file.")
MAPBOX_LINE_COLOUR_HEX = str(MAPBOX_LINE_COLOUR_HEX).replace("#", "")
MAPBOX_MARKER_COLOUR_HEX = str(MAPBOX_MARKER_COLOUR_HEX).replace("#", "")
MAPBOX_MARKER_LABEL = str(MAPBOX_MARKER_LABEL).replace(".svg", "")
if not MAPBOX_ZOOM_LEVEL:
MAPBOX_ZOOM_LEVEL = 17
if not MAPBOX_BASE_STYLE:
MAPBOX_BASE_STYLE = "mapbox/dark-v10"
if "INPUT_VIDEO_MODE" not in vars():
INPUT_VIDEO_MODE = "HERO"
# x and y offset (ratio to width and height)
OVERLAY_OFFSETS = {
"HERO" : {
# 2% from left, 2% from bottom
"x": 0.02,
"y": 0.02
},
"360" : {
# 30% from left, 30% from bottom
"x": 0.3,
"y": 0.3
},
"CUSTOM" : {
"x": VIDEO_OVERLAY_L_OFFSET,
"y": VIDEO_OVERLAY_B_OFFSET
}
}
# mapbox overlay's dimension setting with ratio to input video's dimensions
OVERLAY_RATIO = {
"HERO" : {
# 20% video width, 20% video height
"w": 0.2,
"h": 0.2
},
"360" : {
# 10% video width, 10% video height
"w": 0.1,
"h": 0.1
},
"CUSTOM" : {
"w": MAPBOX_IMG_W,
"h": MAPBOX_IMG_H
}
}
WORK_DIR = ""
def set_overlay_settings(video_w, video_h, mode):
global MAPBOX_IMG_H
global MAPBOX_IMG_W
global VIDEO_OVERLAY_L_OFFSET
global VIDEO_OVERLAY_B_OFFSET
global INPUT_VIDEO_MODE
INPUT_VIDEO_MODE = mode
if not MAPBOX_IMG_H:
MAPBOX_IMG_H = round(video_h * OVERLAY_RATIO[mode]['h'])
else:
MAPBOX_IMG_H = round(video_h * float(MAPBOX_IMG_H))
if not MAPBOX_IMG_W:
MAPBOX_IMG_W = round(video_w * OVERLAY_RATIO[mode]['w'])
else:
MAPBOX_IMG_W = round(video_w * float(MAPBOX_IMG_W))
if not VIDEO_OVERLAY_L_OFFSET:
VIDEO_OVERLAY_L_OFFSET = OVERLAY_OFFSETS[mode]['x']
if not VIDEO_OVERLAY_B_OFFSET:
VIDEO_OVERLAY_B_OFFSET = OVERLAY_OFFSETS[mode]['y']
if MAPBOX_IMG_H > 1280 or MAPBOX_IMG_H < 1 or MAPBOX_IMG_W > 1280 or MAPBOX_IMG_W < 1:
raise ValueError(f"MAPBOX_IMG_H and MAPBOX_IMG_W must be a number between 1 and 1280. Current settings: {MAPBOX_IMG_W}x{MAPBOX_IMG_H}")
def set_working_directory(wd):
global WORK_DIR
isExist = os.path.exists(wd)
if not isExist:
# Create a new directory because it does not exist
os.makedirs(wd)
WORK_DIR = wd