Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //too lazy to do proper Oauth shit figure it out yourself
- key http_request_id;
- string auth = "";
- string RandomString(integer length) {
- list characters = ["-"];
- length=length/2;
- string emp;
- integer p;
- integer r;
- integer q = 50-length ;
- do{
- emp += "|";
- }
- while(length-1 > ++p);
- emp+=">";
- do{
- emp += "-";
- }
- while(q > ++r);
- return emp;
- }
- string spotify_url;
- default
- {
- state_entry(){
- llSetTimerEvent(2);
- }
- timer()
- {
- http_request_id = llHTTPRequest("https://api.spotify.com/v1/me/player/currently-playing?market=ES", [HTTP_METHOD, "GET",HTTP_CUSTOM_HEADER, "Authorization", "Bearer " + auth,HTTP_MIMETYPE, "application/json", HTTP_BODY_MAXLENGTH,16384], "");
- }
- touch(integer num_detected)
- {
- llInstantMessage( llGetOwner(),llKey2Name(llDetectedKey(0))+ " touched me" );
- llInstantMessage(llDetectedKey(0),spotify_url);
- }
- http_response(key request_id, integer status, list metadata, string body)
- {
- if( status == 204 || status == 401){
- llSetText("",<0,0,0>,0);
- }else
- {
- if(llJsonGetValue(body,["currently_playing_type"]) !="ad"){
- string song = llJsonGetValue(body,["item","name"]);
- string artist = llJsonGetValue(body,["item","artists",0,"name"]);
- spotify_url = llJsonGetValue(body,["item","external_urls","spotify"]);
- float song_length= (integer)llJsonGetValue(body,["item","duration_ms"]);
- integer hours = llFloor(song_length / 3600000);
- integer minutes = llFloor((song_length - (hours * 3600000)) / 60000);
- integer seconds = (integer)((song_length - (hours * 3600000) - (minutes * 60000)) / 1000);
- string secondstring ;
- if (seconds < 10){
- secondstring = "0"+(string)seconds;
- }else{
- secondstring = (string)seconds;
- }
- float progress= (integer)llJsonGetValue(body,["progress_ms"]);
- integer hours1 = llFloor(progress / 3600000);
- integer minutes1 = llFloor((progress - (hours1 * 3600000)) / 60000);
- integer seconds1 = (integer)((progress - (hours1 * 3600000) - (minutes1 * 60000)) / 1000);
- string secondstring1 ;
- if (seconds1 < 10){
- secondstring1 = "0"+(string)seconds1;
- }else{
- secondstring1 = (string)seconds1;
- }
- float percent = ((float)progress / (float)song_length )*100;
- string display = (string)minutes1+":"+
- secondstring1+" ["+RandomString(llFloor(percent))+"] "+(string)minutes+":" +secondstring;
- llSetText("Spotify\n" + song+ " - " + artist+"\n"+display, <0.118, 0.834, 0.380>, 1);
- } else{
- llSetText("Playing an ad", <0.118, 0.834, 0.380>, 1);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement