forked from kirek007/ws-osd-py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.py
106 lines (84 loc) · 2.91 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
103
104
105
106
import os
import pathlib
from processor import OsdGenStatus, OsdGenerator, OsdGenConfig
class AppState:
def __init__(self) -> None:
self._video_path = ""
self._osd_path = ""
self._font_path = ""
self._output_path = ""
self._srt_path = ""
self._osd_gen = None
self._include_srt = False
self._hide_sensitive_osd = False
self._use_hw = False
self._fast_srt = True
self.offsetLeft = 0
self.offsetTop = 0
self.osdZoom = 100
self.render_upscale = False
def updateOsdPosition(self, left, top, zoom):
self.offsetLeft = left
self.offsetTop = top
self.osdZoom = zoom
def getOptionsByPath(self, path: str):
file_ext = pathlib.Path(path).suffix
match file_ext:
case ".osd"|".mp4"|".srt":
video = os.fspath(pathlib.Path(path).with_suffix('.mp4'))
srt = os.fspath(pathlib.Path(path).with_suffix('.srt'))
osd = os.fspath(pathlib.Path(path).with_suffix('.osd'))
if os.path.exists(video):
self._video_path = video
if os.path.exists(srt):
self._srt_path = srt
if os.path.exists(osd):
self._osd_path = osd
self.update_output_path(path)
case ".png":
self._font_path = path
case _:
pass
def update_output_path(self, path: str):
self._output_path = os.path.join(
path, "%s_generated" % os.path.splitext(path)[0])
def is_output_exists(self):
return os.path.exists(self._output_path)
def is_configured(self) -> bool:
if (self._font_path and self._osd_path and self._video_path and not self.is_output_exists()):
return True
else:
return False
def osd_cancel_process(self):
if self._osd_gen:
self._osd_gen.stop()
def osd_gen_status(self) -> OsdGenStatus:
return self._osd_gen.osdGenStatus
def get_osd_config(self) -> OsdGenConfig:
return OsdGenConfig(
self._video_path,
self._osd_path,
self._font_path,
self._srt_path,
self._output_path,
self.offsetLeft,
self.offsetTop,
self.osdZoom,
self.render_upscale,
self._include_srt,
self._hide_sensitive_osd,
self._use_hw,
self._fast_srt
)
def osd_init(self) -> OsdGenStatus:
self._osd_gen = OsdGenerator(self.get_osd_config())
return self.osd_gen_status()
def osd_start_process(self):
self._osd_gen.start()
def osd_render_video(self):
self._osd_gen.start_video(False)
def osd_reset(self):
self._osd_gen = None
def get_osd(self):
return self._osd_gen
appState = AppState()