Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Changes to Shoutcast broke the old "7.html" method of getting songtitles
- // Now you should do an http request to the url _ "/stats?sid=1" and parse the body for
- // <SONGTITLE> This script allows textbox to enter a url and see the songtitles IF they are displayed
- // by the streamer (they do not have to show the titles)
- // the script also reads the current music url from the land IF the object is deeded to land
- // If required, deed the object to the land group and the script will reset.
- // this script does NOT set the music url to the land - it only reads it. The other part is pretty trivial
- // added in bitrate server title and current listeners logic just for the hell of it
- // - Sharon Classito 20220812 V1.2
- // added some error testing, included replacing the & and ' issue. 20220822
- string qURL;
- string xtralines="\n \n \n";
- string liner="\n";
- vector hovercolor=<1,1,0>;
- string URL_2="/stats?sid=1";//this is required by shoutcast 2.0
- integer channel;
- integer listener;
- string currSongTitle ;
- string lastSongTitle;
- list feedList;
- key requestid;
- integer RUNNING=FALSE;//starts OFF
- list myhttp = [];
- string ServerTitle;
- integer bitrate;
- integer listeners;
- float delay = 1.0;// how often to poll the website, dont do it too often
- init()
- {
- lastSongTitle="";
- string tempurl=llGetParcelMusicURL();//get the current musicURL this may require deeding to land group
- if(tempurl!="")
- {
- qURL=tempurl;
- RUNNING=TRUE;
- }
- else
- {
- 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");
- RUNNING=FALSE;//if it cant read the URL then it needs to be entered in the dialog menu
- }
- }
- song_hover(string message,vector songcolor)//takes care of all the hovertext
- {
- llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_TEXT,message+xtralines,songcolor,1.0]);
- }
- string strReplace(string str, string search, string replace) {//the wiki strreplace function
- return llDumpList2String(llParseStringKeepNulls((str = "") + str, [search], []), replace);
- }
- default
- {
- state_entry()
- {
- init();
- if(RUNNING)
- {
- requestid = llHTTPRequest(qURL+URL_2,myhttp,"");
- llSetTimerEvent(delay);
- }
- }
- http_response(key request_id, integer status, list metadata, string body)
- {
- if(!RUNNING) return;
- if(status!=200) llSay(0,"Status: "+(string)status+"\nMetadata: "+llList2CSV(metadata));//error catching.
- if (request_id == requestid) {
- if((llSubStringIndex(body,"</SONGTITLE>")!=-1))//it has to have the songtitle expression in the body
- {// the following grabs all the info that I intend to display.
- string feed = llGetSubString(body,llSubStringIndex(body, "<SONGTITLE>") +
- llStringLength("<SONGTITLE>"), llSubStringIndex(body,"</SONGTITLE>") - 1);
- if(llSubStringIndex(body,"</CURRENTLISTENERS>")!=-1)
- listeners = (integer)llGetSubString(body,llSubStringIndex(body,"<CURRENTLISTENERS>")+
- llStringLength("<CURRENTLISTENERS>"), llSubStringIndex(body,"</CURRENTLISTENERS>")-1);
- if(llSubStringIndex(body,"</BITRATE>")!=-1)
- bitrate = (integer)llGetSubString(body,llSubStringIndex(body,"<BITRATE>")+
- llStringLength("<BITRATE>"), llSubStringIndex(body,"</BITRATE>")-1);
- if(llSubStringIndex(body,"</SERVERTITLE>")!=-1)
- ServerTitle = llGetSubString(body,llSubStringIndex(body,"<SERVERTITLE>")+
- llStringLength("<SERVERTITLE>"), llSubStringIndex(body,"</SERVERTITLE>")-1);
- feedList = llParseString2List(feed,[","],[]);
- string temptitle=strReplace(llList2CSV(feedList), "&","&");//REPLACE THE AMPERSAND ISSUE
- currSongTitle =strReplace(temptitle, "'","'");//REPLACE THE APOSTROPHE ISSUE
- integer length = llGetListLength(feedList);
- if ((currSongTitle != lastSongTitle)&&(llStringLength(currSongTitle)>0)&&(llStringLength(currSongTitle)<254))//check validity of song title by length
- {//the following sets it up for the hovertext
- string follower;
- if(llStringLength(ServerTitle)>0) follower="\n"+ServerTitle;
- if(bitrate>0) follower+="\nBitrate:\t"+(string)bitrate;
- if(listeners>0) follower+="\nListeners\t"+(string)listeners;
- lastSongTitle = currSongTitle;
- song_hover("Now playing"+liner+llUnescapeURL(currSongTitle)+follower,<llFrand(0.5)+0.5,llFrand(0.5)+0.5,llFrand(0.5)+0.5>);
- llSay(0, "Upcoming Song - " + currSongTitle);
- }
- }
- else //no songtitle!!
- {
- }
- }
- }
- touch_start(integer num)
- {
- // need to textdialog to allow entry of a url for the qurl
- RUNNING=FALSE;// turn off the requests
- llSetTimerEvent(0);//turn off timer
- llListenRemove(listener);//A previous user may not have responded. Make sure we don't leak!
- channel = ~(integer)llFrand(1000.0);
- listener = llListen(channel,"","","");
- llTextBox(llDetectedKey(0),"Please submit your URL\n it should look like 'http://something.else:1234'\n do not hit ENTER just submit",channel);
- }
- listen(integer channel, string name, key id, string message)
- {
- llListenRemove(listener);//always clean up those listens!
- // llSay(0,"You wrote: " + message);
- llSetText(message,<1.0,1.0,0.0>,1.0);//display the URL until we get a reply from http request
- qURL=message;
- RUNNING=TRUE;
- llSetTimerEvent(delay);
- }
- timer()
- {
- requestid = llHTTPRequest(qURL+URL_2,myhttp,"");
- }
- changed(integer c)
- {
- if(c&&CHANGED_OWNER) llResetScript();//if they deed it this will get it restarted :)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement