Musikstream-Anzeige
Dieses Skript gibt den grad laufenden Song aus einem Stream aus. Dabei wird zwischen Shotcast & Co und Icecast unterschieden. Es wird mittels Notecard konfiguriert.
// script copyright by Rebekka Revnik
integer LINK_MUSIK = 65463;
string STREAM = "http://66.220.3.52:8000"; // dein Musikstream
key Req;
string song;
integer TalkMode = 1;
string NCNAME = "config";
key NCid;
integer NCLine;
integer Online;
integer Icecast = FALSE;
Init()
{
TalkMode = 1;
song = "";
STREAM = "";
llSetTimerEvent(0);
if(llGetInventoryType(NCNAME) == INVENTORY_NONE)
{
llOwnerSay("No config notecard found. Stopped.");
return;
}
llOwnerSay("Reading config...");
NCLine = 0;
NCid = llGetNotecardLine(NCNAME, NCLine++);
}
default
{
state_entry()
{
Init();
}
on_rez(integer start_param)
{
Init();
}
changed(integer change)
{
if(change & CHANGED_INVENTORY) Init();
}
http_response(key request_id, integer status, list metadata, string body)
{
if(Req == request_id)
{
string song1 = "";
if(Icecast)
{
list l = llParseString2List(body,["\n"],[]);
integer i;
list l1;
Online = FALSE;
for(i = 0; i < llGetListLength(l); i++)
{
l1 = llParseStringKeepNulls(llList2String(l, i), [","], []);
if(llList2String(l, 0) == "/yourmount")
{
Online = TRUE;
song1 = llList2String(l1, 5);
if (llSubStringIndex(song1 , " - ") == 0) {
song1 = llDeleteSubString(song1, 0, 2);
}
}
}
} else
{
Online = TRUE;
list l = llParseString2List(body,["<body>", "</body>"],[]);
l = llCSV2List(llList2String(l,1));
song1 = llList2String(l, 6);
}
if(song1 != song)
{
song = song1;
if(Online)
{
if(TalkMode == 0) llWhisper(0, "Now playing:\n" + song);
else if(TalkMode == 2) llShout(0, "Now playing:\n" + song);
else llSay(0, "Now playing:\n" + song);
llMessageLinked(LINK_SET, LINK_MUSIK, song, NULL_KEY);
} else llMessageLinked(LINK_SET, LINK_MUSIK, "Offline", NULL_KEY);
}
}
}
timer()
{
if(Icecast) Req = llHTTPRequest(STREAM+"/status2.xsl", [], "");
else Req = llHTTPRequest(STREAM + "/7.html HTTP/1.0\nUser-Agent: XML Getter (Mozilla Compatible)\n\n", [], "");
}
dataserver(key requested, string data)
{
if(requested == NCid)
{
if(data != EOF)
{
integer x = llSubStringIndex(data, "#");
if(x != -1) data = llDeleteSubString(data, x, llStringLength(data));
list l = llParseString2List(data, ["="],[]);
if(llGetListLength(l) == 2)
{
string s = llStringTrim(llToLower(llList2String(l, 0)), STRING_TRIM);
if(s == "talk_mode") TalkMode = llList2Integer(l, 1);
else if(s == "music_url") STREAM = llStringTrim(llList2String(l, 1), STRING_TRIM);
else if(s == "icecast")
{
s = llStringTrim(llToLower(llList2String(l, 1)), STRING_TRIM);
if(s == "yes") Icecast = TRUE;
else if(s == "no") Icecast = FALSE;
}
}
NCid = llGetNotecardLine(NCNAME, NCLine++);
} else
{
if(STREAM == "") llOwnerSay("No stream url found. Stopped.");
else
{
llOwnerSay("Ready.");
if(Icecast) Req = llHTTPRequest(STREAM + "/status2.xsl", [], "");
else Req = llHTTPRequest(STREAM + "/7.html HTTP/1.0\nUser-Agent: XML Getter (Mozilla Compatible)\n\n", [], "");
llSetTimerEvent(5);
}
}
}
}
}