Tuesday, November 21, 2017

#1 2017-10-25 09:59:50 pm

sojacalcium
Member
Registered: 2017-10-13
Posts: 2

Fast script to duplicate an iTunes playlist?

Hi,

First, thanks a lot to the community here. It's been a very helpful resource for AppleScript questions.

I'm trying to simply duplicate an iTunes playlist but my scripts are taking waaay too much time to complete.

Something as simple as this runs for a minute:

Applescript:


tell application "iTunes"
   duplicate every track of playlist "playlist1" to playlist "playlist2"
end tell

Do you know if there's an alternative that runs faster than this?

Extra context:
My source playlist has 20,000 tracks, that sit on a separate "server" machine. All are indexed though.

Using iTunes' UI, if I select them all then right click > "add to playlist [...]" then that too takes ages. However, if I select the tracks then go to "File">"New">"Playlist from Selection", that's instantaneous. neutral And why wouldn't it? I'm not asking iTunes to duplicate the actual files, just the track references.

And btw, I've simplified the code to go to the essence of the issue, but my actual objective is to not just copy all tracks, but only the ones that match a criterion.
I.e this:

Applescript:


tell application "iTunes"
   duplicate (every track of playlist "playlist1" whose bpm is greater than 120 and bpm is less than 150) to playlist "playlist2"
end tell

From my testing it is clear that it is not the "bpm" condition that slows everything down, it's the actual duplicate function.

Appreciate any help! This is the last problem I need to solve to bring to its conclusion a very cool project I've spent a couple of weeks on: generate playlists on the fly based on "mood" scores (happy, sad, danceable, bright timbre etc.), calculated in real time based on the inputs from a physical midi controller.

Model: MacBook Air
AppleScript: 2.5
Browser: Safari 537.36
Operating System: Mac OS X (10.12.6 beta 6)

Offline

 

#2 2017-11-01 06:34:06 am

DougAdams
Member
From:: Newton, MA, USA
Registered: 2003-05-09
Posts: 81
Website

Re: Fast script to duplicate an iTunes playlist?

If you run the script in Script Editor you will likely see some slowness. Because AppleScript. However, if you run it as a script from the iTunes Script menu it should run pretty speedily.


Doug

Offline

 

#3 2017-11-04 12:41:55 am

sojacalcium
Member
Registered: 2017-10-13
Posts: 2

Re: Fast script to duplicate an iTunes playlist?

Hi Doug. I tried just now to run the same line of code mentioned above, from iTunes and from the script editor, and it takes the same time (around 26 secs) to find and "duplicate" 4000 tracks. :'(

Would you know of another approach worth trying? I'm open to a mac gyver-style solution, as long as it results in a playlist that's been filtered based on the bpm value. And it needs to be AppleScript, because I am using MidiPipe to trigger parts of the script's code based on Midi control events.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)