I also added such a function (with test coverage) on my ampache branch. I will try now to port those features, that unrelated to ampache, to the master branch and then you can use it for your code. Is this okay for you?