├── OBSRemoteParameters_StreamlabsParameter.py ├── UI_Config.json └── readme.txt /OBSRemoteParameters_StreamlabsParameter.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | """ OBS REMOTE PARAMETERS 5 | 6 | Parameter library to control OBS within current existing commands! 7 | 8 | Version 9 | 10 | 1.3.0 11 | $OBStimedSource now has an onoff or offon mode and $OBSscene now can accept an optional delay. 12 | All parameters now use threading in Python to execute actions. 13 | 1.2.0 14 | Added $OBStimedScene swap to a given scene for a set period of time, then swap to another given scene. 15 | Changed script name to _StreamlabsSystem to accomedate the change in the bot name. 16 | 1.1.0 17 | Added $OBStimedSource enabled a given source for a set period of time 18 | 1.0.0 19 | Initial release containing $OBSsource, $OBSscene and $OBSstop 20 | 21 | """ 22 | 23 | #--------------------------------------- 24 | # Import Libraries 25 | #--------------------------------------- 26 | import clr 27 | clr.AddReference("IronPython.Modules.dll") 28 | 29 | import os 30 | import json 31 | import re 32 | import time 33 | import threading 34 | 35 | #--------------------------------------- 36 | # Script Information 37 | #--------------------------------------- 38 | ScriptName = "OBS Studio Remote Parameters" 39 | Website = "http://www.twitch.tv/ocgineer" 40 | Description = "Parameter Library to control OBS Studio with the regular command system." 41 | Creator = "Ocgineer" 42 | Version = "1.3.0" 43 | 44 | #--------------------------------------- 45 | # Global Vars 46 | #--------------------------------------- 47 | ReadMeFile = os.path.join(os.path.dirname(__file__), "ReadMe.txt") 48 | RegObsScene = None 49 | RegObsSource = None 50 | RegObsTmdSrc = None 51 | RegObsTmdScn = None 52 | 53 | #--------------------------------------- 54 | # Functions 55 | #--------------------------------------- 56 | def OpenReadMe(): 57 | """ Open the script readme file in users default .txt application. """ 58 | os.startfile(ReadMeFile) 59 | return 60 | 61 | def CallbackLogger(response): 62 | """ Logs callback error response in scripts logger. """ 63 | parsedresponse = json.loads(response) 64 | if parsedresponse["status"] == "error": 65 | Parent.Log("OBS Remote", parsedresponse["error"]) 66 | return 67 | 68 | def ChangeToScene(scene, delay=None): 69 | """ Swaps to a given scene, optionally after given amount of seconds. """ 70 | if delay: 71 | time.sleep(delay) 72 | Parent.SetOBSCurrentScene(scene, CallbackLogger) 73 | return 74 | 75 | def SetSourceVisibility(source, enabled, scene=None): 76 | """ Set the targeted source visibility optionally in a scene. """ 77 | Parent.SetOBSSourceRender(source, enabled, scene, CallbackLogger) 78 | return 79 | 80 | def ChangeScenesTimed(scene_one, scene_two, delay): 81 | """ Swap to one scene then to another scene after a set delay. """ 82 | Parent.SetOBSCurrentScene(scene_one, CallbackLogger) 83 | if delay: 84 | time.sleep(delay) 85 | Parent.SetOBSCurrentScene(scene_two, CallbackLogger) 86 | return 87 | 88 | def VisibilitySourceTimed(source, mode, delay, scene): 89 | """ Disables a given source in optional scene after given amount of seconds. """ 90 | # off - delay - off 91 | if mode == "offon": 92 | Parent.SetOBSSourceRender(source, False, scene, CallbackLogger) 93 | if delay: 94 | time.sleep(delay) 95 | Parent.SetOBSSourceRender(source, True, scene, CallbackLogger) 96 | # on - delay - off 97 | else: 98 | Parent.SetOBSSourceRender(source, True, scene, CallbackLogger) 99 | if delay: 100 | time.sleep(delay) 101 | Parent.SetOBSSourceRender(source, False, scene, CallbackLogger) 102 | # done 103 | return 104 | 105 | #--------------------------------------- 106 | # Initialize data on load 107 | #--------------------------------------- 108 | def Init(): 109 | """ Initialize Script. """ 110 | 111 | # Globals 112 | global RegObsScene 113 | global RegObsSource 114 | global RegObsTmdSrc 115 | global RegObsTmdScn 116 | 117 | # Compile regexes in init 118 | RegObsScene = re.compile(r"(?:\$OBSscene\([\ ]*[\"\'](?P[^\"\']+)[\"\'][\ ]*(?:\,[\ ]*[\"\'](?P\d*)[\"\'][\ ]*)?\))", re.U) 119 | RegObsSource = re.compile(r"(?P\$OBSsource\([\ ]*[\"\'](?P[^\"\']+)[\"\'][\ ]*\,[\ ]*[\"\'](?P[^\"\']*)[\"\'][\ ]*(?:\,[\ ]*[\"\'](?P[^\"\']*)[\"\'][\ ]*)?\))", re.U) 120 | RegObsTmdScn = re.compile(r"(?P\$OBStimedScene\([\ ]*[\"\'](?P[^\"\']+)[\"\'][\ ]*\,[\ ]*[\"\'](?P[^\"\']+)[\"\'][\ ]*\,[\ ]*[\"\'](?P\d+)[\"\'][\ ]*\))", re.U) 121 | RegObsTmdSrc = re.compile(r"(?P\$OBStimedSource\([\ ]*[\"\'](?P[^\"\']+)[\"\'][\ ]*\,[\ ]*[\"\'](?Ponoff|offon)[\"\'][\ ]*\,[\ ]*[\"\'](?P\d+)[\"\'][\ ]*(?:\,[\ ]*[\"\'](?P[^\"\']*)[\"\'][\ ]*)?\))", re.U) 122 | 123 | # End of Init 124 | return 125 | 126 | #--------------------------------------- 127 | # Parse parameters 128 | #--------------------------------------- 129 | def Parse(parseString, user, target, message): 130 | """ Custom Parameter Parser. """ 131 | 132 | # $OBSscene("scene") parameter 133 | # $OBSscene("scene", "delay") parameter 134 | if "$OBSscene" in parseString: 135 | 136 | # Apply regex to verify correct parameter use 137 | result = RegObsScene.search(parseString) 138 | if result: 139 | 140 | # Get results from regex match 141 | fullParameterMatch = result.group(0) 142 | scene = result.group("scene") 143 | delay = int(result.group("delay")) if result.group("delay") else None 144 | 145 | # Change to another scene, using threading 146 | threading.Thread(target=ChangeToScene, args=(scene, delay)).start() 147 | 148 | # Replace the whole parameter with an empty string 149 | return parseString.replace(fullParameterMatch, "") 150 | 151 | # $OBSsource("source", "enabled") 152 | # $OBSsource("source", "enabled", "scene") 153 | if "$OBSsource" in parseString: 154 | 155 | # Apply regex to verify correct parameter use 156 | result = RegObsSource.search(parseString) 157 | if result: 158 | 159 | # Get match groups from regex 160 | fullParameterMatch = result.group(0) 161 | source = result.group("source") 162 | enabled = False if result.group("enabled").lower() == "false" else True 163 | scene = result.group("scene") if result.group("scene") else None 164 | 165 | # Set source visibility, using threading 166 | threading.Thread(target=SetSourceVisibility, args=(source, enabled, scene)).start() 167 | 168 | # Replace the whole parameter with an empty string 169 | return parseString.replace(fullParameterMatch, "") 170 | 171 | # #OBStimedScene("scene_one", "scene_two", "delay") 172 | if "$OBStimedScene" in parseString: 173 | 174 | # Apply regext to verify correct parameter use 175 | result = RegObsTmdScn.search(parseString) 176 | if result: 177 | 178 | # Get match groups from regex 179 | fullParameterMatch = result.group(0) 180 | scene1 = result.group("s1") 181 | scene2 = result.group("s2") 182 | delay = int(result.group("delay")) if result.group("delay") else None 183 | 184 | # Change to scene one, then to two after set delay, using threading 185 | threading.Thread(target=ChangeScenesTimed, args=(scene1, scene2, delay)).start() 186 | 187 | # Replace the whole parameter with an empty string 188 | return parseString.replace(fullParameterMatch, "") 189 | 190 | # $OBStimedSource("source", "mode", "delay") 191 | # $OBStimedSource("source", "mode", "delay", "scene") 192 | if "$OBStimedSource" in parseString: 193 | 194 | # Apply regex to verify correct parameter use 195 | result = RegObsTmdSrc.search(parseString) 196 | if result: 197 | 198 | # Get match groups from regex 199 | fullParameterMatch = result.group(0) 200 | source = result.group("source") 201 | mode = result.group("mode") 202 | delay = int(result.group("delay")) if result.group("delay") else None 203 | scene = result.group("scene") if result.group("scene") else None 204 | 205 | # Start a new thread to disable the source again after amount of given seconds 206 | threading.Thread(target=VisibilitySourceTimed, args=(source, mode, delay, scene)).start() 207 | 208 | # Replace the whole parameter with an empty string 209 | return parseString.replace(fullParameterMatch, "") 210 | 211 | # $OBSstop parameter 212 | if "$OBSstop" in parseString: 213 | 214 | # Call Stop streaming 215 | Parent.StopOBSStreaming(CallbackLogger) 216 | 217 | # Replace the whole parameter with an empty string 218 | return parseString.replace("$OBSstop", "") 219 | 220 | # Return unaltered parseString 221 | return parseString 222 | -------------------------------------------------------------------------------- /UI_Config.json: -------------------------------------------------------------------------------- 1 | { 2 | "button_readme": { 3 | "type": "button", 4 | "label": "Open ReadMe File", 5 | "tooltip": "Opens the readme of this script.", 6 | "function": "OpenReadMe", 7 | "wsevent": "", 8 | "group": "" 9 | } 10 | } -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- 1 | OBS STUDIO REMOTE CONTROL PARAMETER SCRIPT FOR STREAMLABS CHATBOT 2 | ############################################################################### 3 | 4 | To use the OBS Remote Parameters you first need to have OBS Websocket plugin installed to use in OBS. 5 | 6 | Download and install the latest version of the plugin here from GitHub; 7 | > https://github.com/Palakis/obs-websocket/releases 8 | 9 | After installing start OBS Studio, then a new option is available under 'Tools' in the menu bar. 10 | Open 'Websocket Server Settings' and check the Enable box and hit OK. Optionally you can set a password. 11 | 12 | Then go to Streamlabs Chatbot Connections (the avatar icon) > OBS Remote > Setup the same port and 13 | password (if any is set in the OBS plugin) and hit connect. 14 | 15 | # Few pointers; 16 | 17 | Streamlabs Chatbot will attemt to auto-connect to the OBS websocket on startup if OBS Studio 18 | is started and running before you start the bot. If you start OBS Studio after starting the 19 | bot you have to manually connect again. 20 | 21 | If the used parameter (see available parameters in ParameterHelp directory) is spit back out in 22 | the chat, that means the scripts parameter parser is not hooked/loaded in correctly. One can 23 | resolive this, by making sure it is enabled, then reload scripts and/or restart the bot. Or you 24 | have used the parameter incorrectly, make sure you check carefully over the use of the parameter! 25 | 26 | 27 | CHANGE TO SCENE WITH OPTIONAL DELAY 28 | =============================================================================== 29 | 30 | $OBSscene("") 31 | $OBSscene("", "") 32 | 33 | # Swap to a scene instantly or after a delay. 34 | 35 | 36 | 37 | The scene name to swap to. 38 | This is a required argument and cannot be empty. The name has to match the 39 | scene name in SLOBS and is therefore case sensitive. All characters can be 40 | used except names containing single (') or double (") quotes for this 41 | parameter. 42 | 43 | 44 | 45 | The delay in seconds before changing to the targeted scene. 46 | This is an optional argument but if given it needs to contain a valid 47 | number in seconds. 48 | 49 | 50 | SET VISIBILITY OF SOURCE IN ACTIVE OR TARGET SCENE 51 | =============================================================================== 52 | 53 | $OBSsource("", "") 54 | $OBSsource("", "", "") 55 | 56 | # Set the visibilty of a source in the current active or target scene. 57 | 58 | 59 | 60 | Name of the targeted source to set the visibility of. 61 | This is a required argument and cannot be empty. The name has to match the 62 | source name in OBS and is therefore case sensitive. All characters can be 63 | used except names containing single (') or double (") quotes for this 64 | parameter. 65 | 66 | 67 | 68 | Sets the visibility state of the targeted source [true|false]. 69 | This is a required argument and the targeted source will be set to *not* 70 | visible if this argument is set to `false`. Anything else, or `true` will 71 | set the targeted source to visible. 72 | 73 | 74 | 75 | Name of the targeted scene to set the targeted source visibility in. 76 | This is an optional argument but if given it needs to match the scene name 77 | in SLOBS and is case sensitive. All characters can be used execept names 78 | containing containing single (') or double (") quotes for this parameter. 79 | 80 | CHANGE TO SCENE THEN TO ANOTHER SCENE AFTER A SET DELAY 81 | =============================================================================== 82 | 83 | $OBStimedScene("", "", "") 84 | 85 | # Swap from one scene and back or another scene after a set time. 86 | 87 | 88 | 89 | The scene name to change to. 90 | This is a required argument and cannot be empty. The name has to match the 91 | scene name in SLOBS and is therefore case sensitive. All characters can be 92 | used except names containing single (') or double (") quotes for this 93 | parameter. 94 | 95 | 96 | 97 | The scene name to swap to after the delay elapsed. 98 | This is a required argument and cannot be empty. The name has to match the 99 | scene name in SLOBS and is therefore case sensitive. All characters can be 100 | used except names containing single (') or double (") quotes for this 101 | parameter. 102 | 103 | 104 | 105 | Time in seconds how long the targeted scene needs to be visible. 106 | This is a required argument and cannot be empty and needs to be a valid 107 | number to be used. 108 | 109 | 110 | SET VISIBILITY OF SOURCE IN ACTIVE OR TARGET SCENE TIMED ONOFF OR OFFON 111 | =============================================================================== 112 | 113 | $OBStimedSource("", "", "") 114 | $OBStimedSource("", "", "", "") 115 | 116 | # Set the visibilty of a source in the current active or target scene for a 117 | # set amount of time (delay) and then turns it to another state (mode). 118 | 119 | 120 | 121 | Name of the targeted source to set the visibility of. 122 | This is a required argument and cannot be empty. The name has to match the 123 | source name in OBS and is therefore case sensitive. All characters can be 124 | used except names containing single (') or double (") quotes for this 125 | parameter. 126 | 127 | 128 | 129 | Sets mode to use visible/hidden or hidden/visible. [onoff|offon] 130 | This is a required argument and the targeted source will turn on and then 131 | off after a delay (mode: onoff) or will turn off and then on again after a 132 | delay (mode: offon). 133 | 134 | 135 | 136 | Set the delay in seconds before hiding or showing the targeted source. 137 | This is a required argument and cannot be empty and needs to be a valid 138 | number to be used. 139 | 140 | 141 | 142 | Name of the targeted scene to set the targeted source visibility in. 143 | This is an optional argument but if given it needs to match the scene name 144 | in SLOBS and is case sensitive. All characters can be used execept names 145 | containing containing single (') or double (") quotes for this parameter. 146 | 147 | 148 | STOP STREAMING 149 | =============================================================================== 150 | 151 | $OBSstop 152 | 153 | No arugments required. Can be used for example for a trusted moderator to 154 | stop streaming in case of an emergency. --------------------------------------------------------------------------------