xxxxxxxxxx
106
let autho
let newData
let tempo
let live
let s = new SpotifyWebApi()
let mySong
let songID = ""
let ColH
let ColS
let ColB
let radiusSize
let radiusRatio = 1
let authURL = "https://accounts.spotify.com/authorize?client_id=9e748c14f9654918be4b2d8c8861b953&response_type=token&scope=user-top-read"
let authRedirect = "&redirect_uri=" + encodeURIComponent("https://editor.p5js.org/rajshree.s/present/rmiAnER1I")
function getURLQuery(u) {
let q = window.location.hash.substring(1)
let v = q.split('&')
for (let i = 0; i < v.length; i++) {
let pair = v[i].split("=")
if (pair[0] == u){return pair[1]}
}
return false
}
s.setAccessToken(getURLQuery('access_token'))
function searchAudioFeatures() {
s.getAudioFeaturesForTrack(songID, function(err, data) {
if (err) console.error(err)
else {
mySong = returnData(data)
console.log('song', mySong)
tempo = Math.round(mySong.tempo)
live = Math.round(mySong.liveness)
}
})
}
// danceability: 0.281, energy: 0.505, key: 4, loudness: -9.662, mode: 0, …}
// acousticness: 0.159
// analysis_url: "https://api.spotify.com/v1/audio-analysis/2hMtYQ6KvvSidwV7JH7gnx"
// danceability: 0.281
// duration_ms: 219933
// energy: 0.505
// id: "2hMtYQ6KvvSidwV7JH7gnx"
// instrumentalness: 0.00921
// key: 4
// liveness: 0.0923
// loudness: -9.662
// mode: 0
// speechiness: 0.0311
// tempo: 132.752
// time_signature: 4
// track_href: "https://api.spotify.com/v1/tracks/2hMtYQ6KvvSidwV7JH7gnx"
// type: "audio_features"
// uri: "spotify:track:2hMtYQ6KvvSidwV7JH7gnx"
// valence: 0.219
function returnData(responseData){
return responseData
}
function getCurrentTrack() {
s.getGeneric("https://api.spotify.com/v1/me/top/tracks?limit=1&time_range=long_term", function(err, data) {
if (err) console.error(err)
else {
newData = data
console.log(data)
songID = newData.items[0].id
console.log(songID)
searchAudioFeatures(songID)
}
}
)
}
function mouseClicked(canvas){
getCurrentTrack()
}
function setup() {
let canvas = createCanvas(400,400)
// canvas.parent(mySketch)
autho = createA(str(authURL + authRedirect), "authorise shit man")
autho.id("authenticate")
autho.position(width/3, height/3)
//autho.mouseClicked(href(str(authURL + authRedirect)))
}