Modules
obs_sd_controls.cli_entry
This is the main entry point for the command line tools, performing routing and higher level functions that need to stitch multiple elements together
- obs_sd_controls.cli_entry.live_safety_button(config, ws_password)
Sadly, people are performing “hate raids” on twitch, raiding channels and getting bot accounts to follow the streamer and spam chat with hateful messages.
The follows will cause sound alert overlays to queue up notifications, so this function will disable and re-enable those overlays as configured in the ini file. Additionally, chat safety features can be enabled
- Parameters
config (ConfigParser) – ConfigParser object created in cli_tools
ws_password (str) – The password for the OBS WebSockets server
- obs_sd_controls.cli_entry.main()
Entry point for the console script ‘obs-streamdeck-ctl’
- obs_sd_controls.cli_entry.start_stop(config, ws_password)
Start/Stop streaming in OBS and if twitch chat safety features have been enabled switch those as well
- Parameters
config (ConfigParser) – Config details loaded by ConfigParser
ws_password (str) – The password for the OBS WebSockets server
obs_sd_controls.config_mgmt
This contains all of the functions for managing the local config file, including running the Tk setup wizard to create and modify the config file.
- class obs_sd_controls.config_mgmt.AdditionalSafetyOptions(parent, controller, name='')
A Page to collect additional options for the Live Safety function.
- Parameters
parent (tk.Frame) – The parent frame to attach this frame to
controller (tk.Tk) – The main application GUI
name (str) – The name for the frame widget
- Variables
controller – The main application GUI
top_frame – The header frame
middle_frame – The main frame for the wizard pages
bottom_frame – The navigation frame
- load_additional()
If there are additional safety options update the form with those values
- update_additional()
Update the config with the additional Live Safety options, then show the final screen
- class obs_sd_controls.config_mgmt.ExistingConfig(parent, controller, name='')
A Page to confirm if the user is happy to edit their already existing config, as determined after the Welcome page
- Parameters
parent (tk.Frame) – The parent frame to attach this frame to
controller (tk.Tk) – The main application GUI
name (str) – The name for the frame widget
- Variables
controller – The main application GUI
top_frame – The header frame
middle_frame – The main frame for the wizard pages
bottom_frame – The navigation frame
- class obs_sd_controls.config_mgmt.LaunchTwitch(parent, controller, name='')
A Page to launch Twitch Authorisation in a web browser and handle the return with a small web server.
- Parameters
parent (tk.Frame) – The parent frame to attach this frame to
controller (tk.Tk) – The main application GUI
name (str) – The name for the frame widget
- Variables
controller – The main application GUI
top_frame – The header frame
middle_frame – The main frame for the wizard pages
bottom_frame – The navigation frame
- launch_browser()
Disable the Next button, launch the user’s web browser and take them to the Twitch OAuth page. Start a web server to listen for the response
- load_channel()
If there is an existing channel, return that value.
- Returns
The existing channel
- Return type
str
- return_from_web_server(return_object)
Receive the Twitch object from the web server and update the config. Take user to the next frame
- Parameters
return_object (dict) – The JSON object returned from the thanks.js file
- start_web_server()
Start a web server using the custom response handler which will have a reference to the controller app to return the values from twitch.
- class obs_sd_controls.config_mgmt.LiveSafetyOptions(parent, controller, name='')
A Page to select the Live Safety options.
- Parameters
parent (tk.Frame) – The parent frame to attach this frame to
controller (tk.Tk) – The main application GUI
name (str) – The name for the frame widget
- Variables
controller – The main application GUI
top_frame – The header frame
middle_frame – The main frame for the wizard pages
bottom_frame – The navigation frame
safety_check_value – A Tkinter BooleanVar for safety pages
emote_option – A Tkinter BooleanVar for safety pages
safety_option – A Tkinter StringVar for safety pages
follow_time – A Tkinter StringVar for safety pages
- update_safety()
Update th2 config for the Live Safety features, then show the next screen
- class obs_sd_controls.config_mgmt.ObsAlertSources(parent, controller, name='')
A Page to determine the Notification and chat sources in OBS that would be disabled in the Live Safety functions.
- Parameters
parent (tk.Frame) – The parent frame to attach this frame to
controller (tk.Tk) – The main application GUI
name (str) – The name for the frame widget
- Variables
controller – The main application GUI
top_frame – The header frame
middle_frame – The main frame for the wizard pages
bottom_frame – The navigation frame
- get_source_url(source)
Connect to OBS to get the URL for the supplied source
- load_default_alert_sources()
If there are existing alert sources configured, add them to the listbox
- load_obs_sources(obs_sources)
Load the OBS Sources from the previous frame into the Listbox
- remove_alert_source()
Move sources from the list of config Sources to the list of OBS sources
- select_alert_source()
Move sources from the list of OBS Sources to the list of config sources
- update_sources()
Get the updated values from the Alert sources Listbox and add them to the config. Then save the config and move to the twitch stage
- class obs_sd_controls.config_mgmt.ObsAudioSources(parent, controller, name='')
A Page to determine the Microphone and Desktop Audio sources in OBS.
- Parameters
parent (tk.Frame) – The parent frame to attach this frame to
controller (tk.Tk) – The main application GUI
name (str) – The name for the frame widget
- Variables
controller – The main application GUI
top_frame – The header frame
middle_frame – The main frame for the wizard pages
bottom_frame – The navigation frame
- load_desktop_source()
If there is an existing Desktop source, return that value. Otherwise return the default
- Returns
The existing password
- Return type
str
- load_mic_source()
If there is an existing Mic source, return that value, otherwise return the default
- Returns
The existing password
- Return type
str
- load_obs_sources(obs_sources)
Load the OBS Sources from the previous frame into the Listbox
- select_desktop_source()
Move a source from the Listbox to the Desktop Entry widget
- select_mic_source()
Move a source from the Listbox to the Microphone Entry widget
- update_sources()
Get the updated value from the entry box and update the config before moving onto the next frame
- class obs_sd_controls.config_mgmt.ObsWsPass(parent, controller, name='')
A Page to determine the password for the OBS WebSockets server, if any.
- Parameters
parent (tk.Frame) – The parent frame to attach this frame to
controller (tk.Tk) – The main application GUI
name (str) – The name for the frame widget
- Variables
controller – The main application GUI
top_frame – The header frame
middle_frame – The main frame for the wizard pages
bottom_frame – The navigation frame
- get_obs_sources()
Load the OBS Source list from the OBS WebSockets interface, raising an alert if we’re unable to connect. Then pass that list to the next frame to load into its Listbox before showing the next frame
- load_password()
If there is an existing password, return that value.
- Returns
The existing password
- Return type
str
- update_password()
Get the updated value from the entry box and update the config. Before showing the next frame, load the sources from OBS
- class obs_sd_controls.config_mgmt.SafetyOptions(parent, controller, name='', headers=(), footers=())
Create an intermediary class, since the next two setup pages are essentially the same
- Parameters
parent (tk.Frame) – The parent frame to attach this frame to
controller (tk.Tk) – The main application GUI
name (str) – The name for the frame widget
- Variables
controller – The main application GUI
top_frame – The header frame
middle_frame – The main frame for the wizard pages
bottom_frame – The navigation frame
safety_check_value – A Tkinter BooleanVar for safety pages
emote_option – A Tkinter BooleanVar for safety pages
safety_option – A Tkinter StringVar for safety pages
follow_time – A Tkinter StringVar for safety pages
- load_safety(section_name)
If there are existing safety options, update the form to reflect them
- Parameters
section_name (str) –
- safety_check_changed()
Enable or disable the safety options when the checkbox is selected
- safety_radio_change()
Enable or disable the additional follower option when the radio options are selected
- update_safety(section_name, next_frame)
Get the updated values from the form and update the config. Then show the next frame
- Parameters
section_name (str) – The name for the config section
next_frame (str) – The name of the next frame to load after updating the config
- class obs_sd_controls.config_mgmt.SetupApp(config)
The main Tkinter GUI for the config setup wizard
- Parameters
config (ConfigParser) – The ConfigParser object that was loaded from config_mgmt.load_config
- Variables
obs_config – The stored ConfigParser object
- clear_busy()
Set the cursor back to normal
- load_frames(container)
Loop through the frames defined in this module, create them and add them to the returned dictionary
- Parameters
container – The main application container frame that all frames wil be attached to
- Type
tk.Frame
- Returns
A dictionary of frame names and the objects created
- Return type
dict
- show_busy()
Change the cursor to ‘watch’ to reflect waiting on a background operation
- show_frame(page_name)
Bring the requested frame to the foreground
- Parameters
page_name (str) – The name of the frame to bring forward
- class obs_sd_controls.config_mgmt.SetupComplete(parent, controller, name='')
The final page of the setup wizard..
- Parameters
parent (tk.Frame) – The parent frame to attach this frame to
controller (tk.Tk) – The main application GUI
name (str) – The name for the frame widget
- Variables
controller – The main application GUI
top_frame – The header frame
middle_frame – The main frame for the wizard pages
bottom_frame – The navigation frame
- complete()
Save the config to the local file and quit the setup wizard
- class obs_sd_controls.config_mgmt.SetupPage(parent, controller, name='', headers=(), footers=())
A superclass frame that should not be called directly, but instead manages the split between the main wizard, the header, and the navigation sections below.
- Parameters
parent (tk.Frame) – The parent frame to attach this frame to
controller (tk.Tk) – The main application GUI
name (str) – The name to refer to this frame
headers (tuple) – A pair of text strings in a tuple (HEADING, HEADING_TEXT), to provide to the top frame
footers – A tuple of arguments to pass to the _setup_footer method
- Variables
controller – The main application GUI
top_frame – The header frame
middle_frame – The main frame for the wizard pages
bottom_frame – The navigation frame
- enable_disable_widgets(test, widgets, target_frame='middle_frame')
Enable or Disable a set of widgets based on a truthiness test
- Parameters
test – The statement to evaluate for truthiness
test – Bool
widgets (tuple) – A list or tuple of widgets to enable or disable
target_frame (str) – the name of the target frame where the widgets are
- get_list_frame_lbx(name, target_frame='middle_frame')
Return the listbox widget that was created in a frame.
- Parameters
name (str) – The name of the listbox/frame widget created earlier
target_frame (str) – The name of the frame that contains the listbox/frame
- Returns
The listbox widget
- Return type
tk.Listbox
- static list_to_entry(list_widget, entry_widget)
Swap the selected entry in a Listbox widget with the value in an Entry widget
- Parameters
list_widget (tk.Listbox) – The Listbox widget
entry_widget (tk.Entry) – The Entry widget
- static list_to_list(list_a, list_b)
Move selected items from list_a to list_b
- Parameters
list_a (tk.Listbox) – The listbox widget to move items from
list_b (tk.Listbox) – The listbox widget to move items to
- setup_list_frame(header='', name='', select_mode='single')
Create a frame for a list box with a scroll bar to be added to the top frame. Weighting of the outer grid sections is not completed in this function, and should be completed after the other components have been laid out
- Parameters
header (str) – Header text for the frame
name (str) – The name to give to the listbox
select_mode (str) – Value for select_mode for the Listbox widget
- Returns
The frame
- Return type
tk.Frame
- class obs_sd_controls.config_mgmt.StartStopOptions(parent, controller, name='')
A Page to select the Start/Stop safety options.
- Parameters
parent (tk.Frame) – The parent frame to attach this frame to
controller (tk.Tk) – The main application GUI
name (str) – The name for the frame widget
- Variables
controller – The main application GUI
top_frame – The header frame
middle_frame – The main frame for the wizard pages
bottom_frame – The navigation frame
safety_check_value – A Tkinter BooleanVar for safety pages
emote_option – A Tkinter BooleanVar for safety pages
safety_option – A Tkinter StringVar for safety pages
follow_time – A Tkinter StringVar for safety pages
- update_safety()
Update the config for the Start/Stop safety features, then show the next screen
- class obs_sd_controls.config_mgmt.TwitchResponseHandler(controller, *args, **kwargs)
Local web server handler to handle the return request from the Twitch authentication portal. Normally the __init__ method would not be overridden but we need to reference the Setup Wizard application stored in the object to change frames when complete
- Parameters
controller (tk.Tk) – A reference to the main TK application
*args – List of arguments accepted by BaseHTTPRequestHandler
**kwargs – Dictionary of keyword arguments accepted by BaseHTTPRequestHandler
- do_GET()
GET only serves 2 files, thanks.html and thanks.js. As the twitch response is in the document hash, it’s easier to get through Javascript
- do_POST()
Receive the Twitch tokens via a POST from thanks.js. Update the original setup app with the values received and shut down the web server
- class obs_sd_controls.config_mgmt.WelcomePage(parent, controller, name='')
Introduction page for the Setup Wizard
- Parameters
parent (tk.Frame) – The parent frame to attach this frame to
controller (tk.Tk) – The main application GUI
name (str) – The name for the frame widget
- Variables
controller – The main application GUI
top_frame – The header frame
middle_frame – The main frame for the wizard pages
bottom_frame – The navigation frame
- check_existing()
Check the controller to see if the loaded config file had valid sections. If it did redirect the user to a confirmation page about changing existing configs, otherwise step past to the OBS WebSockets Password configuration
- static get_obsws()
Open a new web browser tab and load the github release page for the latest release of OBS WebSockets server
- obs_sd_controls.config_mgmt.load_config()
Load the config file and return the ConfigParser object
- Returns
the ConfigParser object
- Return type
ConfigParser
- obs_sd_controls.config_mgmt.save_config(config)
Save the config file to the user’s local config directory.
- Parameters
config (ConfigParser) – The ConfigParser object
obs_sd_controls.obs_controls
This contains all of the functions for controlling OBS via the OBS WebSockets library
- obs_sd_controls.obs_controls.get_all_sources(ws_password)
Get a list of all sources currently configured in OBS
- Parameters
ws_password (str) – The password for the OBS WebSockets server
- Returns
A list of sources
- Return type
list
- obs_sd_controls.obs_controls.get_source_settings(source, ws_password)
Get the current settings for an OBS Source
- Parameters
source (str) – The name of the OBS source
ws_password (str) – The password for the OBS WebSockets server
- Returns
The current settings for the OBS source
- Return type
dict
- obs_sd_controls.obs_controls.mute_audio_source(source, ws_password)
Mute/Unmute the Microphone audio source as configured in sd_controls.ini
- Parameters
source (str) – the audio source to mute
ws_password (str) – The password for the OBS WebSockets server
- obs_sd_controls.obs_controls.set_scene(scene_number, ws_password)
Set the active scene in OBS using the number of the scene as counted from the top down of the scene list in OBS
- Parameters
scene_number (int) – The scene number to make active
ws_password (str) – The password for the OBS WebSockets server
- obs_sd_controls.obs_controls.set_source_settings(source, settings, ws_password)
Apply new settings for the selected source
- Parameters
source (str) – The name of the OBS source
settings (dict) – The updated settings to apply to the source in the same format as the sourceSettings section returned from get_source_settings
ws_password (str) – The password for the OBS WebSockets server
- obs_sd_controls.obs_controls.start_stop_stream(ws_password)
Start/Stop the stream
- Parameters
ws_password (str) – The password for the OBS WebSockets server
obs_sd_controls.twitch_controls
This contains all of the functions for controlling Twitch chat via a chat bot
- class obs_sd_controls.twitch_controls.TwitchLiveSafetyBot(nickname, token, enabled, emote_mode, method, follow_time, advert, clear_chat)
A simple bot that logs into the twitch user’s own channel to run a batch of commands before logging out again. This bot is for use during live streams.
- Parameters
nickname (str) – The user’s twitch logon
token (str) – The user’s OAUTH token
enabled (bool) – If this safety mode is enabled
emote_mode (bool) – If Emote Only chat is part of the requested safety mode
method (str) – The preferred chat lockdown method
follow_time (str) – If the lockdown method is Followers only, the length of follow time allowed before a user can chat
advert (bool) – If a 1m advert should currently be played
marker (bool) – If a marker should be placed
- Variables
channel – The user’s chat channel
enabled – If this safety mode is enabled
emote_mode – If Emote Only chat is part of the requested safety mode
method – The preferred chat lockdown method
follow_time – If the lockdown method is Followers only, the length of follow time allowed before a user can chat
advert – If a 1m advert should currently be played
marker – If a marker should be placed
- on_roomstate(connection, event)
Override the parent event handler to run the live related features before the chat modes.
- class obs_sd_controls.twitch_controls.TwitchSafetyBot(nickname, token, enabled, emote_mode, method, follow_time)
A simple bot that logs into the twitch user’s own channel to run a batch of commands before logging out again.
- Parameters
nickname (str) – The user’s twitch logon
token (str) – The user’s OAUTH token
enabled (bool) – If this safety mode is enabled
emote_mode (bool) – If Emote Only chat is part of the requested safety mode
method (str) – The preferred chat lockdown method
follow_time (str) – If the lockdown method is Followers only, the length of follow time allowed before a user can chat
- Variables
VERSION – IRC Bot Version
channel – The user’s chat channel
enabled – If this safety mode is enabled
emote_mode – If Emote Only chat is part of the requested safety mode
method – The preferred chat lockdown method
follow_time – If the lockdown method is Followers only, the length of follow time allowed before a user can chat
- on_roomstate(connection, event)
After receiving the ROOMSTATE tags from Twitch IRC, toggle between the requested safety modes before gracefully logging out of IRC
- on_welcome(connection, event)
Event handler to make sure the extra twitch capabilities are requested and to join the user’s channel