-
Notifications
You must be signed in to change notification settings - Fork 13
/
chat-votes-camera.py
84 lines (65 loc) · 2.96 KB
/
chat-votes-camera.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
# OBS-Studio python scripts
# Copyright (C) 2018-2019 IBM
# Copyright (C) 2018-2019 Jim and the OBS authors
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# chat-votes-camera.py
# This script fetches the name of an OBS scene from a remote server. If the
# name matches a scene in the current configuration, OBS switches to that
# scene. The intention is for the chat to vote twitch-plays-pokemon style on
# which view of they want, and automation shows them that view. This seems
# primarily useful for creative streamers.
import urllib.request
import urllib.error
import obspython as obs
import json
url = ""
# ------------------------------------------------------------
def update():
global url
try:
with urllib.request.urlopen(url) as response:
data = response.read()
response = json.loads(data)
_scenes = zip(obs.obs_frontend_get_scene_names(),
obs.obs_frontend_get_scenes())
scenes = {}
for scene in _scenes:
scenes[scene[0]] = scene[1]
if scenes.get(response['camera']) is not None:
print("Switching to scene: " + response['camera'])
obs.obs_frontend_set_current_scene(scenes[response['camera']])
except urllib.error.URLError as err:
obs.script_log(obs.LOG_WARNING,
"Error opening URL '" + url + "': " + err.reason)
obs.remove_current_callback()
# ------------------------------------------------------------
def script_properties():
"""
Called to define user properties associated with the script. These
properties are used to define how to show settings properties to a user.
"""
props = obs.obs_properties_create()
obs.obs_properties_add_text(props, "url", "URL", obs.OBS_TEXT_DEFAULT)
obs.obs_properties_add_text(props, "secret", "secret",
obs.OBS_TEXT_DEFAULT)
obs.obs_properties_add_int(props, "cycle_rate", "Cycle Rate(ms)",
1000, 1000000, 1000)
return props
def script_update(settings):
"""
Called when the script’s settings (if any) have been changed by the user.
"""
global url
obs.timer_remove(update)
blink_rate = obs.obs_data_get_int(settings, "cycle_rate")
obs.timer_add(update, blink_rate) # Change scene every cycle_rate ms
url = obs.obs_data_get_string(settings, "url")