1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Script speed

Discussion in 'iTunes & AppleScripts' started by UKenGB, Dec 7, 2016.

  1. UKenGB

    UKenGB Member

    The other day I realised that a lot of my music was 'missing'. Well, not really, but iTunes still thought it was in an old location I used to use. Only a minor proportion, but still several thousand files and no way I was going to locate each file individually. So I wrote an AppleScript to iterate through every track in the selected Playlist and check for wrong location. Rather surprisingly any track whose location cannot be found actually shows up in AppleScript as 'missing file', whereas looking at that track in iTunes and it shows the full path to the location it cannot find, so it is still stored. Ah the wonders of iTunes. ;)

    So I ended up with something similar to Doug's MIA script, but instead of writing the list to a file, I tagged each MIA track as 'Disliked'. This meant I could sort the list in iTunes to get ALL these MIAs together. Then I created a symlink that in theory meant the now incorrect paths should actually work and iTunes will read a file across a symlink, so when you 'Get info' on the first of these now 'Disliked' tracks, it instantly finds the file and re-writes the location to the correct path where the file now exists. Since they were all sorted next to each other I just repeatedly pressed the next arrow until all the tracks were corrected and no longer had the missing file flag in iTunes. Sorted I thought.

    Until the next day and many were still showing as missing. Huh? So I tried to run my script again, but it was hopelessly slow. The previous day it was counting through each track in the Music playlist so fast I couldn't read the numbers (AppleScript Progress counter). It was checking hundreds in only a few seconds. Still took a while to do 25,000, but no problem. Then this next day it was struggling to check more than 2 tracks per second, painfully slow. I restarted Script Editor (I was just running it there, same as the day before) and also restarted iTunes, but the exact same script, with no mods (I hadn't touched it in the meantime) was now running hundreds of times slower. WTF?

    I then thought about why the track locations seemed to have reverted and I think it was down to the fact that although iTunes was visually updating the location, it was not then saving it. This became apparent when I was looking in the library.xml file and saw a lot of the old incorrect locations. Hmmm.

    So I instead changed an ID3 tag on every file. I used BPM as I don't use that and it is stored in the file, not an iTunes only date field. Took a while but actually saving each file (remember the symlink that allowed the incorrect locations to work) meant that iTunes did save the correct location and once it had finished, the library.xml file no longer has any reference to the old incorrect locations. I realise the xml file is just for export, but it was a good indicator of whether any file still had the wrong location just using cat and a bit of grep.

    So in the end I got all files with their correct locations, but I'm baffled by this momental slowdown in the speed of the script when simply iterating through all the tracks. What could possibly cause such a huge difference? Any ideas?
     

Share This Page