Created
December 5, 2011 09:40
-
-
Save liesen/1433041 to your computer and use it in GitHub Desktop.
Count number of tracks in playlists
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
_ = sp.require('underscore'); | |
sp.core.library.getTracks().length | |
// Versus: | |
// Total number of tracks in "library" = all playlists | |
_.reduce(sp.core.library.getPlaylists(), function (a, x) { return a + _.reject(_.map(_.range(x.length || 0), function (i) { return x.getTrack(i); }), function (t) { return t.isLocal || t.isAd || t.isPlaceholder || !t.availableForPlayback; }).length; }, 0) | |
// Number of unique tracks (unique track URIs) | |
_(sp.core.library.getPlaylists()).chain().map(function (p) { return _.map(_.range(p.length || 0), function (i) { return p.getTrack(i) }) }).flatten().filter(function (t) { return t.availableForPlayback && !t.isLocal }).map(function (t) { return t.uri }).uniq().size().value() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment