-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathHyperAI_OBS.py
225 lines (194 loc) · 8.87 KB
/
HyperAI_OBS.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
from obswebsocket import obsws, events, requests # noqa: E402
from HyperAI_Secrets import OBS_WS_PASSWORD
class OBS_Websocket():
host = "localhost"
port = 4455
password = OBS_WS_PASSWORD
connected = False
ws = None
def check_connection(self):
if not self.connected:
try:
self.ws = obsws(self.host, self.port, self.password)
self.ws.connect()
self.connected = True
return True
except BaseException as err:
print('[OBS WS CONNECT ERR]', err)
self.connected = False
return False
else:
return True
def call_get(self, request):
try:
result = self.ws.call(request)
return dict(result.datain)
except BaseException as err:
print('[OBS WS REQ GET ERR]', err)
self.connected = False
return None
def call(self, request):
try:
self.ws.call(request)
return True
except BaseException as err:
print('[OBS WS REQ SIMPLE ERR]', err)
self.connected = False
return False
def get_stream_status(self) -> dict:
if self.check_connection():
stream_status = self.call_get(requests.GetStreamStatus())
if stream_status is not None:
return stream_status
return {"outputActive": False}
# https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md#getstreamstatus
# outputActive outputReconnecting outputTimecode outputDuration outputCongestion outputBytes outputSkippedFrames outputTotalFrames
def set_scene(self, scene_name: str) -> bool: # NetTyanChat NetTyan NetTyan NetTyanDisclaimer
if self.check_connection():
return self.call(requests.SetCurrentProgramScene(sceneName=scene_name))
def set_record(self, enable: bool) -> bool:
if self.check_connection():
if enable:
return self.call(requests.StartRecord())
else:
return self.call(requests.StopRecord())
def set_stream(self, enable: bool) -> bool:
if self.check_connection():
if enable:
return self.call(requests.StartStream())
else:
return self.call(requests.StopStream())
# timecode = stream_status.get("outputTimecode", "00:00:-00")
# active = stream_status.get("outputActive", False)
if __name__ == "__main__":
import sys
import time
import logging
# logging.basicConfig(level=logging.DEBUG)
# sys.path.append('../')
host = "localhost"
port = 4455
password = "h4sXG6mppje0wll4"
def on_event(message):
print("Got message: {}".format(message))
def on_switch(message):
print("You changed the scene to {}".format(message.getSceneName()))
# {'d': {'eventData': {'sceneName': 'NetTyanDisclaimer'}, 'eventIntent': 4, 'eventType': 'CurrentProgramSceneChanged'}, 'op': 5}
# Got message: <CurrentProgramSceneChanged event ({'sceneName': 'NetTyanDisclaimer'})>
def connec():
print('connec thread started')
new_obs_exemplar = OBS_Websocket()
print(new_obs_exemplar.get_stream_status())
time.sleep(10)
# new_obs_exemplar.set_record(True)
time.sleep(5)
# new_obs_exemplar.set_record(False)
time.sleep(10)
print(new_obs_exemplar.get_stream_status())
time.sleep(10)
print(new_obs_exemplar.get_stream_status())
time.sleep(10)
print(new_obs_exemplar.get_stream_status())
time.sleep(10)
print(new_obs_exemplar.get_stream_status())
time.sleep(10)
print(new_obs_exemplar.get_stream_status())
#
import threading
thr = threading.Thread(target=connec, daemon=True)
thr.start()
# ws = obsws(host, port, password)
#
# ws.register(on_event)
# ws.register(on_switch, events.SwitchScenes)
# ws.register(on_switch, events.CurrentProgramSceneChanged)
# ws.connect()
# Got message: <RecordStateChanged event ({'outputActive': True, 'outputPath': 'C:/Users/Onix/Downloads/2023-07-09 01-15-20.mp4', 'outputState': 'OBS_WEBSOCKET_OUTPUT_STARTED'})>
# Got message: <RecordStateChanged event ({'outputActive': False, 'outputPath': 'C:/Users/Onix/Downloads/2023-07-09 01-15-20.mp4', 'outputState': 'OBS_WEBSOCKET_OUTPUT_STOPPED'})>
# Хоррор версия NetTyan
# Got message: <SourceFilterEnableStateChanged event ({'filterEnabled': False, 'filterName': 'HorrorNetTyan', 'sourceName': 'VTube Studio'})>
# DEBUG:obswebsocket.core:Got event: {'d': {'eventData': {'filterEnabled': False, 'filterName': 'HorrorNetTyan', 'sourceName': 'VTube Studio'}, 'eventIntent': 32, 'eventType': 'SourceFilterEnableStateChanged'}, 'op': 5}
# DEBUG:obswebsocket.core:Got event: {'d': {'eventData': {'filterEnabled': True, 'filterName': 'HorrorNetTyan', 'sourceName': 'VTube Studio'}, 'eventIntent': 32, 'eventType': 'SourceFilterEnableStateChanged'}, 'op': 5}
# Got message: <SourceFilterEnableStateChanged event ({'filterEnabled': True, 'filterName': 'HorrorNetTyan', 'sourceName': 'VTube Studio'})>
# Нужное!
####def set_scare_filter(value: bool = True):
#### ws.call(requests.SetSourceFilterEnabled(sourceName="VTube Studio",filterName="HorrorNetTyan", filterEnabled=value))
####
####def scare_transition():
#### currentSceneData = ws.call(requests.GetCurrentProgramScene())
#### print("currentSceneData", currentSceneData, currentSceneData.data(),currentSceneData.datain,currentSceneData.dataout)
#### currentScene = currentSceneData.datain.get("currentProgramSceneName", "NetTyan")
#### print('got cur scene: '+currentScene+" "+str(currentSceneData))
#### ws.call(requests.SetSceneSceneTransitionOverride(sceneName=currentScene, transitionName=None,
#### transitionDuration=None))
#### #ws.call(requests.SetSceneSceneTransitionOverride(sceneName=currentScene, transitionName="NetTyanTransition", transitionDuration=1250))
####def get_stream_time():
#### stream_status = ws.call(requests.GetStreamStatus())
#### timecode = stream_status.datain.get("outputTimecode", "00:00:-00")
#### active = stream_status.datain.get("outputActive", False)
#### print(timecode,active)
# https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md#stopstream
obss = OBS_Websocket()
try:
print("OK")
time.sleep(1)
print('1')
# ws.call(requests.SetCurrentProgramScene(sceneName='NetTyan'))
# ws.call(requests.StartRecord())
# ws.call(requests.StartStream())
# ws.call(requests.StopStream())
# time.sleep(2)
# scare_transition()
time.sleep(0.4)
print(obss.get_stream_status())
# set_scare_filter(True)
# ws.call(requests.SetCurrentProgramScene(sceneName='NetTyan'))
time.sleep(1)
# set_scare_filter(False)
# ws.call(requests.SetCurrentProgramScene(sceneName='NetTyanDisclaimer'))
# ws.call(requests.StopRecord())
# https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md#setpersistentdata
# https://pub.dev/documentation/obs_websocket/latest/#sending-commands-to-obs---low-level
# ws.call(requests.GetPersistentData(realm='OBS_WEBSOCKET_DATA_REALM_PROFILE',slotName='port'))
time.sleep(100)
print("END")
except KeyboardInterrupt:
pass
# import obspython as obs
#
## The name of# the scene containing the text source
# scene_name = "NetTyan"
#
## The name of the text source to modify
# text_source_name = "TextForChange"
#
## The new text value to set
# new_text_value = "Hello, world!"
#
# def script_description():
# return "Changes the text value of a text source in an OBS sc3ene"
#
# def script_update(settings):
# # Get the current scene and text source objects
# current_scene = obs.obs_frontend_get_current_scene()
# scene = obs.obs_scene_from_source(current_scene)
# text_source = obs.obs_scene_find_source(scene, text_source_name)
#
# ###if scene is not None and text_source is not None:
# ### # Set the new text value
# ### settings_value = obs.obs_data_get_string(settings, "text_value")
# ### obs.obs_data_set_string(obs.obs_data_create(), "text", settings_value)
# ### obs.obs_source_update(text_source, obs.obs_data_create())
# ###
# ### # Release the objects
# ### obs.obs_source_release(text_source)
# ### obs.obs_scene_release(scene)
# ### obs.obs_sceneitem_release(current_scene)
#
# def script_properties():
# props = obs.obs_properties_create()
#
# # Add a text property for the new text value
# obs.obs_properties_add_text(props, "text_value", "New Text Value", obs.OBS_TEXT_DEFAULT)
#
# return props