NOTE: as of Firefox 71 (perhaps even earlier), the screensaver/DPMS are automatically suspended when watching videos. This tool is therefore deprecated.
Watching videos on YouTube always proved to be problematic because my DPMS settings would kick in and the screen would turn off. Firefox didn't suspend them automatically when it detected HTML5 video playback. That's a feature that would be great. Not just in Firefox. But instead if there was a standard way that programs could signal that they want any screen blankings mechanisms to suspend. I think something similar exists with dbus and screensaver implementations like xscreensaver. None of them affect DPMS settings though. I prefer using just DPMS because it's always there and doesn't require additional software.
Programs which accomplished something similar existed, like lightsOn. However they didn't work how I wanted them. For example lightsOn checks for activity periodically and only does Flash video (not HTML5 video).
My solution
I noticed that Pulseaudio creates streams for each sound source (see picture below of Pavucontrol).
That gave me the idea to utilize that to figure out if Firefox is playing
back video. If it is, there should be an audio stream together with it.
Shortly after that, I discovered via pactl subscribe
that PulseAudio
emits events for certain things, like new streams appearing. I could
leverage that and trigger DPMS setting changes with that.
I wrote a Python script utilizing the python-pulse-control library. It allows one to monitor the PulseAudio events.
Download Firefox-DPMS
Arch Linux users can use the included PKGBUILD. You will need python-pulse-control. You can use my PKGBUILD from here or the one from the AUR.