Last active
January 28, 2022 13:46
-
-
Save musantro/96194f4305981169f89614d62b69f45b to your computer and use it in GitHub Desktop.
OBS Script to automatically change scene in iRacing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Author: Antonio Rodríguez (@musantro) | |
# Date: 2022-01-28 | |
# This code is licensed under the terms of the MIT license | |
import obspython as obs | |
import irsdk | |
interval = 3 | |
on_track_scene_prop = "" | |
off_track_scene_prop = "" | |
ir = irsdk.IRSDK() | |
def script_description(): | |
return "Updates the scene whether the streamer is on Track at iRacing or not" | |
def script_update(settings): | |
global interval | |
global on_track_scene_prop | |
global off_track_scene_prop | |
on_track_scene_prop = obs.obs_data_get_string(settings, "on_track_scene_prop") | |
off_track_scene_prop = obs.obs_data_get_string(settings, "off_track_scene_prop") | |
obs.timer_remove(update_scene) | |
obs.timer_add(update_scene, interval * 1000) | |
def update_scene(): | |
global on_track_scene_prop | |
global off_track_scene_prop | |
global ir | |
scenes = obs.obs_frontend_get_scenes() | |
current_scene = obs.obs_frontend_get_current_scene() | |
track_scenes = { | |
True: on_track_scene_prop, | |
False: off_track_scene_prop | |
} | |
if on_track_scene_prop != "" and off_track_scene_prop != "" and ir.startup() \ | |
and ir.is_initialized and ir.is_connected: | |
current_scene_name = obs.obs_source_get_name(current_scene) | |
if track_scenes[ir['IsOnTrack']] != current_scene_name: | |
for scene in scenes: | |
name_scene = obs.obs_source_get_name(scene) | |
if track_scenes[ir['IsOnTrack']] == name_scene: | |
obs.obs_frontend_set_current_scene(scene) | |
obs.obs_source_release(current_scene) | |
obs.source_list_release(scenes) | |
def script_properties(): | |
props = obs.obs_properties_create() | |
on_track_scenes_combo = obs.obs_properties_add_list( | |
props, "on_track_scene_prop", "On Track Scene", obs.OBS_COMBO_TYPE_EDITABLE, obs.OBS_COMBO_FORMAT_STRING) | |
off_track_scenes_combo = obs.obs_properties_add_list( | |
props, "off_track_scene_prop", "Off Track Scene", obs.OBS_COMBO_TYPE_EDITABLE, obs.OBS_COMBO_FORMAT_STRING) | |
scenes = obs.obs_frontend_get_scene_names() | |
if scenes is not None: | |
for scene in scenes: | |
name = scene | |
obs.obs_property_list_add_string(on_track_scenes_combo, name, name) | |
obs.obs_property_list_add_string(off_track_scenes_combo, name, name) | |
obs.source_list_release(scenes) | |
return props | |
def script_save(settings): | |
script_update(settings) | |
def script_unload(): | |
global ir | |
ir.shutdown() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You need to have python 3 installed.
Also, install
pyirsdk
with:> pip install pyirsdk
To use it:
Place it into your
scripts
folder in OBS. Tipically:C:\Program Files (x86)\obs-studio\data\obs-plugins\frontend-tools\scripts
Then activate in OBS, in
tools > scripts
and add the file you just created inscripts
folder.Then set in the two combos which scene do you want for "is driving" or "is not driving".
Happy streaming!