Python script to change Media Source file path

jiimjaam

New Member
I recently designed a bunch of different BRB/Ending videos for my stream, and I wanted to write a script that would modify a Media Source by picking a random file from a directory and assigning that file to said Media Source. I have the script that picks a random video and it works fine, but I have no idea how to implement it with OBS's Python functions. Basically, I have 3 scenes: Main, BRB, and Ending. I would like to run the script every time I switch to the Main scene, causing the BRB and Ending screens to be randomized the next time I switch to them.

Here's the Python I have so far to pick the files randomly:
Python:
import os, random
import obspython as obs

def list_full_paths(directory):
    return [os.path.join(directory, file) for file in os.listdir(directory)]

brb = random.choice(list_full_paths("E:\\Streaming\\Bumpers\\BRB"))
end = random.choice(list_full_paths("E:\\Streaming\\Bumpers\\Ending"))

Sorry if this is the wrong subforum to post this on! I've been using OBS for a while but I'm new to its more advanced features.
 

AaronD

Active Member
There's a plugin that can do that (and a LOT of other things too!):
1695136800127.png

1695136817342.png

1695136835031.png

1695136872115.png

That's incomplete, but I think you get the idea. Each BRB_# macro switches to a specific scene every time, and the main BRB macro runs a random one of those, selected when you switch to it, not when you go back to Main. That's slightly different from what you said, but gives the same result on the stream. The difference is that *you* don't know either, while if it's chosen beforehand like you specified originally, you *can* know if you want.
 
Top