Here's a rough version of my script: https://github.com/smnx/mpv-autosub (forked from https://gist.github.com/selsta/ce3fb37e775dbd15c698).