Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

discussion: Parcel DJ Station / Media changer

Dimentox Travanti
DCS Coder
Join date: 10 Sep 2006
Posts: 228
12-04-2006 22:46
This Will allow you to change stations via a touch and dialog.
It also allows you to have a user list.
This requires two parts one is the mixer the other is a repeter which should be by the mixer (usefull for group lands if its a group land make sure the prim thats the reciever not the mixer is group owned.)
This also contacts my server and grabs the shoutcast info for the station your on and displays it on a hover text on the mixer.


-The Mixer-
Script name: sc
CODE

//Writen By Dimentox Travanti
//Please leave this Intact
//You may not SELL this script.
//You may have limited liscence to use the SC query.
//This script is covered by the Creative Commons Liscence

string stationcard = "Stations";
string userc = "users";
integer cline = 0;
integer tline = 0;
key qstation;
key qlines;
integer d = 3;
string http ="http://";
string col = ":";
string scip;
string scpt;
string stationname;
integer x=0;
integer y=0;
integer z=0;
list users;
integer uline = 0;
key uquery;
key whotouch;
integer handle;
string request;
qsc()
{
request = "http://www.dimentox.com/sc/sc2.php?scip=" + scip + "&scpt=" + scpt;
llHTTPRequest(request,[HTTP_METHOD,"GET"],"");
}
change_s()
{
z = cline + d;
x = 0;
if (x > tline)
{
cline = 0;
}

qstation = llGetNotecardLine(stationcard, cline);

}
default
{
state_entry()
{

llSetText("loading", <1,1,1>, 1.0);
handle = llListen(-12345, "", NULL_KEY, "");
qlines = llGetNumberOfNotecardLines(stationcard);
uquery = llGetNotecardLine(userc, uline);
change_s();
cline = 0;

llSetTimerEvent(30);
}
on_rez(integer blahh)
{
llResetScript();
}
touch_start(integer times)
{
whotouch = llDetectedKey(0);
//string search = llDetectedName(0);
integer index = llListFindList( users, [llDetectedName(0)]);

if ( index != -1)
{
llListenRemove(handle);
handle = llListen(-12345, "", llDetectedKey(0), "");
llDialog(llDetectedKey(0), "Current Station " + stationname , ["Previous" , "Next", "Reset"], -12345);
} else {
llInstantMessage(whotouch, "You are not a DJ you may not change stations");
}
}
listen(integer channel, string name, key id, string message)
{
if (message == "Previous")
{
if (cline >= d)
{
cline = cline - d;
cline = cline - d;
change_s();
} else
{
cline = 0;
change_s();
}
//change_s();
}
if (message == "Next")
{
change_s();
}
if (message == "Reset")
{
llResetScript();
}

}
dataserver(key queryid, string data) {
if (queryid == uquery) {
if (data != EOF) {
users = users + [data];
++uline;
uquery = llGetNotecardLine(userc, uline);
}
}



if (queryid == qlines)
{

tline = (integer)data;

}
if (queryid == qstation) {
if (data != EOF) {
if (x == 0)
{
stationname = data;
if (whotouch){
llInstantMessage(whotouch, "Station Set to " + stationname);
}

}
if (x == 1)
{
//llSay(0, "ip"+data);
scip = data;
}
if (x == 2)
{
// llSay(0, "port"+data);
scpt = data;
}

++cline;
++x;
if (cline < z ){
qstation = llGetNotecardLine(stationcard, cline);
} else {
string media = "http://" + scip + ":" + scpt + "/";
qsc();
//this is for the group land with a reciever(might want to change the chan)
llWhisper(123456, "music " + media);
//uncomment this for a single prim on not grp based land
//llSetParcelMusicURL(media);
}




}
}


}
timer()
{
llSetText("loading", <1,1,1>, 1.0);
//llHTTPRequest("http://www.dimentox.com/sc/sc.php",[HTTP_METHOD,"GET"],"");
qsc();

}
http_response(key id, integer status, list metadata, string body)
{
llSetText("Station: " + stationname + "\n" + body, <1,1,1>, 1.0);
}

}


Note cards for the Mixer

Notecard:Stations
line 1: Name
line2: url w/o http
line3: port
Has to be this way for the hover text query.
CODE

Lost Angel's Radio
stream.dimentox.com
8000
UltraDark #1
84.16.231.180
3026
UltraDark #2
85.214.63.31
3026
Doomed
somafm-sc.streamguys.com
8300
Temple SL
66.197.50.71
8130


Notecard: users
full name per line
CODE

Dimentox Travanti
Ashes Arizona



-----Reciever---
aka for grp lands or non grp lands
this changes the actual media on the land

(you might want a transparent textoure on this prim)
script: Media Controller
CODE

//Writen By Dimentox Travanti
//Please leave this Intact
//You may not SELL this script.
//You may have limited liscence to use the SC query.
//This script is covered by the Creative Commons Liscence
default
{
state_entry()
{
llListen(123456, "", NULL_KEY, "");
}

listen( integer channel, string name, key id, string message )
{
if (llGetSubString(message, 0,4) == "music")
{
string media = llGetSubString(message, 6, -1);
llSetParcelMusicURL(media);
}
}

}


You might wanna change the channels for the reciever and dialogs.
_____________________
LSL Scripting Database - http://lsl.dimentox.com
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Original Thread
12-05-2006 08:24
/15/13/152853/1.html
_____________________
i've got nothing. ;)
Mathieu Basiat
Wavemaster
Join date: 24 Apr 2006
Posts: 57
12-07-2006 10:02
cool, mind posting the sc.php script?
ND Pitts
Registered User
Join date: 20 Jun 2006
Posts: 6
12-11-2006 07:03
I agree.. It's a great script but it does need the php counterpart.

pleae :)
Popcorn Munson
Registered User
Join date: 2 Nov 2006
Posts: 1
12-16-2006 06:03
Thanks for sharing Dimentox...Excellent!!!
Dimentox Travanti
DCS Coder
Join date: 10 Sep 2006
Posts: 228
12-18-2006 10:21
The sc2 script is a modified script i found...
but here it is.


FILE: sc2.php
CODE

?php
//header("Content-type: text/plain; charset=UTF-8");

//_____________________________________________________________________________
//=============================================================================
//
// SCSTATS v1.1 - Shoutcast Stats Quirier
// Orginal DL Location: http://public.ravetrax.com/scripts/scstats/
//
// This php application will quiry one shoutcast server, and then display the
// output as desired by the user altered templates.
//
// Copyright (C) 2005 - RaveTrax / Eric Crispen [aka: Rava]
//
// To contact me send email to: rava@ravetrax.com / eric@crispen.com
// Modified by Dimentox Travanti - for SL..
// you must have register globals on or you need to change the code to use the post vars
//-----------------------------------------------------------------------------
//
// The following are usable variables in the output templates:
//
// $listener_c = Current Listener Count
// $listener_p = Listener Peak Count
// $listener_m = Listener Max Count
// $listener_r = Report Listener Count
// $sc_bitrate = Current Stream Bitrate
// $sc_playing = Current Title Playing
//
//-----------------------------------------------------------------------------
//
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 of the License, or any later version.
//
// This program is distributed in hopes that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. Remeber, you are responible for your
// own actions, and at any time you may not blame me for anything that this
// script might have done.
//
// For more info on the GNU General Public License related to this program,
// write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
// Boston, MA 02110-1301 USA
//
//=============================================================================
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

//-----------------------------------------------------------------------------
//--[ put the path to your config file below

$cfg_path = "_scstats.cfg";

//--[ script stats function
function quiry_scserv($scservurl, $scservprt) {
//--[ kets turn all host names to ips
$scservfip = gethostbyname($scservurl);
//--[ lets open a socket to the shoutcast server
$getscserv = fsockopen($scservfip, $scservprt, &$errno, &$errstr, 10) or $php_err .= "server doa";
//--[ clear any leftover data
$servquiry = "";
//--[ if server is not found, return server quiry as offline
if (!$getscserv) { return "offline"; }
//--[ if server is online, go further
else {
//--[ ok we are in! lets quiry shoutcasts public 7.html page
fputs($getscserv, "GET /7.html HTTP/1.1\r\nAccept: */*\r\nAccept-Encoding: gzip, deflate\r\nUser-Agent: RaveTrax SC_Serv Stats Getter v1.1 (Mozilla Compatible)\r\nConnection: Keep-Alive\r\n\r\n");
//--[ keep reading until we reach the end of the file
while (!feof($getscserv)) { $servquiry .= fread($getscserv, 500); }
//--[ close socket once we are done reading the 7.html file
fclose($getscserv);
//--[ lets read and setup the string... call the cows, a haystack is nearby
$quiryb = substr($servquiry, strpos($servquiry, "\r\n\r\n") + 4);
//--[ ok fucntion complete, lets return our server quiry as online with data
return $quiryb;
}
}
//--[ verifies you set a config file path, continues or exits...
if (!$cfg_path) { echo "no config file listed!"; exit; }
else { include($cfg_path); $cfg_key = str_replace("ravetrax" ,"y", $cfg_key); }
//--[ the next few lines just varify that you have read the read me and edited the config
//--[ file as needed, then continues or exits as needed... i'm so evil... :)
if (!$html_a) { echo "no offline template found in config file"; exit; }
if (!$html_b) { echo "no online template found in config file"; exit; }
if ($cfg_key != "y") { echo "config file not found or formatted incorrectly!"; exit; }
else {
//--[ this is the guts of the script, lets call function here, hide if it fails
//echo "<!-- ";
$scserv_quiry = quiry_scserv($scip, $scpt);
//echo " -->";
//--[ returned quiry is offline, lets bail!
if ($scserv_quiry == "offline") {
//--[ what verbage should be used?
$csc_status = "$lang_a";
//--[ lets get the offline template and show user what we found.
include($html_a);
//--[ time to exit... see ya!
exit; }
//--[ retuned quiry is online! let continue here
else {
//--[ lets explode the quiry data into an array...
$quirydat = explode(",", $scserv_quiry);
//--[ ok, now lets double check to see if server is actually broadcasting
if ($quirydat[1] == "1") {
//--[ double check says server is online, lets continue here.
//--[ what verbage should be used?
$csc_status = "$lang_b";
//--[ now lets turn the pretty array into some variables for output.
$listener_c = $quirydat[0]; $listener_p = $quirydat[2];
$listener_c = strip_tags($listener_c);

$listener_m = $quirydat[3]; $listener_r = $quirydat[4];
$listener_m = strip_tags($listener_m);

$sc_bitrate = $quirydat[5];
$sc_playing = $quirydat[6];
$sc_playing = strip_tags($sc_playing);

//--[ let get the online template and show user the stats what we found.
include($html_b);
}
else {
//--[ double check says server is offline, lets bail!
//--[ what verbage should be used?
$csc_status = "$lang_a";
//--[ let get the offline template and show user what we found.
include($html_a);
//--[ time to exit... see ya!
exit;
}
}
}

//_____________________________________________________________________________
//=============================================================================
//--[ ok stop reading now, time to say goodbye! developed by rava@ravetrax.com
?>



Heres the config file
File: _scstats.cfg
CODE

//--[ shoutcast server ip and port
//moded and depricated for SL script
// $scip = "www.ravetrax.com";
// $scpt = "8128";


//-----------------------------------------------------------------------------
//--[ html outplut template files

$html_a = "_html-offline.sub";
$html_b = "_html-online.sub";


//-----------------------------------------------------------------------------
//--[ hard coded words - change to fit your needs

$lang_a = "Offline";
$lang_b = "Online";


//-----------------------------------------------------------------------------
//--[ this little trap must be set to "ravetrax" before the script will work

$cfg_key = "ravetrax";

//_____________________________________________________________________________
//=============================================================================
//--[ config is complete, time to say goodbye! developed by rava@ravetrax.com
?>



heres the html

file: _html-online.sub
CODE

Playing: <? echo $sc_playing; ?>
------------------------------------------
Current Listeners: <? echo $listener_c; ?>
Listener Peak: <? echo $listener_p; ?>
Max Listeners: <? echo $listener_m; ?>
Bitrate: <? echo $sc_bitrate; ?>


file: _html-offline.sub
CODE

Server Is Currently: <? echo $csc_status; ?>
_____________________
LSL Scripting Database - http://lsl.dimentox.com
Dioxide DeSantis
Registered User
Join date: 2 Feb 2007
Posts: 63
01-18-2008 14:26
Not sure why but I cant get the box to display any shoutcast info it always says offline even if the music is playing.

I placed all the files on my web server.

Did I do something wrong on the sc2.php file?
Haruki Watanabe
llSLCrash(void);
Join date: 28 Mar 2007
Posts: 434
01-18-2008 14:54
There's an easier way to get the current title/song directly from the shoutcast-server without having a PHP-Script pre-processing it.

Try to access the file http://myshoutcastserver.com:mountpoint/7.html

The file is really small (so it fits into the 2k limit of the HTTP-Request). You'll find something like:

10,0,27,50,10,112,midimal - 03 - deep devil-upe

The last part is the current title - song... just use a llParseString2List(html_body, [","], []) to split it up and you're done...

The remaining fields mean:

0 -> current listeners
1 -> status
2 -> listener peak
3 -> max listeners
4 -> reported listeners
5 -> bitrate
6 -> song

That's about all information you need... :)

[edit]

the actual http-request has to be a little special, just calling «server:mountpoint/7.html» doesn't work - use something like this instead:

string url = "http://www.myshoutcastserver.com:8000/7.html HTTP/1.0\nUser-Agent: XML Getter (Mozilla Compatible)\n\n";

requestid = llHTTPRequest(url,[],"";);

This will return the correct body in the http-request...
Dioxide DeSantis
Registered User
Join date: 2 Feb 2007
Posts: 63
02-20-2008 06:52
Well since I am not a scripted I don't have any idea how to implement that.
But thanks for the info anyway
BillFox Devin
Registered User
Join date: 27 May 2008
Posts: 1
06-18-2008 23:21
WOW thank you so much 2 posts up.. Ive been pounding my head on my desk for hours trying to figure out how to pull right from the sc server. Thanks a lot :D
Now my headache might go away =p
Rava Senior
Registered User
Join date: 28 Apr 2006
Posts: 3
06-20-2008 13:06
wow, its amazing what tend to stumble across...

i'm the original creator of the SCSTATS script posted by Dimentox Travanti... i wrote it many years ago... when shoutcast was just a baby for us.

however... i would think Haruki Watanabe's responce would be much better.

quiry the 7.html file of the shoutcast server your tuned to, then just split the string into varibales... would save alot of time really and be much quicker, and no php or web host would be needed.

Rava
Favio Piek
Registered User
Join date: 20 Jun 2007
Posts: 5
08-08-2008 21:53
From: Haruki Watanabe


the actual http-request has to be a little special, just calling «server:mountpoint/7.html» doesn't work - use something like this instead:

string url = "http://www.myshoutcastserver.com:8000/7.html HTTP/1.0\nUser-Agent: XML Getter (Mozilla Compatible)\n\n";

requestid = llHTTPRequest(url,[],"";);

This will return the correct body in the http-request...


Using that http-request I get an error "The server committed a protocol violation."
There is something missing in the url string?
Talon Brown
Slacker Punk
Join date: 17 May 2006
Posts: 352
08-08-2008 22:43
Try this (works for me)

CODE

string url = stream + "/7.html HTTP/1.0\nUser-Agent: XML Getter (Mozilla Compatible)\n\n";
llHTTPRequest(url, [HTTP_METHOD,"GET"], "");
Favio Piek
Registered User
Join date: 20 Jun 2007
Posts: 5
08-09-2008 00:12
I see that I only get the error in Lsleditor, apparently is working fine inworld.

Thanks
Napili Sands
Registered User
Join date: 8 Jun 2007
Posts: 29
02-04-2009 14:50
Does anyone have a working example of this code using the direct query to the shoutcast server that will return the artist/song title?

Thanks
Very Keynes
LSL is a Virus
Join date: 6 May 2006
Posts: 484
02-04-2009 23:18
For some reason the forum is not letting me post code today.
I can create a message like this but if I paste code into it I get a 404 error :(
I will try to send it to you in-world and update the thread when the forums have finished having a tantrum.
Napili Sands
Registered User
Join date: 8 Jun 2007
Posts: 29
02-05-2009 07:33
Thanks, Very!

I got the script and it works great. Songs with a comma in the title get truncated, but I don't see how you could easily fix that.
Cookie Bertone
Music & Audio
Join date: 13 May 2006
Posts: 13
AOL URL's not working
06-20-2009 14:16
The above works for a lot of stations but it does seem to have problems with AOL URL's I get from SHOUTcast such as http://scfire-mtc-aa04.stream.aol.com:80/stream/1018

I can play the stream using this URL in SecondLife but it doesn't seem to contain the 7.html , however if I play this stream in my usual media player, VLC, the track details are displayed. Is there any way I can impliment the same method of track extraction in SL?

The code I am currently using is:

timer()
{
llHTTPRequest(nPlayingURL+"/7.html HTTP/1.0\nUser-Agent: XML Getter (Mozilla Compatible)\n\n",[],"";);
}


http_response(key trackid, integer status, list metadata, string trackbody)
{
list TrackPullList = llParseString2List(trackbody,[","],[]); // takes the http result and turns it into a list
string TrackElement = llList2String(TrackPullList,6); // takes the track details out of the http result list (the sixth item)
TrackElement = llDeleteSubString(TrackElement, -14, -1); // strips off the html junk text at the end
llSay(0, "Now playing: " + TrackElement + ".";); // displays the result
}
_____________________
Bertone Audio Systems
Rossa (212, 98, 79)

Thanks to these forums the supplier of probably the best parcel music player in Second Life.