Using scripts to change a local image source based on contents of a text file?

cfilsooth

New Member
I'm trying to create a custom widget (a scene that can be nested inside other scenes) that displays data based on the media playing within that scene's VLC source. Basically, when this source is made visible on the layout, it starts playing its music, and displaying all the current song's associated metadata in the scrolling text sources I've put there. I'm using Tuna to get data from the currently playing media file and save it to .txt files in static locations. The text stuff all works just fine, and I've gotten it all to do exactly what I need it to do there. However, I'm running into a wall trying to figure out how to get this to interface with image sources.

I've already created a bunch of custom images to use as backgrounds for the widget. What I want to do is to tie a custom image to each song, and display the correct one based on the contents of the provided .txt file. (While Tuna can display album art, this isn't a workable solution, because I need the images to differ even if they're from the same album.) I imagine I can do this with a bunch of if and elseif statements housed within the script, and I have an extremely limited understanding of Python (I've gotten a basic hello-world working in OBS), but I don't know how I should write a script to do this specific thing.

For example: if the contents of the songandauthor.txt file the script is reading from says "Cool Submarine House, Bro - Some Guy" , the script knows it should change the image source to "C:\houses\submarine.png" . When the next song comes on, and Tuna updates that .txt file, the script checks it again. This time it reads "My Hat Smells Bad - Violent Fingers," so the script checks its if-then statements, and sees that it needs to change the image source to "D:\fingers\hats\smelly.png" .

Also, I should probably mention that the actual media titles will be non-English and in UTF-8 encoding, in case that requires extra consideration to handle.

What's the best way to make this work?
 

Suslik V

Active Member
If number of songs/pictures is not huge, then it was possible even in old v27+ OBS with the Advanced Scene Switcher plugin:
Something like in this (on the picture: 2 strings, 2 images, 1 macro per image/text):
Text-to-Image-binding-with-OBS-Advanced-Scene-Switcher-plugin2.png
 
Top