Advertisement
Guest User

Untitled

a guest
Sep 8th, 2019
1,698
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //too lazy to do proper Oauth shit figure it out yourself
  2. key http_request_id;
  3.  string auth = "";
  4. string  RandomString(integer length) {
  5. list characters = ["-"];
  6. length=length/2;
  7. string emp;
  8. integer p;
  9. integer r;
  10. integer q = 50-length  ;
  11.  
  12.     do{
  13.        emp += "|";
  14.     }
  15.     while(length-1  > ++p);
  16.     emp+=">";
  17.    
  18.     do{
  19.         emp += "-";
  20.     }
  21.     while(q > ++r);  
  22.                                      
  23.     return emp;
  24. }
  25. string spotify_url;
  26. default
  27. {
  28.  
  29.     state_entry(){
  30.          llSetTimerEvent(2);
  31.     }
  32.    
  33.     timer()
  34.     {
  35.         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], "");
  36.     }
  37.  touch(integer num_detected)
  38.      {
  39.         llInstantMessage( llGetOwner(),llKey2Name(llDetectedKey(0))+ " touched me" );
  40.         llInstantMessage(llDetectedKey(0),spotify_url);
  41.      }
  42.      
  43.     http_response(key request_id, integer status, list metadata, string body)
  44.     {
  45.  
  46.         if( status == 204 || status == 401){
  47.              llSetText("",<0,0,0>,0);
  48.             }else
  49.         {
  50. if(llJsonGetValue(body,["currently_playing_type"]) !="ad"){
  51.     string song = llJsonGetValue(body,["item","name"]);
  52.     string artist = llJsonGetValue(body,["item","artists",0,"name"]);
  53.     spotify_url =  llJsonGetValue(body,["item","external_urls","spotify"]);
  54.     float song_length= (integer)llJsonGetValue(body,["item","duration_ms"]);
  55.  
  56.  
  57.     integer  hours = llFloor(song_length / 3600000);
  58.     integer minutes = llFloor((song_length - (hours * 3600000)) / 60000);
  59.  
  60.     integer seconds = (integer)((song_length - (hours * 3600000) - (minutes * 60000)) / 1000);
  61.  
  62.     string secondstring ;
  63.  
  64.     if (seconds < 10){
  65.         secondstring = "0"+(string)seconds;
  66.     }else{
  67.         secondstring = (string)seconds;
  68.         }
  69.  
  70.        
  71.      float progress= (integer)llJsonGetValue(body,["progress_ms"]);
  72.  
  73.  
  74.     integer  hours1 = llFloor(progress / 3600000);
  75.     integer minutes1 = llFloor((progress - (hours1 * 3600000)) / 60000);
  76.     integer seconds1 = (integer)((progress - (hours1 * 3600000) - (minutes1 * 60000)) / 1000);
  77.  
  78.     string secondstring1 ;
  79.  
  80.     if (seconds1 < 10){
  81.         secondstring1 = "0"+(string)seconds1;
  82.     }else{
  83.          secondstring1 = (string)seconds1;
  84.         }
  85.  
  86.     float percent = ((float)progress / (float)song_length )*100;
  87.  
  88.  
  89.     string display =   (string)minutes1+":"+
  90.     secondstring1+" ["+RandomString(llFloor(percent))+"] "+(string)minutes+":" +secondstring;
  91.     llSetText("Spotify\n" + song+ " - " + artist+"\n"+display,     <0.118, 0.834, 0.380>, 1);
  92.     } else{
  93.                            llSetText("Playing an ad",     <0.118, 0.834, 0.380>, 1);
  94.             }
  95.  }
  96.  
  97. }
  98.  
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement