diff --git a/OBSRemoteParameters_StreamlabsParameter.py b/OBSRemoteParameters_StreamlabsParameter.py index 6b3f13e..402a6bd 100644 --- a/OBSRemoteParameters_StreamlabsParameter.py +++ b/OBSRemoteParameters_StreamlabsParameter.py @@ -7,12 +7,14 @@ Version + 1.4.0 + Added $OBSsetVolume set volume for given source, 1-100 1.3.0 $OBStimedSource now has an onoff or offon mode and $OBSscene now can accept an optional delay. All parameters now use threading in Python to execute actions. 1.2.0 Added $OBStimedScene swap to a given scene for a set period of time, then swap to another given scene. - Changed script name to _StreamlabsSystem to accomedate the change in the bot name. + Changed script name to _StreamlabsParameter to accomedate the change in the bot name. 1.1.0 Added $OBStimedSource enabled a given source for a set period of time 1.0.0 @@ -39,7 +41,7 @@ Website = "http://www.twitch.tv/ocgineer" Description = "Parameter Library to control OBS Studio with the regular command system." Creator = "Ocgineer" -Version = "1.3.0" +Version = "1.4.0" #--------------------------------------- # Global Vars @@ -49,6 +51,7 @@ RegObsSource = None RegObsTmdSrc = None RegObsTmdScn = None +RegObsAudioVolume = None #--------------------------------------- # Functions @@ -85,6 +88,14 @@ def ChangeScenesTimed(scene_one, scene_two, delay): Parent.SetOBSCurrentScene(scene_two, CallbackLogger) return +def SetAudioSourceVolume(source, volume): + """ Set the targeted source to the volume """ + #clip numbers at 100 + output = 100 if (int(volume) > 100) else volume + #Volume function expects value between 0-1, divide by 100 for convenience of using whole numbers in chat commands + Parent.SetOBSVolume(source, float(output)/100, CallbackLogger) + return + def VisibilitySourceTimed(source, mode, delay, scene): """ Disables a given source in optional scene after given amount of seconds. """ # off - delay - off @@ -113,12 +124,14 @@ def Init(): global RegObsSource global RegObsTmdSrc global RegObsTmdScn - + global RegObsAudioVolume + # Compile regexes in init RegObsScene = re.compile(r"(?:\$OBSscene\([\ ]*[\"\'](?P[^\"\']+)[\"\'][\ ]*(?:\,[\ ]*[\"\'](?P\d*)[\"\'][\ ]*)?\))", re.U) RegObsSource = re.compile(r"(?P\$OBSsource\([\ ]*[\"\'](?P[^\"\']+)[\"\'][\ ]*\,[\ ]*[\"\'](?P[^\"\']*)[\"\'][\ ]*(?:\,[\ ]*[\"\'](?P[^\"\']*)[\"\'][\ ]*)?\))", re.U) RegObsTmdScn = re.compile(r"(?P\$OBStimedScene\([\ ]*[\"\'](?P[^\"\']+)[\"\'][\ ]*\,[\ ]*[\"\'](?P[^\"\']+)[\"\'][\ ]*\,[\ ]*[\"\'](?P\d+)[\"\'][\ ]*\))", re.U) RegObsTmdSrc = re.compile(r"(?P\$OBStimedSource\([\ ]*[\"\'](?P[^\"\']+)[\"\'][\ ]*\,[\ ]*[\"\'](?Ponoff|offon)[\"\'][\ ]*\,[\ ]*[\"\'](?P\d+)[\"\'][\ ]*(?:\,[\ ]*[\"\'](?P[^\"\']*)[\"\'][\ ]*)?\))", re.U) + RegObsAudioVolume = re.compile(r"(?P\$OBSvolumeSet\([\ ]*[\"\'](?P[^\"\']+)[\"\'][\ ]*(?:\,[\ ]*[\"\'](?P\d*)[\"\'][\ ]*)?\))", re.U) # End of Init return @@ -135,7 +148,7 @@ def Parse(parseString, user, target, message): # Apply regex to verify correct parameter use result = RegObsScene.search(parseString) - if result: + if result: # Get results from regex match fullParameterMatch = result.group(0) @@ -163,7 +176,7 @@ def Parse(parseString, user, target, message): scene = result.group("scene") if result.group("scene") else None # Set source visibility, using threading - threading.Thread(target=SetSourceVisibility, args=(source, enabled, scene)).start() + threading.Thread(target=SetSourceVisibility, args=(source, enabled, scene)).start() # Replace the whole parameter with an empty string return parseString.replace(fullParameterMatch, "") @@ -208,6 +221,22 @@ def Parse(parseString, user, target, message): # Replace the whole parameter with an empty string return parseString.replace(fullParameterMatch, "") + # $OBSvolumeSet("source", "volume") + if "$OBSvolumeSet" in parseString: + + # Apply regex to verify correct parameter use + result = RegObsAudioVolume.search(parseString) + if result: + + # Get match groups from regex + fullParameterMatch = result.group(0) + source = result.group("source") + volume = result.group("volume") + # Set source visibility, using threading + threading.Thread(target=SetAudioSourceVolume, args=(source, volume)).start() + # Replace the whole parameter with an empty string + return parseString.replace(fullParameterMatch, "") + # $OBSstop parameter if "$OBSstop" in parseString: diff --git a/readme.txt b/readme.txt index 6271730..766f3a0 100644 --- a/readme.txt +++ b/readme.txt @@ -145,10 +145,32 @@ $OBStimedSource("", "", "", "") containing containing single (') or double (") quotes for this parameter. +SET VOLUME OF SOURCE +=============================================================================== + +$OBSvolumeSet("", "") + + # Set the current volume for a given source. + + + + Name of the targeted source to set the visibility of. + This is a required argument and cannot be empty. The name has to match the + source name in OBS and is therefore case sensitive. All characters can be + used except names containing single (') or double (") quotes for this + parameter. + + + + Set the volume on values from 0-100. + This is a required argument and cannot be empty and needs to be a valid + number to be used. + + STOP STREAMING =============================================================================== $OBSstop No arugments required. Can be used for example for a trusted moderator to - stop streaming in case of an emergency. \ No newline at end of file + stop streaming in case of an emergency.