bitfocus / companion-module-obs-studio

OBS Studio Module for Companion
MIT License
41 stars 28 forks source link

Variable `obs:free_disk_space` without text in it? #251

Closed chrisspiegl closed 5 months ago

chrisspiegl commented 5 months ago

I was just setting up Companion with OBS Studio and wondered if it would be possible to get a Feedback button for the remaining disk space to turn red once it's less than 10 GB for example.

As it stands, I found the variable obs:free_disk_space and that I can use it in the Feedback Internal Variable Check Boolean Expression or Check Value. However, the obs:free_disk_space appears to include the text " GB" at the end instead of a parsed bytes or GB number only.

Would it be possible to parse this, or setup a variable which is pre parsed for things like this type of feedback button?

Warm Regards, Chris

thedist commented 5 months ago

In Expressions you can use the function substr(value, start, end) to remove the characters from the start/end of a string. So for eaxmple substr($(obs:free_disk_space), 0, -3) would return the variable without GB or MB.

It'd still have issues when going from GB to MB as suddenly it'd jump from a low number to a high number which would throw off feedback, so ideally there should still be a variable with a raw disk space remaining value, but for the time being this may meet your needs to remove the GB from the end.

chrisspiegl commented 5 months ago

Thank you, @thedist, that indeed helps (see screenshot below). And I agree with the end statement: it still would be helpful to have the “clean value”.

I also added some bits to the expression for the Feedback, which makes it possible to work with the MB & GB (though I don't know if it would jump to TB for big drives).

This expression should make it so that it is true when the disk space is in the MB area or when it's GB and less than 10 (or whatever number you put there).

I set it up so that the color is yellow with less than 50 GB left, and then turns red when there is less than 10 GB left on the internal disk.

(
  substr($(obs:free_disk_space), -2) === 'MB'
  || (
    substr($(obs:free_disk_space), -2) === 'GB'
    && substr($(obs:free_disk_space), 0, -3) < 10
  )
)
Xnapper-2024-02-06-09 45 34
bryce-seifert commented 5 months ago

@chrisspiegl I have this merged and it will appear in a future version of the module. The changes made are:

chrisspiegl commented 5 months ago

This looks genius. To implement both of these is the best. Thank you.

One question, if I may: how do releases of these modules work? Do they auto-update in Companion, or do they release once a new update of Companion itself is shipped?

bryce-seifert commented 5 months ago

Currently modules are bundled with Companion, so you have to update the whole app. It will appear in beta there first and then in the next release.

I need to finish up a few other changes, but hope to have this in the betas soon, ideally this weekend.

bryce-seifert commented 4 months ago

@chrisspiegl This should be in the Companion beta version for you to try now.

chrisspiegl commented 4 months ago

@bryce-seifert - I downloaded the latest beta of Companion, and it is in there and working. Great work and I appreciate the fast implementation 👍.

I played around the parameters to see how they reacted, and the setup of the preset with the red and yellow feedback is exactly as I would have set it up as well.

Wonderful.