This repository was archived by the owner on Aug 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathobs.py
More file actions
92 lines (69 loc) · 2.59 KB
/
Copy pathobs.py
File metadata and controls
92 lines (69 loc) · 2.59 KB
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
from urllib import request
from obswebsocket import obsws, requests # noqa: E402
import logger
import config
SETTINGS = config.get_config()
ws = None
try:
ws = obsws(SETTINGS['obs']['host'], int(
SETTINGS['obs']['port']), SETTINGS['obs']['password'])
ws.connect()
except Exception as e:
logger.error("Unable to connect to OBS: {}".format(repr(e)))
def obs_call(call):
try:
return ws.call(call)
except Exception as e:
logger.error("Error making OBS call: {}.".format(repr(e)))
def disconnect():
ws.disconnect()
def get_current_scene():
scenes = obs_call(requests.GetSceneList())
return scenes.getCurrentScene()
def get_scene_list():
scenes = obs_call(requests.GetSceneList())
return scenes.getScenes()
def is_in_scene_list(scene_name):
scenes = obs_call(requests.GetSceneList())
for scene in scenes.getScenes():
if scene_name == scene['name']:
return True
return False
def is_in_source_list(source_name):
sources = obs_call(requests.GetSourcesList())
for source in sources.getSources():
if source_name == source["name"]:
return True
return False
def broadcast_message(realm,message):
requests.BroadcastCustomMessage(realm, { "message": message })
logger.event(f'Broadcasted message "{message}" to realm {realm}')
def setSourceText(name, text):
try:
source_settings = obs_call(
requests.GetSourceSettings(name)).getSourceSettings()
logger.event('Changing source text of "{}" to "{}"'.format(name, text))
source_settings["text"] = text
obs_call(requests.SetSourceSettings(sourceName=name, sourceSettings=source_settings))
except Exception as e:
logger.error("Unable to set source text for {}: {}".format(name, repr(e)))
def setSourceImage(name,file):
try:
source_settings = obs_call(
requests.GetSourceSettings(name)).getSourceSettings()
logger.event('Changing source image of "{}" to "{}"'.format(name, file))
source_settings["file"] = file
obs_call(requests.SetSourceSettings(sourceName=name, sourceSettings=source_settings))
except Exception as e:
logger.error("Unable to set source image for {}: {}".format(name, repr(e)))
def change_scene(name):
try:
logger.event("Switching to {}".format(name))
ws.call(requests.SetCurrentScene(name))
except Exception as e:
logger.error("Unable to scene to {}: {}".format(name, repr(e)))
if __name__ == "__main__":
setSourceImage("Image","")