Last active
December 11, 2015 07:39
-
-
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/)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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