Added spotify playlist image on exportation

This commit is contained in:
Kasper Rynning-Tønnesen
2017-12-01 11:47:04 +01:00
parent 03db8aa60a
commit fe728ad3c2
2 changed files with 26 additions and 2 deletions

View File

@@ -8,7 +8,7 @@ window.addEventListener("load", function() {
if(query.spotify) { if(query.spotify) {
client_id = "b934ecdd173648f5bcd38738af529d58"; client_id = "b934ecdd173648f5bcd38738af529d58";
response = "token"; response = "token";
scope = "playlist-read-private playlist-read-collaborative user-read-private playlist-modify-public"; scope = "playlist-read-private ugc-image-upload playlist-read-collaborative user-read-private playlist-modify-public playlist-modify-private";
state = query.nonce; state = query.nonce;
window.location.href = "https://accounts.spotify.com/authorize?client_id=" + client_id + "&scope=" + scope + "&show_dialog=false&response_type=" + response + "&redirect_uri=" + redirect + "&state=" + state; window.location.href = "https://accounts.spotify.com/authorize?client_id=" + client_id + "&scope=" + scope + "&show_dialog=false&response_type=" + response + "&redirect_uri=" + redirect + "&state=" + state;

View File

@@ -575,11 +575,35 @@ var List = {
}, },
data: JSON.stringify({ data: JSON.stringify({
name: chan.toLowerCase() + " - Zoff", name: chan.toLowerCase() + " - Zoff",
description: "Playlist exported from Zoff (https://zoff.me/" + chan.toLowerCase() + "/)",
public: true public: true
}), }),
success: function(response){ success: function(response){
var playlist_id = response.id; var playlist_id = response.id;
//$.each(full_playlist, function(i, curr_song){ $.ajax({
type: "GET",
url: window.location.protocol + "//" + window.location.hostname + "/assets/images/small-square.base64.txt",
success: function(base64image) {
var image = base64image.substring(0, base64image.length - 1);
$.ajax({
type: "PUT",
url: "https://api.spotify.com/v1/users/" + user_id + "/playlists/" + playlist_id + "/images",
headers: {
'Authorization': 'Bearer ' + access_token_data.access_token,
'Content-Type': 'image/jpeg'
},
contentType: "image/jpeg",
data: image,
success: function(resp) {
console.log(resp);
console.log("Added image");
},
error: function(error) {
console.log(error);
}
});
}
});
var i = 0; var i = 0;
List.searchSpotify(full_playlist[i], playlist_id, user_id, full_playlist, i); List.searchSpotify(full_playlist[i], playlist_id, user_id, full_playlist, i);
//}); //});