Jump to content

Need some help with a Script


Stone Vought
 Share

You are about to reply to a thread that has been inactive for 2723 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

I wrote this script to extract the artist and song now playing on 181FM channels. It basically does what i'm asking it to do. But I have a problem with parsing the data extracted. The artist and song playing change sizes depending on whats being played at the time. So either the artist or song gets cut off if too long , or it shows the html tags if the artist and song is too short. I've tried a few things to adjust for this, but it's got me scratching my head. Any ideas on how to correct this ? I'll post the script below. Just rez a cube and put the url provided in the object description. I have the timer set to 60 you can change that to shorter to save time. Thanks for any ideas or help that you can provide.

 

//example use this URL in Objects Description - http://www.181.fm/station_playing/181-eagle.html
string music_url = "";
key HTTPRequestKey;
string URL;
default
{
    state_entry()
    {
        llSetText(" ",<1,1,1>,1);
        llSetTimerEvent(60.0);
   
        if(music_url)
        {
            URL = music_url;
        } else {
            URL = llGetObjectDesc();
        }
    }

    timer()
    {
HTTPRequestKey=llHTTPRequest(llGetObjectDesc() ,[],"");
    }
    http_response(key k,integer status, list meta, string body)
    {
        if(k != HTTPRequestKey) return;
           
     llSetText("Now Playing : "+llGetSubString(body,    -72, -45),<1,1,1>,1.0);
    llOwnerSay(llGetSubString(body,  -72, -45));
   
        }
         
    }

  • Like 1
Link to comment
Share on other sites

You'll need to nibble away at the returned body string from locations matched by llSubStringIndex().

I'll throw out a sample snippet below that worked a few times, so might keep working for a while, but this is all just crazy fragile and there's little reason to expect that any scraper script written today will work tomorrow. (Somebody invested in the problem could surely improve on this, but because I have no hint what might change first it's hard to guess what would make it more robust.)

        integer startIdx = llSubStringIndex(body, "startcurrent");        if (-1 == startIdx) return; // broke        string title = llGetSubString(body, startIdx+25, -1);        startIdx = llSubStringIndex(title, ">");        title = llGetSubString(title, startIdx+1, llSubStringIndex(title, "<")-1 );     llSetText("Now Playing : "+title,<1,1,1>,1.0);    llOwnerSay(title);
  • Like 1
Link to comment
Share on other sites

Thank you Qie, I'm testing it now. Looks good so far. I'm going to repost the ammended script if you don't mind, in case someone else can use it.        

 

// Script by Stone Vought with contributions from Qie Niangao

// Put your URL in the prims description Example : http://www.181.fm/station_playing/181-eagle.html it must be from 181.fm & their station playing website or type in /station_playing/ And which ever 181 site
string music_url = "";
key HTTPRequestKey;
string URL;
default
{
    state_entry()
    {
        llSetText(" ",<1,1,1>,1);
        llSetTimerEvent(40.0);
   
        if(music_url)
        {
            URL = music_url;
        } else {
            URL = llGetObjectDesc();
        }
    }

    timer()
    {
HTTPRequestKey=llHTTPRequest(llGetObjectDesc() ,[],"");
    }
    http_response(key k,integer status, list meta, string body)
    {
        if(k != HTTPRequestKey) return;
           
     integer startIdx = llSubStringIndex(body, "startcurrent");
        if (-1 == startIdx) return; // broke
        string title = llGetSubString(body, startIdx+25, -1);
        startIdx = llSubStringIndex(title, ">");
        title = llGetSubString(title, startIdx+1, llSubStringIndex(title, "<")-1 );
     llSetText("Now Playing : "+title,<1,1,1>,1.0);
    llOwnerSay(title);
   
        }
         
    }

       

  • Like 1
Link to comment
Share on other sites

you could also try using llParseString2List. I don't know a lot about html, so I don't know if it would be consistent enough to always use the same index, but it's worth a try:

list bodylist = llParseString2List(body, ["<",">"],[]);

integer listlength = llGetListLength(bodylist);

llOwnerSay(llList2String(bodylist, listlength-8));

  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 2723 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...