nova's Music Script is a mod that exposes the machinations of the Minecraft music system to the end user, to be controlled via python scripts via Jython, and even allows you to play your own songs!
Available on https://modrinth.com/mod/novas-music-script
Documentation available at https://github.com/null-version-nova/musicscript/wiki