/*_____________________________________________________________________________ |/ / Shoutcast add-on by David "Saturn" van Moolenbroek | Version 0.3, released 18-07-2005 -- support on #help.script/Quakenet | Use/modify however you want, but please keep my name in it. Thank you! | | Keywords: shoutcast, sockets, regex, repeat-safe, callback | | This add-on allows you to fetch information (eg. number of listeners, | currently playing song) from a shoutcast server, and call a user-defined | command when it succeeds. | | The script defines the following commands/identifiers: | | /shoutcast [alias [params]] | | This command starts a socket connection to the specified destination | and will try to fetch information about the shoutcast server. The | part should be in the format "http://IP:port/", but just specifying | "IP:port" or "IP port" will work as well. | | If querying the shoutcast server succeeds, the script will pass this | information to an alias. If you do NOT specify an alias name with the | /shoutcast command, then the "sc_result" alias in the script will be | called. See below, at the bottom of this file. You can edit the | "sc_result" alias to let it do whatever you want - for example message | a channel. | | If you DO specify a callback alias, the script will call this alias | instead. This callback alias will be called like this: | | / [params] | | Where [params] is the list of parameters specified in the original | call to /shoutcast. For example, the song name starts at the | seventh parameter from the start of the info (ie. $7- if there are no | custom parameters at all). | | If the script somehow fails at retrieving the information, no alias will | be called at all. | | Examples | | ; simple: display what song is playing on http://205.188.234.65:8018/ | /shoutcast http://205.188.234.65:8018/ | | ; advanced: use e.g. "!shoutcast 213.73.255.244 8000" in a channel | alias -l scmsg msg $1 $+([http://,$2,:,$3,]) $4 listeners, playing $10- | on *:TEXT:!shoutcast & &:#:shoutcast $2-3 scmsg $chan $2-3 \ _\_____________________________________________________________________________ */ alias -l sc_result { ; THIS ALIAS IS CALLED WHEN THE SHOUTCAST INFO IS SUCCESSFULLY RETRIEVED ; $1 = nr. of listeners, $2 = status, $3 = listener peak, ; $4 = max. listeners, $5 = nr. unique listeners, $6 = kbps ; $7- = song name echo -atc info Now playing: $7- } alias shoutcast { if (: isin $1) { var %dst = $gettok($remove($1,http://),1,47) tokenize 32 $gettok(%dst,1,58) $gettok(%dst,2,58) $2- } if ((. !isin $1) || ($$2 !isnum)) return var %i = $rand(0,999) while ($sock(shoutcast- $+ %i)) inc %i sockopen shoutcast- $+ %i $1-2 sockmark shoutcast- $+ %i $iif($3 != $null,$3-,sc_result) } on *:SOCKOPEN:shoutcast-*:{ if ($sockerr > 0) return sockwrite -n $sockname GET /7.html HTTP/1.0 sockwrite -n $sockname User-Agent: Mozilla sockwrite -n $sockname } on *:SOCKREAD:shoutcast-*:{ if ($sockerr > 0) return var %line sockread %line while ($sockbr) sockread %line } on *:SOCKCLOSE:shoutcast-*:{ var %line sockread -f %line if ($regex(%line,(?:<.*?>)+([^<]+))) { tokenize 44 $gettok($regml(1),1-6,44) tokenize 32 $1-6 $gettok($regml(1),7-,44) $sock($sockname).mark $1- } }