# This script is written by Sm0ke0ut. # For shoutcast servers only! # # Available Commands: # !np !song = Current Song # !dj !title = Stream Title/Current DJ # !server = Server Status # !status = Current Status of Stream (users/kbps) # !record = Listeners Peak # !listen = Get playlist # !genre = Shows Genre # !website !site !url = Shows url/site # !icq = ICQ Number # !aim = AIM Address # !request = Request Song # # indeed, there's also `Stream IRC`, but that's pretty useless because you're already at IRC... # # irc.fayntic.com #fatalerrorgroup ########################## ######## Settings ######## ########################## package require fileutil package require mysqltcl package require textutil # Stream URL (e.g. http://domain.tld:port OR http://IP:port) set url "http://stellar.dj:8000" # Playlist URL (Leave empty for default stream playlist) set playlist "http://stellar.dj:8000/listen.pls" # Public/User Channel set streamch "#SW" # Private/DJ Channel set djch "#radio" ########################## ###### DO NOT EDIT ####### ########################## # -- shrink -- proc shrink { calc number string start bl} { return [expr [string first "$string" $bl $start] $calc $number] } # Funky - Added to update the shoutcast information in the stellardb database set sqlserver "localhost" set dbuser "www" set dbpassword "notarealpassword" set dbname "stellardb" set dbportno "1178" set searchlimit "1" # These settings are to control the time a timer runs and in which intervals # updatedbtimer - used in the timer set updatedbtimer "1" # updatedbproctimer - used in the proc set updatedbproctimer "30" # The actual timer definition if {![info exists statuscheck_running]} { timer $updatedbtimer [list updatedb] set statuscheck_running 1 } proc updatedb {} { global updatedbtimer updatedbproctimer url playlit streamch djch global sqlserver dbuser dbpassword dbname dbportno searchlimit set streamip "91.121.140.69" set streamport "8000" set streampass "notarealpasswordeither" set db_handle [mysqlconnect -host $sqlserver -port $dbportno -user $dbuser -password $dbpassword -db $dbname] if {[catch {set sock [socket $streamip $streamport] } sockerror]} { putlog "error: $sockerror" } else { puts $sock "GET /admin.cgi?pass=$streampass&mode=viewxml HTTP/1.0" puts $sock "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.9)" puts $sock "Host: $streamip" puts $sock "Connection: close" puts $sock "" flush $sock while {[eof $sock] != 1} { set bl [gets $sock] if { [string first "standalone" $bl] != -1 } { set currentl "[string range $bl [shrink + 18 "" 0 $bl] [shrink - 1 "" 0 $bl]]" set curhigh "[string range $bl [shrink + 15 "" 0 $bl] [shrink - 1 "" 0 $bl]]" set maxl "[string range $bl [shrink + 14 "" 0 $bl] [shrink - 1 "" 0 $bl]]" set reported "[string range $bl [shrink + 19 "" 0 $bl] [shrink - 1 "" 0 $bl]]" set avgtime "[string range $bl [shrink + 13 "" 0 $bl] [shrink - 1 "" 0 $bl]]" set sgenre "[string range $bl [shrink + 13 "" 0 $bl] [shrink - 1 "" 0 $bl]]" set surl "[string range $bl [shrink + 11 "" 0 $bl] [shrink - 1 "" 0 $bl]]" set stitle "[string range $bl [shrink + 13 "" 0 $bl] [shrink - 1 "" 0 $bl]]" set cursong "[string range $bl [shrink + 11 "" 0 $bl] [shrink - 1 "" 0 $bl]]" set webhits "[string range $bl [shrink + 9 "" 0 $bl] [shrink - 1 "" 0 $bl]]" set streamhits "[string range $bl [shrink + 12 "" 0 $bl] [shrink - 1 "" 0 $bl]]" set streamstatus "[string range $bl [shrink + 14 "" 0 $bl] [shrink - 1 "" 0 $bl]]" set bitrate "[string range $bl [shrink + 9 "" 0 $bl] [shrink - 1 "" 0 $bl]]" set content "[string range $bl [shrink + 9 "" 0 $bl] [shrink - 1 "" 0 $bl]]" set version "[string range $bl [shrink + 9 "" 0 $bl] [shrink - 1 "" 0 $bl]]" set sql "select name, value from settings where id='3'" set result [mysqlsel $db_handle $sql -list] mysqlendquery $db_handle for {set i 0} {$i < $searchlimit} {incr i} { set record [lindex $result $i]; set livedj [lindex $record 0]; set livedjvalue [lindex $record 1]; } if { $stitle != $livedjvalue } { set sql "update `settings` set value='$stitle' where id='3' and name='$livedj'" set result [mysqlsel $db_handle $sql] mysqlendquery $db_handle } set sql "select name, value from settings where id='6'" set result [mysqlsel $db_handle $sql -list] mysqlendquery $db_handle for {set i 0} {$i < $searchlimit} {incr i} { set record [lindex $result $i]; set song [lindex $record 0]; set songvalue [lindex $record 1]; } if { $song != $cursong } { set sql "update `settings` set value='$cursong' where id='6' and name='$song'" set result [mysqlsel $db_handle $sql] mysqlendquery $db_handle } set sql "select name, value from settings where id='10'" set result [mysqlsel $db_handle $sql -list] mysqlendquery $db_handle for {set i 0} {$i < $searchlimit} {incr i} { set record [lindex $result $i]; set listeners [lindex $record 0]; set listenersvalue [lindex $record 1]; } if { $listeners != $reported } { set sql "update `settings` set value='$reported' where id='10' and name='$listeners'" set result [mysqlsel $db_handle $sql] mysqlendquery $db_handle } set sql "select name, value from settings where id='11'" set result [mysqlsel $db_handle $sql -list] mysqlendquery $db_handle for {set i 0} {$i < $searchlimit} {incr i} { set record [lindex $result $i]; set peak [lindex $record 0]; set peakvalue [lindex $record 1]; } if { $peak != $curhigh } { set sql "update `settings` set value='$curhigh' where id='11' and name='$peak'" set result [mysqlsel $db_handle $sql] mysqlendquery $db_handle } } } flush $sock close $sock } mysql::close $db_handle utimer $updatedbproctimer [list updatedb] } # Funky - Added to have a backup for the kick in the panel bind pub -!- !kicksource kickproc proc kickproc {nick uhost hand chan arg} { global url djch set streamip "91.121.140.69" set streamport "8000" set streampass "notarealpassword" if { $chan == $djch } { if {[catch {set sock [socket $streamip $streamport] } sockerror]} { putserv "privmsg $djch : error: $sockerror" putserv "privmsg $djch : Stellar Transmissions Shoutcast 1.9.8 Server is down." return 0 } else { puts $sock "GET /admin.cgi?pass=$streampass&mode=kicksrc HTTP/1.0" puts $sock "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.9)" puts $sock "Host: $streamip" puts $sock "Connection: close" puts $sock "" flush $sock close $sock putserv "privmsg $djch : Success! Source kicked as requested." } } } package require http bind pub -|- !song get_shoutcast_song bind pub -|- !np get_shoutcast_song proc get_shoutcast_song {nick uhost hand chan arg} { global url streamch djch set streamch [string tolower $streamch] set djch [string tolower $djch] ::http::config -useragent "Mozilla/5.0; Shoutinfo" if { $chan == $streamch } { set chan "$streamch" } if { $chan == $djch } { set chan "$djch" } set http_req [::http::geturl $url -timeout 2000] if {[::http::status $http_req] != "ok"} { puthelp "PRIVMSG $chan :Stream is unavailable"; return 0 } set data [::http::data $http_req] ::http::cleanup $http_req if {[regexp {Current Song: ([^<]+)} $data x title]} { puthelp "PRIVMSG $chan :\002Current Song\002: $title" } else { puthelp "PRIVMSG $chan :Couldn't receive any information, checking server status..." get_shoutcast_server $nick $uhost $hand $chan $arg } } bind pub -|- !title get_shoutcast_title bind pub -|- !dj get_shoutcast_title proc get_shoutcast_title {nick uhost hand chan arg} { global url streamch djch set streamch [string tolower $streamch] set djch [string tolower $djch] ::http::config -useragent "Mozilla/5.0; Shoutinfo" if { $chan == $streamch } { set chan "$streamch" } if { $chan == $djch } { set chan "$djch" } set http_req [::http::geturl $url -timeout 2000] if {[::http::status $http_req] != "ok"} { puthelp "PRIVMSG $chan :Stream is unavailable"; return 0 } set data [::http::data $http_req] ::http::cleanup $http_req if {[regexp {Stream Title: ([^<]+)} $data x title]} { puthelp "PRIVMSG $chan :\002DJ\002: $title" } else { puthelp "PRIVMSG $chan :Couldn't receive any information, checking server status..." get_shoutcast_server $nick $uhost $hand $chan $arg } } bind pub -|- !site get_shoutcast_site bind pub -|- !url get_shoutcast_site bind pub -|- !website get_shoutcast_site proc get_shoutcast_site {nick uhost hand chan arg} { global url streamch djch set streamch [string tolower $streamch] set djch [string tolower $djch] ::http::config -useragent "Mozilla/5.0; Shoutinfo" if { $chan == $streamch } { set chan "$streamch" } if { $chan == $djch } { set chan "$djch" } set http_req [::http::geturl $url -timeout 2000] if {[::http::status $http_req] != "ok"} { puthelp "PRIVMSG $chan :Stream is unavailable"; return 0 } set data [::http::data $http_req] ::http::cleanup $http_req if {[regexp {>http://([^<]+)} $data x title]} { puthelp "PRIVMSG $chan :\002Website\002: http://$title" } elseif {[regexp {>www.([^<]+)} $data x title]} { puthelp "PRIVMSG $chan :\002Website\002: http://www.$title" } else { puthelp "PRIVMSG $chan :Couldn't receive any information, checking server status..." get_shoutcast_server $nick $uhost $hand $chan $arg } } bind pub -|- !server get_shoutcast_server proc get_shoutcast_server {nick uhost hand chan arg} { global url streamch djch set djch [string tolower $djch] set streamch [string tolower $streamch] ::http::config -useragent "Mozilla/5.0; Shoutinfo" if { $chan == $streamch } { set chan "$streamch" } if { $chan == $djch } { set chan "$djch" } set http_req [::http::geturl $url -timeout 2000] if {[::http::status $http_req] != "ok"} { puthelp "PRIVMSG $chan :Stream is unavailable"; return 0 } set data [::http::data $http_req] ::http::cleanup $http_req if {[regexp {Server Status: ([^<]+)} $data x title]} { puthelp "PRIVMSG $chan :\002Server\002: $title" } else { puthelp "PRIVMSG $chan :Couldn't contact the server, please check the configuration and/or streaming server" } } bind pub -|- !genre get_shoutcast_genre proc get_shoutcast_genre {nick uhost hand chan arg} { global url streamch djch set streamch [string tolower $streamch] set djch [string tolower $djch] ::http::config -useragent "Mozilla/5.0; Shoutinfo" if { $chan == $streamch } { set chan "$streamch" } if { $chan == $djch } { set chan "$djch" } set http_req [::http::geturl $url -timeout 2000] if {[::http::status $http_req] != "ok"} { puthelp "PRIVMSG $chan :Stream is unavailable"; return 0 } set data [::http::data $http_req] ::http::cleanup $http_req if {[regexp {Stream Genre: ([^<]+)} $data x title]} { puthelp "PRIVMSG $chan :\002Genre\002: $title" } else { puthelp "PRIVMSG $chan :Couldn't receive any information, checking server status..." get_shoutcast_server $nick $uhost $hand $chan $arg } } bind pub -|- !status get_shoutcast_status proc get_shoutcast_status {nick uhost hand chan arg} { global url streamch djch set streamch [string tolower $streamch] set djch [string tolower $djch] ::http::config -useragent "Mozilla/5.0; Shoutinfo" if { $chan == $streamch } { set chan "$streamch" } if { $chan == $djch } { set chan "$djch" } set http_req [::http::geturl $url -timeout 2000] if {[::http::status $http_req] != "ok"} { puthelp "PRIVMSG $chan :Stream is unavailable"; return 0 } set data [::http::data $http_req] ::http::cleanup $http_req if {[regexp {B>([^<]+) of} $data x title]} { regexp { of ([^<]+) listeners} $data x title2 regexp {listeners ([^<]+)} $data x title3 regexp {Stream is up at ([^<]+) with} $data x title4 puthelp "PRIVMSG $chan :\002Status\002: $title of $title2 $title3 at $title4" } else { puthelp "PRIVMSG $chan :Couldn't receive any information, checking server status..." get_shoutcast_server $nick $uhost $hand $chan $arg } } bind pub -|- !record get_shoutcast_peak proc get_shoutcast_peak {nick uhost hand chan arg} { global url streamch djch set streamch [string tolower $streamch] set djch [string tolower $djch] ::http::config -useragent "Mozilla/5.0; Shoutinfo" if { $chan == $streamch } { set chan "$streamch" } if { $chan == $djch } { set chan "$djch" } set http_req [::http::geturl $url -timeout 2000] if {[::http::status $http_req] != "ok"} { puthelp "PRIVMSG $chan :Stream is unavailable"; return 0 } set data [::http::data $http_req] ::http::cleanup $http_req if {[regexp {Listener Peak: ([^<]+)} $data x title]} { puthelp "PRIVMSG $chan :\002Record\002: $title" } else { puthelp "PRIVMSG $chan :Couldn't receive any information, checking server status..." get_shoutcast_server $nick $uhost $hand $chan $arg } } bind pub -|- !stream get_shoutcast_listen proc get_shoutcast_listen {nick uhost hand chan arg} { global url streamch playlist djch set streamch [string tolower $streamch] set djch [string tolower $djch] if { $chan == $streamch } { set chan "$streamch" } if { $chan == $djch } { set chan "$djch" } if {$playlist == ""} { puthelp "PRIVMSG $chan :\002Stream/Listen\002: $url/listen.pls" } else { puthelp "PRIVMSG $chan :\002Stream/Listen\002: $playlist" } } bind pub -|- !icq get_shoutcast_icq proc get_shoutcast_icq {nick uhost hand chan arg} { global url streamch djch set streamch [string tolower $streamch] set djch [string tolower $djch] ::http::config -useragent "Mozilla/5.0; Shoutinfo" if { $chan == $streamch } { set chan "$streamch" } if { $chan == $djch } { set chan "$djch" } set http_req [::http::geturl $url -timeout 2000] if {[::http::status $http_req] != "ok"} { puthelp "PRIVMSG $chan :Stream is unavailable"; return 0 } set data [::http::data $http_req] ::http::cleanup $http_req if {[regexp {Stream ICQ: ([^<]+)} $data x title]} { puthelp "PRIVMSG $chan :\002ICQ\002: $title" } else { puthelp "PRIVMSG $chan :Couldn't receive any information, checking server status..." get_shoutcast_server $nick $uhost $hand $chan $arg } } bind pub -|- !aim get_shoutcast_aim proc get_shoutcast_aim {nick uhost hand chan arg} { global url streamch djch set streamch [string tolower $streamch] set djch [string tolower $djch] ::http::config -useragent "Mozilla/5.0; Shoutinfo" if { $chan == $streamch } { set chan "$streamch" } if { $chan == $djch } { set chan "$djch" } set http_req [::http::geturl $url -timeout 2000] if {[::http::status $http_req] != "ok"} { puthelp "PRIVMSG $chan :Stream is unavailable"; return 0 } set data [::http::data $http_req] ::http::cleanup $http_req if {[regexp {Stream AIM: ([^<]+)} $data x title]} { puthelp "PRIVMSG $chan :\002AIM\002: $title" } else { puthelp "PRIVMSG $chan :Couldn't receive any information, checking server status..." get_shoutcast_server $nick $uhost $hand $chan $arg } } bind pub -|- !request get_shoutcast_request proc get_shoutcast_request {nick uhost hand chan arg} { global streamch djch set streamch [string tolower $streamch] if {[string tolower $chan] == "$streamch"} { puthelp "PRIVMSG $djch :\002\Request\002: $arg - Requested by: \002$nick\002" puthelp "NOTICE $nick :\002$arg\002 is succesfully requested" } } bind time - "?1 *" checkannounce proc checkannounce { minute hour day month year } { global updatedbtimer updatedbproctimer url playlit streamch djch global sqlserver dbuser dbpassword dbname dbportno searchlimit set ctime [clock scan now] set atime [expr [clock scan now] - 300] set streamip "91.121.140.69" set streamport "8000" set streampass "notarealpasswordeither" set db [mysqlconnect -host $sqlserver -port $dbportno -user $dbuser -password $dbpassword -db $dbname] mysqluse $db $dbname //build var list set sql "SELECT name, value FROM settings" set sql [::mysql::sel $m $sql -list] foreach info $sql { set info [split $info " "] set [lindex $info 0] [lindex $info 1] } if ([expr $lastannounce + 300] < $ctime || $announcelines > 40) { set mysql_update [::mysql::exec $db "UPDATE settings SET value='${ctime}' WHERE name='lastannounce' "] set mysql_update [::mysql::exec $db "UPDATE settings SET value='0' WHERE name='announcelines' "] sendannounce #radio } mysqlclose $db } proc sendannounce { chan } { global sqlserver dbuser dbpassword dbname dbportno url set db [mysqlconnect -host $sqlserver -port $dbportno -user $dbuser -password $dbpassword -db $dbname] mysqluse $db $dbname //build var list set sql "SELECT name, value FROM settings" set sql [::mysql::sel $m $sql -list] foreach info $sql { set info [split $info " "] set [lindex $info 0] [lindex $info 1] } putquick "PRIVMSG $chan : test $status" if ($status == Online) { putquick "PRIVMSG $chan :Stellar.DJ Radio -- ${livedj} now playing ${song} with ${listeners} Unique Listeners -- ${url}" } mysqlclose $db }