Skip to content

Commit bc5253c

Browse files
ocramwatsonbox
authored andcommitted
Add support for 'Saved tracks' from 'Your music' library
1 parent 4cba847 commit bc5253c

1 file changed

Lines changed: 34 additions & 3 deletions

File tree

exportify.js

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ window.Helpers = {
1010
window.location = "https://accounts.spotify.com/authorize" +
1111
"?client_id=" + client_id +
1212
"&redirect_uri=" + encodeURIComponent([location.protocol, '//', location.host, location.pathname].join('')) +
13-
"&scope=playlist-read-private%20playlist-read-collaborative" +
13+
"&scope=playlist-read-private%20playlist-read-collaborative%20user-library-read" +
1414
"&response_type=token";
1515
},
1616

@@ -87,6 +87,26 @@ var PlaylistTable = React.createClass({
8787
playlists = $.merge([arguments[0][0]], arguments[1][0].items);
8888
}
8989

90+
// Show library of saved tracks if viewing first page
91+
if (firstPage) {
92+
playlists.unshift({
93+
"id": "saved",
94+
"name": "Saved",
95+
"public": false,
96+
"collaborative": false,
97+
"owner": {
98+
"id": userId,
99+
"uri": "spotify:user:" + userId
100+
},
101+
"tracks": {
102+
"href": "https://api.spotify.com/v1/me/tracks",
103+
"limit": 50,
104+
"total": 2500 // TODO: get rid of hard-coded library size
105+
},
106+
"uri": "spotify:user:" + userId + ":saved"
107+
});
108+
}
109+
90110
if (this.isMounted()) {
91111
this.setState({
92112
playlists: playlists,
@@ -155,7 +175,7 @@ var PlaylistRow = React.createClass({
155175
},
156176

157177
renderIcon: function(playlist) {
158-
if (playlist.name == 'Starred') {
178+
if (playlist.name == 'Starred' || playlist.name == 'Saved') {
159179
return <i className="glyphicon glyphicon-star" style={{ color: 'gold' }}></i>;
160180
} else {
161181
return <i className="fa fa-music"></i>;
@@ -273,6 +293,17 @@ var PlaylistsExporter = {
273293
playlists = arguments[0].items
274294
}
275295

296+
// Add library of saved tracks
297+
playlists.unshift({
298+
"id": "saved",
299+
"name": "Saved",
300+
"tracks": {
301+
"href": "https://api.spotify.com/v1/me/tracks",
302+
"limit": 50,
303+
"total": 2500 // TODO: get rid of hard-coded library size
304+
},
305+
});
306+
276307
$(playlists).each(function(i, playlist) {
277308
playlistFileNames.push(PlaylistExporter.fileName(playlist));
278309
playlistExports.push(PlaylistExporter.csvData(access_token, playlist));
@@ -305,7 +336,7 @@ var PlaylistExporter = {
305336

306337
csvData: function(access_token, playlist) {
307338
var requests = [];
308-
var limit = 100;
339+
var limit = playlist.tracks.limit || 100;
309340

310341
for (var offset = 0; offset < playlist.tracks.total; offset = offset + limit) {
311342
requests.push(

0 commit comments

Comments
 (0)