-
Notifications
You must be signed in to change notification settings - Fork 0
/
call_obs.py
executable file
·96 lines (79 loc) · 2.44 KB
/
call_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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import os.path
import time
import yaml
from obswebsocket import obsws, requests # noqa: E402
import logging
functions = []
def current_scene(ws, args):
response = ws.call(requests.GetCurrentScene())
print(response.getName())
def is_streaming(ws, args):
resp = ws.call(requests.GetStreamingStatus())
if( resp.getStreaming() ):
print('yes')
exit(0)
else:
print('no')
exit(1)
def show_scenes(ws, args):
response = ws.call(requests.GetSceneList())
for s in response.getScenes():
print(s['name'])
exit(0)
def start_stream(ws, args):
response = ws.call(requests.GetStreamingStatus())
if not response.getStreaming():
ws.call(requests.StartStopStreaming())
def stop_stream(ws, args):
response = ws.call(requests.GetStreamingStatus())
if response.getStreaming():
ws.call(requests.StartStopStreaming())
def set_scene(ws, args):
if len(args) == 1:
response = ws.call(requests.GetSceneList())
for scene in response.getScenes():
if scene['name'] == args[0]:
ws.call(requests.SetCurrentScene(args[0]))
exit(0)
print("Secne({}) not Found!".format(args))
exit(1)
def set_camera(wc, args):
set_scene(ws, ["FullCamera"])
def set_slides(wc, args):
set_scene(ws, ["FullSlides"])
def set_mixed(wc, args):
set_scene(ws, ["MixedScene"])
with open(os.path.join(os.path.dirname(__file__), "config.yml"), 'r') as ymlfile:
cfg = yaml.load(ymlfile, Loader=yaml.SafeLoader)
logging.basicConfig(level=cfg['log_level'])
ws = obsws(cfg['host'], cfg['port'], cfg['password'])
ws.connect()
try:
num_args = len(sys.argv)
args = sys.argv
if num_args == 1:
#function = sys.argv.pop(0)
test='test'
else:
args.pop(0)
#function = sys.argv[1]
function = sys.argv.pop(0)
function = os.path.basename(function)
#print("{}({})".format(function, args))
if( function in locals() ):
locals()[function](ws, args)
else:
funcs = []
for key,item in locals().copy().items():
if str(item).startswith("<function"):
funcs.append(key)
funcs.sort()
#print(' '.join(funcs))
print("({}) function not found, the following are supported\n[{}]".format(function, ' '.join(funcs)))
exit(2)
except KeyboardInterrupt:
pass
ws.disconnect()