I was looking up the information for scripting and was about to script something like you have here but with an extra option outside of just BPM's, I'm a DJ and when I mix I try to keep things harmonically mixed (every DJ does but it got easier than it was 10-15 years ago LOL) by keeping songs not only in a 6% BPM range but also by keeping them in keys similar to the key they are played in, instead of rambling on look at the
image here. Outside of mixing by ear I can now take guess work out of what songs go together by keeping them close in notes, it just makes things not only sound so damn good but I no longer need to label my mp3's manually there is a program that detects the key a file is played in and fills the comment section with the key it is played in & I mention this so you will understand why I was about to program my script.
So what I was going to script was something that allows me to choose the auto DJ to pick songs similar in BPM with a range of 6% either up or down and also simultaneously picking from my comments section and keeping that either in the same key, one key up or one key down. As a sample look at the image I linked then imagine a song played in F-Sharp Minor, that song would sound fantastic with another song in F-Sharp minor, A Major, D-Flat Minor or B Minor. However, not so good if you went to E-Major, D-Major, A-Flat Minor or B-Minor it doesn't mean it cannot be done or every song will sound bad it just means it's optimal to stay either one note to the left, right or directly above when looking at that Camelot wheel.
If you could do this feel free to otherwise I'll go along with my original plan and create it myself, I just didn't think it would be fair to do it when there is already a script which does the bulk of it.