Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.IO
- Imports System.Text
- Imports OBSWebsocketDotNet
- Imports Newtonsoft.Json.Linq
- Module Main
- Private _obs As OBSWebsocket
- Sub Main()
- Dim args As String() = Environment.GetCommandLineArgs
- Dim password As String = ""
- Dim server As String = "ws://127.0.0.1:4444"
- Dim profile As String = ""
- Dim scene As String = ""
- Dim hidesource As String = ""
- Dim showsource As String = ""
- Dim togglesource As String = ""
- Dim toggleaudio As String = ""
- Dim mute As String = ""
- Dim unmute As String = ""
- Dim setvolume As String = ""
- Dim stopstream As Boolean = False
- Dim startstream As Boolean = False
- Dim startrecording As Boolean = False
- Dim stoprecording As Boolean = False
- If args.Count = 1 Then
- PrintUsage()
- End
- End If
- For Each arg As String In args
- If arg = "?" Or arg = "/?" Or arg = "-?" Or arg = "help" Or arg = "/help" Or arg = "-help" Then
- PrintUsage()
- End
- End If
- If arg.StartsWith("/server=") Then
- server = "ws://" & arg.Replace("/server=", "")
- End If
- If arg.StartsWith("/password=") Then
- password = arg.Replace("/password=", "")
- End If
- If arg.StartsWith("/profile=") Then
- profile = arg.Replace("/profile=", "")
- End If
- If arg.StartsWith("/scene=") Then
- scene = arg.Replace("/scene=", "")
- End If
- If arg.StartsWith("/hidesource=") Then
- hidesource = arg.Replace("/hidesource=", "")
- End If
- If arg.StartsWith("/showsource=") Then
- showsource = arg.Replace("/showsource=", "")
- End If
- If arg.StartsWith("/togglesource=") Then
- togglesource = arg.Replace("/togglesource=", "")
- End If
- If arg.StartsWith("/toggleaudio=") Then
- toggleaudio = arg.Replace("/toggleaudio=", "")
- End If
- If arg.StartsWith("/mute=") Then
- mute = arg.Replace("/mute=", "")
- End If
- If arg.StartsWith("/unmute=") Then
- unmute = arg.Replace("/unmute=", "")
- End If
- If arg.StartsWith("/setvolume=") Then
- setvolume = arg.Replace("/setvolume=", "")
- End If
- If arg = "/startstream" Then
- startstream = True
- End If
- If arg = "/stopstream" Then
- stopstream = True
- End If
- If arg = "/startrecording" Then
- startrecording = True
- End If
- If arg = "/stoprecording" Then
- stoprecording = True
- End If
- Next
- Dim myout As TextWriter = Console.Out
- Try
- Dim builder As StringBuilder = New StringBuilder()
- Dim writer As TextWriter = New StringWriter(builder)
- Console.SetOut(writer)
- _obs = New OBSWebsocket()
- _obs.WSTimeout = New TimeSpan(0, 0, 0, 3)
- _obs.Connect(server, password)
- If profile <> "" Then
- _obs.SetCurrentProfile(profile)
- End If
- If scene <> "" Then
- _obs.SetCurrentScene(scene)
- End If
- If hidesource <> "" Then
- If hidesource.Contains("/") Then
- Dim tmp As String() = hidesource.Split("/")
- ' scene/source
- If tmp.Count = 2 Then _obs.SetSourceRender(tmp(1), False, tmp(0))
- Else
- _obs.SetSourceRender(hidesource, False)
- End If
- End If
- If showsource <> "" Then
- If showsource.Contains("/") Then
- Dim tmp As String() = showsource.Split("/")
- ' scene/source
- If tmp.Count = 2 Then _obs.SetSourceRender(tmp(1), True, tmp(0))
- Else
- _obs.SetSourceRender(showsource, True)
- End If
- End If
- If togglesource <> "" Then
- If togglesource.Contains("/") Then
- Dim tmp As String() = togglesource.Split("/")
- ' scene/source
- If tmp.Count = 2 Then OBSToggleSource(tmp(1), tmp(0))
- Else
- OBSToggleSource(togglesource)
- End If
- End If
- If toggleaudio <> "" Then
- _obs.ToggleMute(toggleaudio)
- End If
- If mute <> "" Then
- _obs.SetMute(mute, True)
- End If
- If unmute <> "" Then
- _obs.SetMute(unmute, False)
- End If
- If setvolume <> "" Then
- ' source/volume,delay
- Dim tmp As String() = setvolume.Split(",")
- If Not IsNumeric(tmp(1)) Then Throw New Exception("Volume value is not nummeric (0-100)!")
- If tmp.Count = 2 Then
- OBSSetVolume(tmp(0), tmp(1))
- ElseIf tmp.Count = 3 Then
- If Not IsNumeric(tmp(2)) Then Throw New Exception("Delay value is not nummeric (0-x)!")
- OBSSetVolume(tmp(0), tmp(1), tmp(2))
- End If
- End If
- If startstream = True Then
- _obs.StartStreaming()
- End If
- If stopstream = True Then
- _obs.StopStreaming()
- End If
- If startrecording = True Then
- _obs.StartRecording()
- End If
- If stoprecording = True Then
- _obs.StopRecording()
- End If
- _obs.Disconnect()
- Console.SetOut(myout)
- Console.WriteLine("Ok")
- Catch ex As Exception
- Console.SetOut(myout)
- Console.WriteLine("Error: " & ex.Message.ToString())
- End Try
- End Sub
- Private Sub OBSToggleSource(ByVal source As String, Optional ByVal sceneName As String = "")
- Dim _obsScene As OBSScene
- Dim obsSettings As SourceSettings
- If sceneName = "" Then
- _obsScene = _obs.GetCurrentScene()
- sceneName = _obsScene.Name
- End If
- obsSettings = _obs.GetSourceSettings(sceneName)
- Dim counter As Integer = 0
- For Each item As JProperty In obsSettings.sourceSettings
- Debug.WriteLine(item)
- If item.Name = "id_counter" Then
- counter = item.Value
- Continue For
- End If
- Dim found As Boolean = False
- Dim wrongname As Boolean = False
- For Each child As JToken In item.Children.Children
- For Each _item As JProperty In child
- 'Debug.WriteLine(_item.ToString())
- If _item.Name.ToString() = "name" Then
- If _item.Value.ToString() <> source Then
- wrongname = True
- End If
- found = True
- End If
- If wrongname = True Then
- wrongname = False
- Exit For
- End If
- If found = False Then Continue For
- If _item.Name.ToString() = "visible" Then
- If _item.Value.ToString() = "True" Then
- Debug.WriteLine(sceneName & "/" & source & " is visible")
- _obs.SetSourceRender(source, False, sceneName)
- Else
- Debug.WriteLine(sceneName & "/" & source & " is not visible")
- _obs.SetSourceRender(source, True, sceneName)
- End If
- End If
- Next
- Next
- Next
- End Sub
- Private Sub OBSSetVolume(ByVal source As String, ByVal volume As Integer, Optional ByVal delay As Integer = 0)
- If delay = 0 Then
- _obs.SetVolume(source, volume / 100)
- Else
- If delay > 10 Then delay = 10
- If delay > 1000 Then delay = 1000
- Dim _VolumeInfo As VolumeInfo = _obs.GetVolume(source)
- Dim startvolume As Integer = _VolumeInfo.Volume * 100
- If startvolume = volume Then
- Exit Sub
- ElseIf startvolume < volume Then
- For a = startvolume To volume
- _obs.SetVolume(source, (a / 100))
- Threading.Thread.Sleep(delay)
- Next
- ElseIf startvolume > volume Then
- For a = startvolume To volume Step -1
- _obs.SetVolume(source, (a / 100))
- Threading.Thread.Sleep(delay)
- Next
- End If
- End If
- End Sub
- Private Sub PrintUsage()
- Dim out As List(Of String) = New List(Of String)
- out.Add("OBSCommand v1.3 ©2018 by FSC-SOFT (http://www.VoiceMacro.net)")
- out.Add(vbCrLf)
- out.Add("Usage:")
- out.Add("------")
- out.Add("OBSCommand.exe /server=127.0.0.1:4444 /password=xxxx /profile=myprofile /scene=myscene /hidesource=myscene/mysource /showsource=myscene/mysource /toggleaudio=myaudio /mute=myaudio /unmute=myaudio /setvolume=mysource,volume,delay /startstream /stopstream /startrecording /stoprecording")
- out.Add(vbCrLf)
- out.Add("Note: If Server is omitted, default 127.0.0.1:4444 will be used.")
- out.Add("Use quotes if your item name includes spaces.")
- out.Add("Password can be empty if no password is set in OBS Studio.")
- out.Add(vbCrLf)
- out.Add("This tool uses the obs-websocket plugin to talk to OBS Studio:")
- out.Add("https://github.com/Palakis/obs-websocket/releases")
- out.Add(vbCrLf)
- out.Add("Dynamic link libraries used:")
- out.Add("Json.NET ©2008 by James Newton-King")
- out.Add("websocket-sharp ©2010-2016 by sta.blockhead")
- out.Add("obs-websocket-dotnet ©2017 by Stéphane Lepin.")
- out.Add(vbCrLf)
- out.Add("Examples:")
- out.Add("---------")
- out.Add("OBSCommand.exe /scene=myscene")
- out.Add("OBSCommand.exe /toggleaudio=""Desktop Audio""")
- out.Add("OBSCommand.exe /mute=myAudioSource")
- out.Add("OBSCommand.exe /unmute=""my Audio Source""")
- out.Add("OBSCommand.exe /setvolume=Mic/Aux,0,50")
- out.Add("OBSCommand.exe /setvolume=Mic/Aux,100")
- out.Add("OBSCommand.exe /stopstream")
- out.Add("OBSCommand.exe /profile=myprofile /scene=myscene /showsource=mysource")
- out.Add("OBSCommand.exe /showsource=mysource")
- out.Add("OBSCommand.exe /hidesource=myscene/mysource")
- out.Add("OBSCommand.exe /showsource=""my scene""/""my source""")
- out.Add(vbCrLf)
- out.Add("Options:")
- out.Add("--------")
- out.Add("/server=127.0.0.1:4444 define server address and port")
- out.Add(" Note: If Server is omitted, default 127.0.0.1:4444 will be used.")
- out.Add("/password=xxxx define password (can be omitted)")
- out.Add("/profile=myprofile switch to profile ""myprofile""")
- out.Add("/scene=myscene switch to scene ""myscene""")
- out.Add("/hidesource=myscene/mysource hide source ""scene/mysource""")
- out.Add("/showsource=myscene/mysource show source ""scene/mysource""")
- out.Add(" Note: if scene is omitted, current scene is used")
- out.Add("/toggleaudio=myaudio toggle mute from audio source ""myaudio""")
- out.Add("/mute=myaudio mute audio source ""myaudio""")
- out.Add("/unmute=myaudio unmute audio source ""myaudio""")
- out.Add("/setvolume=myaudio,volume,delay set volume of audio source ""myaudio""")
- out.Add(" volume is 0-100, delay is in milliseconds")
- out.Add(" between steps (min. 10, max. 1000) for fading")
- out.Add(" Note: if delay is omitted volume is set instant")
- out.Add("/startstream starts streaming")
- out.Add("/stopstream stop streaming")
- out.Add("/startrecording starts recording")
- out.Add("/stoprecording stops recording")
- out.Add("")
- Dim i As Integer = 0
- Dim z As Integer = 0
- Do While True
- Console.WriteLine(out(i))
- If z = Console.WindowHeight - 6 Then
- Console.Write("Press any key to continue...")
- Console.ReadKey()
- ClearCurrentConsoleLine()
- z = 0
- End If
- i += 1
- z += 1
- If i >= out.Count Then Exit Do
- If out(i).Length > Console.WindowWidth Then
- z += 1
- End If
- If out(i).Length > Console.WindowWidth * 2 Then
- z += 1
- End If
- Loop
- End Sub
- Public Sub ClearCurrentConsoleLine()
- Dim currentLineCursor As Integer = Console.CursorTop
- Console.SetCursorPosition(0, Console.CursorTop)
- Console.Write(New String(" "c, Console.WindowWidth))
- Console.SetCursorPosition(0, currentLineCursor)
- End Sub
- End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement