Skip to content

Instantly share code, notes, and snippets.

@shinnn
Last active December 11, 2015 07:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shinnn/4567913 to your computer and use it in GitHub Desktop.
Save shinnn/4567913 to your computer and use it in GitHub Desktop.
Creating playlist on album name of itlp file, in iTunes LP (http://www.apple.com/itunes/lp-and-extras/)
var mainPlaylist = iTunes.createTempPlaylist();
(function(){
//location.host returns "persistentid-***"
var hostPersistentID = location.host.split("-")[1];
var tmpArr = iTunes.findTracksByTextFields({
album : iTunes.findTrackByPersistentID( hostPersistentID ).album
});
function isItlp(track){
return (track.bitRate === 0 && track.duration === 0 && track.version);
}
tmpArr.forEach( function(val, index, arr){
if(isItlp(arr[index])){
arr.splice(index, 1);
}
});
tmpArr.sortOn = function(){
for(var i=0 ; i < arguments.length; i++){
var field = arguments[i];
this.sort(function(a, b){
if(a[field] > b[field]){
return 1;
}
if(a[field] < b[field]){
return -1;
}
return 0;
});
}
}
tmpArr.sortOn("trackNumber"/*, "discNumber"*/);
mainPlaylist.addTracks(tmpArr);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment