Advertisement
charon_allen

Untitled

Apr 26th, 2024
608
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Changes to Shoutcast broke the old "7.html" method of getting songtitles
  2. //  Now you should do an http request to the url _ "/stats?sid=1" and parse the body for
  3. //   <SONGTITLE> This script allows textbox to enter a url and see the songtitles IF they are displayed
  4. //   by the streamer (they do not have to show the titles)
  5. // the script also reads the current music url from the land IF the object is deeded to land
  6. // If required, deed the object to the land group and the script will reset.
  7. // this script does NOT set the music url to the land - it only reads it. The other part is pretty trivial
  8. // added in bitrate server title and current listeners logic just for the hell of it
  9. // - Sharon Classito 20220812 V1.2
  10. // added some error testing, included replacing the &amp; and &apos; issue. 20220822
  11.  
  12. string qURL;
  13. string xtralines="\n \n \n";
  14. string liner="\n";
  15. vector hovercolor=<1,1,0>;
  16. string URL_2="/stats?sid=1";//this is required by shoutcast 2.0
  17. integer channel;
  18. integer listener;
  19. string currSongTitle ;
  20. string lastSongTitle;
  21. list feedList;
  22. key requestid;
  23. integer RUNNING=FALSE;//starts OFF
  24. list myhttp = [];
  25. string ServerTitle;
  26. integer bitrate;
  27. integer listeners;
  28. float delay = 1.0;// how often to poll the website, dont do it too often
  29.  
  30. init()
  31. {
  32.     lastSongTitle="";
  33.     string tempurl=llGetParcelMusicURL();//get the current musicURL this may require deeding to land group
  34.     if(tempurl!="")
  35.     {
  36.         qURL=tempurl;
  37.         RUNNING=TRUE;
  38.     }
  39.     else
  40.     {
  41.         llSay(0,"ERROR only the owner or a deeded object can get the parcel URL\nDeed to Group and it will restart\nOr touch to submit a URL");
  42.         RUNNING=FALSE;//if it cant read the URL then it needs to be entered in the dialog menu
  43.     }
  44. }
  45. song_hover(string message,vector songcolor)//takes care of all the hovertext
  46. {
  47.     llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_TEXT,message+xtralines,songcolor,1.0]);
  48. }
  49. string strReplace(string str, string search, string replace) {//the wiki strreplace function
  50.     return llDumpList2String(llParseStringKeepNulls((str = "") + str, [search], []), replace);
  51. }
  52.  
  53. default
  54. {
  55.     state_entry()
  56.     {
  57.         init();
  58.         if(RUNNING)
  59.         {
  60.             requestid = llHTTPRequest(qURL+URL_2,myhttp,"");
  61.             llSetTimerEvent(delay);
  62.         }
  63.     }
  64.     http_response(key request_id, integer status, list metadata, string body)
  65.     {
  66.         if(!RUNNING) return;
  67.         if(status!=200) llSay(0,"Status: "+(string)status+"\nMetadata: "+llList2CSV(metadata));//error catching.
  68.         if (request_id == requestid) {
  69.             if((llSubStringIndex(body,"</SONGTITLE>")!=-1))//it has to have the songtitle expression in the body
  70.             {// the following grabs all the info that I intend to display.
  71.                 string feed = llGetSubString(body,llSubStringIndex(body, "<SONGTITLE>") +
  72.                           llStringLength("<SONGTITLE>"), llSubStringIndex(body,"</SONGTITLE>") - 1);
  73.                 if(llSubStringIndex(body,"</CURRENTLISTENERS>")!=-1)
  74.                     listeners = (integer)llGetSubString(body,llSubStringIndex(body,"<CURRENTLISTENERS>")+
  75.                     llStringLength("<CURRENTLISTENERS>"), llSubStringIndex(body,"</CURRENTLISTENERS>")-1);
  76.                          
  77.                 if(llSubStringIndex(body,"</BITRATE>")!=-1)
  78.                     bitrate = (integer)llGetSubString(body,llSubStringIndex(body,"<BITRATE>")+
  79.                     llStringLength("<BITRATE>"), llSubStringIndex(body,"</BITRATE>")-1);
  80.                          
  81.                 if(llSubStringIndex(body,"</SERVERTITLE>")!=-1)
  82.                     ServerTitle = llGetSubString(body,llSubStringIndex(body,"<SERVERTITLE>")+
  83.                     llStringLength("<SERVERTITLE>"), llSubStringIndex(body,"</SERVERTITLE>")-1);
  84.                          
  85.                 feedList = llParseString2List(feed,[","],[]);
  86.                 string temptitle=strReplace(llList2CSV(feedList), "&amp;","&");//REPLACE THE AMPERSAND ISSUE
  87.                 currSongTitle =strReplace(temptitle, "&apos;","'");//REPLACE THE APOSTROPHE ISSUE
  88.                 integer length = llGetListLength(feedList);
  89.                 if ((currSongTitle != lastSongTitle)&&(llStringLength(currSongTitle)>0)&&(llStringLength(currSongTitle)<254))//check validity of song title by length
  90.                 {//the following sets it up for the hovertext
  91.                     string follower;
  92.                     if(llStringLength(ServerTitle)>0) follower="\n"+ServerTitle;
  93.                     if(bitrate>0) follower+="\nBitrate:\t"+(string)bitrate;
  94.                     if(listeners>0) follower+="\nListeners\t"+(string)listeners;
  95.                     lastSongTitle = currSongTitle;
  96.                     song_hover("Now playing"+liner+llUnescapeURL(currSongTitle)+follower,<llFrand(0.5)+0.5,llFrand(0.5)+0.5,llFrand(0.5)+0.5>);
  97.                     llSay(0, "Upcoming Song - " + currSongTitle);
  98.                 }
  99.             }
  100.             else //no songtitle!!
  101.             {
  102.             }
  103.         }
  104.     }
  105.     touch_start(integer num)
  106.     {
  107.         // need to textdialog to allow entry of a url for the qurl
  108.         RUNNING=FALSE;// turn off the requests
  109.         llSetTimerEvent(0);//turn off timer
  110.         llListenRemove(listener);//A previous user may not have responded. Make sure we don't leak!
  111.         channel = ~(integer)llFrand(1000.0);
  112.         listener = llListen(channel,"","","");
  113.         llTextBox(llDetectedKey(0),"Please submit your URL\n it should look like 'http://something.else:1234'\n do not hit ENTER just submit",channel);
  114.     }
  115.     listen(integer channel, string name, key id, string message)
  116.     {
  117.         llListenRemove(listener);//always clean up those listens!
  118.         // llSay(0,"You wrote: " + message);
  119.         llSetText(message,<1.0,1.0,0.0>,1.0);//display the URL until we get a reply from http request
  120.         qURL=message;
  121.         RUNNING=TRUE;
  122.         llSetTimerEvent(delay);
  123.     }    
  124.     timer()
  125.     {
  126.         requestid = llHTTPRequest(qURL+URL_2,myhttp,"");
  127.     }
  128.     changed(integer c)
  129.     {
  130.         if(c&&CHANGED_OWNER) llResetScript();//if they deed it this will get it restarted :)
  131.     }
  132.  
  133. }
  134.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement