Copy calculated bpm data from algoriddim djay to iTunes using Applescript

It’s been a long time since I’ve messed with Applescript.

I modified a script I found on the algoriddim forums. This script would run through all tracks that were analyzed in djay and try to write the bpm data to the mp3 tag in iTunes. If your library is large, this could take days.

My modified script will take the currently selected tracks in iTunes and look for bpm data in the djay metadata plist file. Potentially a much smaller and more focused task.

 

[UPDATED 29 Feb 2012] I have included support for manually-set bpm values, which are stored by djay in a separate plist file.

 

[UPDATED 29 Mar 2012] I have included support for copying key data to iTunes, with translation of djay’s integer value to string representation

 

[UPDATED 23 Dec 2012] Bugfix: reset bpm variables in script to prevent old values from being held in memory for the next track. Thanks, Kieron Thorpe!

 

[UPDATED 22 Jan 2013] Bugfix: tracks with a key of 8B-C were being skipped. Thanks, recoltonRobert!
Enhancement: warn user if no tracks are selected in iTunes.

 

Download “Get bpm and key from Djay.scpt”

51 Replies to “Copy calculated bpm data from algoriddim djay to iTunes using Applescript”

    1. Thanks for the script, Mumbler. Saw your postings on the djay forum.

      I’m trying to modify your bpm script to transfer key data into the Groupings field in iTunes. Seems only a few parameters would have to be changed, such as changing BPM to KEY for the code lines that refer to the djay plist.

      What parameter(s) need to change on the iTunes side of the code?

      Thanks so much!
      Rob

    2. The above would replace the grouping field, so if you wanted to preserve existing data you would have to read the tag and do some string concatenation:

      set oldGrouping to grouping of myTrack
      set grouping to oldGrouping & ” ” & myKeyData

  1. Edmond,

    Thanks for the info. I’ve edited your script to copy over key data instead of bpm. It copies the key into the Groupings field in iTunes. As written, it will overwrite existing Grouping data.

    Here’s the script: http://dl.dropbox.com/u/7987233/Get%20key%20from%20Djay.scpt

    It records the key data in the form recorded by djay, which are values from 0 to 23. Once the data is in iTunes, it is easy to group together all songs with the same key value and do a batch change to a format more useful for harmonic mixing, such as 1A-G#m.

    Here’s how the djay key values correlate to key names:
    http://dl.dropbox.com/u/7987233/djay%20harmonic%20codes.txt

    It would be nice to work this conversion into the script to avoid this manual step in iTunes. I’m kind of an Applescript newbie — any suggestions for how to code this? Some kind of “if-then”? If you give me the code for doing one (example: 9 = 12A-C#m) then I can go from there for doing the other 23 values.

    I’d like to see this script posted to the following djay forum, either as is or with the proposed addition, since it offers the alternative approach of selecting the tracks in iTunes rather than doing a batch process on the whole djay cached plist.
    http://forum.algoriddim.com/viewtopic.php?pid=12951#p12951

    Thanks again!
    Rob

    1. Nice, Rob!

      I incorporated your script and suggestions. I will update the post with the new script.

      FYI, I handled the conversion to text by using a list (Applescript’s version of an array). I just set up a list:
      set all_keys to {“8B-C”, “8A-Am”, “3B-Db”}

      Then when I have the integer value from djay, I use that to grab the one I want:
      set key_djay_string to item (key_djay + 1) of all_keys

      The +1 is necessary because Applescript does not start indexing at 0 but at 1. So for a key_djay of 0 we want item 1 of the list.

  2. Awesome! This will save me lots of time for new music I’m bringing into my library. Really appreciate the help, and thanks for posting to djay forum.

    Rob

  3. hi ed,

    i found your scripts just recently after having upgraded to itunes 11.
    keys work perfectly, but bpm doesn’t.
    it just gives rubbish values like 10x 312 then 15x 64 then 10x 67 … definitely neither the auto-bpms of djay nor the ca. one third manual bpms i did there.
    i’m not really able to understand/edit the code of apple-scripts.
    do you plan to write an update for itunes 11 and make it available for download here again? would be very great!!

    all the best, roland

    1. Hi Roland,

      Thanks for letting me know. I will find time soon to update the script for iTunes 11. I’ll update this post when it’s ready.

      Ed

  4. Strange. I have not been able to replicate the bpm error. Just in case, I am uploading the version of the script from my hard drive. Please try downloading again and trying with iTunes 11.

  5. Hi, I was also getting false bpms. After a bit of digging I tracked it down to the rounding routine. I fixed it by doing the rounding once, AFTER choosing between the manual or auto bpm. Like so:

    try
    set bpm_djay to manual_bpm_djay
    on error
    set bpm_djay to auto_bpm_djay
    end try

    if (bpm_djay is not 0) then
    — write bpm data:
    set bpm of theT to (round bpm_djay rounding to nearest)
    end if

    Seems to work now. Kinda proud of myself TBH since this is my first attempt at Applescript. Recording Excel macros is as far as I’ve got until now : )

    1. I spoke too soon! It seems to fall over whenever it gets to a track with a manually set BPM, copying that value to the next track. Gonna do some more digging….

  6. Thanks, Kieron!

    I updated the script to only round the final bpm_djay value, as you demonstrated.

    I also added a few lines to reset the variables to zero to hopefully prevent bpm values making it into the wrong tracks.

    Ed

  7. works! works! works!!! that’s a nice christmas gift!!!
    thanks to you both ed and kieron!
    and have some nice x-mas holidays & a happy new year!
    all the best, roland

  8. I hate to seem like a noob here but I really want to get this working for me so I figured it doesn’t hurt to ask. I wonder if you could go through the steps to running this please? Do you want DJay and/or iTunes to be running at the same time or should they be closed? I opened the script in AppleScript Editor and hit run. It prompts me to chose key or bpm and also if I want to overwrite existing iTuines data. I make my selections, then in the event log it seems like it stops with “end tell
    tell application “iTunes”
    get selection
    –> {}
    end tell”

    I don’t know if it is working or not or what is going on. Any clarification would be appreciated.

  9. I literally just figured that out after a few days of going bonkers trying to decipher the script and figure out what was wrong. I was only getting one track to update but then I had a “eureka!” moment. I then selected all tracks and now it is doing its thing working like a charm! Amazing! I do think a pop-up reminding about track selections would be helpful. It sure would have saved me a lot of time and headache. Not that I am complaining or anything. Again, great work to all that contributed to this.

  10. Happy New Year! I had this working just great. I was selecting chunks at a time and running the script. Eventually it stopped actually writing to iTunes. First it was just kicking out an “error -10004” over and over. I did a permissions tweak.

    Now it keeps giving me “error number -1728”

    I would copy and past the lines around it but for some reason I cannot copy them. That also seems odd.

  11. Hi Flufnstuf,

    Happy New Year. Apparently, -1728 mean “Can’t get “. Are you able to tell by the results log what the script is trying to “get” when it throws this error?

    Ed

  12. Not any more. I ended up rebooting and that seems to have fixed it. Odd, I know. It is working though as I type this. I have a large library (35,000+) so I am doing it in chunks. I did notice one thing. I’ll try it again to confirm but, if I recall correctly, after choosing both BPM and Key, when I then choose to not overwrite iTunes info, it skips that track totally. This only was a thing when I already had BMP filled in on tracks and figured by not overwriting it would just fill in the Key. Not sure if that actually makes sense since it is early and I have only had a sip of coffee. In the end, for tracks that already had BPM, I chose to overwrite so it would fill in both.

  13. Tried this script again and it seems to have worked perfectly. The errors I was getting before Christmas (even AFTER the rounding adjustment I suggested) aren’t happening any more. Nice work Edmond & MacPinguin!

  14. Hey there — just dropping by to say thanks for this script! I also found my way here through the djay forums, and I’ve got the script working its way through my playlists, running like a charm. Much appreciated!

  15. Hi Edmon,

    Thanks for posting the script. I have used in extensively. There are a couple of problems I am having with it, but am able to work around them

    1. The first “8B-C” does not post to the meta tag. To get around this, I run a playlist of about 1,000 songs, what is left is 8B-C. I just group edit them.

    2. Apple script constantly reports “Not Responding” which I ignore, but my laptop crawls through a playlist when this happens. I close both iTunes and Djay constantly after running a couple of 1,000 songs and reboot.

    Ist there any way to speed up the script? Have one just for BPM without the extra code for Key? And vice-verse. I have 8GB ram and a hybrid drive. For a three year old Macbook Pro, it is fairly fast.

    I have about 61,000 songs in current library.

    Thanks again, Robert

    1. Hi Robert,

      First of all, thanks for pointing out the “8B-C” bug. I have updated the script.

      Unfortunately, Applescript is not known for its efficiency or speed. I would suggest cutting back your batch size until you find a balance between responsiveness and convenience that you deem acceptable.

      You can run the script in BPM-only or Key-only mode and the script will skip over those parts of the code.

      Are you running the script from the iTunes script menu?

      Ed

  16. I’ve edited it to put it in the comments instead of grouping (for traktor) and put equal spacing between the number and the actual key so it’s a little easier to see quickly.

  17. Thanks a lot, Ed.

    it works fine in a Mini with 10.6.8 , iTunes 10 and Djay 4.1
    Your post in the old Djay forum brought me there. It´s a pity that the new ones suck so much.
    Cheers

  18. Thanks for this the BPM element is perfect.

    I just have a query regarding the key, and sorry if it is a dumb question but my knowledge of “real” music is a bit crap.

    In DJAY the key for a track is: Gb (i assume that is G flat), but in itunes in the grouping filed it says 2A-Ebm.

    Thanks in advance for any enlightenment!

  19. Hi! Script Installed today, before updating iTunes to 11.1 (126), but BPM & Groups fields stay empty, this is an issue due to iTunes update? Thanks yo for help!

  20. ok!
    For me, all Groups Fields are filled yet. All BPM ready, calculated in DJay, BPM empty in iTunes, tests done track by track… itunes BPM not filled… ?
    My iTunes Library is so 90% analysed by DJay (?)

    Best regards.

  21. Hi dmsr,

    Since André is reporting that the script works with 11.1 on his system I would suggest trying either a reboot of your system or using Disk Utility to repair permissions. Or both.

    Edmond

  22. hi edmond
    forward i thank you for the script its genius !! i am not so fit in computer and my english to i have a question its possible to put the keys in comments in itunes???
    thanks for answer

  23. I stumbled across your awesome work, whilst searching for a way of getting djay bpm data to copy into iTunes track info and you seem to have done it! But I have no real tech skills and I don’t know how to run your script?!!! Do I literally download it and “open with” iTunes, or is there more too it? I should mention my iTunes is on a PC not a Mac – does that matter. Are there any djay settings that need adjusting to allow the data to be shared? If you have a mo to post an idiots guide it’d be great. Thanks buddy. Ronb

  24. Thank you so much for this wonderful script. Sometimes in djay, the auto bpm will give a value that is half the actual bpm, which I remedy by clicking ‘double.’ These bpm values are not transferring to iTunes. Instead it’s giving me the ‘auto’ value of one half the correct number. Any thoughts as to what’s going on?

  25. I have this problem to. I use a lot of old music when I dj, and djay’s calculated bpm value is almost always half of the the actual bpm. Therefore I go through each new song after it’s been imported to djay and double their bpm value. When I use the script, however, djay’s initial value is copied instead of the doubled, correct, value.

  26. Oops, posted on the wrong place, so I repost it here aswell.

    I have this problem to. I use a lot of old music when I dj, and djay’s calculated bpm value is almost always half of the the actual bpm. Therefore I go through each new song after it’s been imported to djay and double their bpm value. When I use the script, however, djay’s initial value is copied instead of the doubled, correct, value.

  27. Same problem with wrong half speed bpm. For me as swing dj, it´s not possible to use the script. An update would be fantastic!

  28. Good news everyone!

    Here is a brand new version of djay2itunes — now with day Pro support!

    Source code (now JavaScript) and application available on GitHub:
    https://github.com/ofstudio/djay2itunes.js

    (Note: open djay2itunes.app with right-click -> Open, because app is not signed)

    How to use this:
    http://yesnomaybe.ofstudio.ru/2015/01/23/djay2itunes-pierienos-mietadannykh-is-djay-pro-v-itunes/

    Text is in Russian, but pictures can tell everything 🙂

    Have a nice day!

Leave a Reply to Sandro BelloliCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.