################################################################# # SAM BroadCaster 4 Eggdrop TCL addon # Version 1.0 written by POEMA # # - History # * 29 sep 2005 + Wrote the script # - Bugs # * Dunno # * 01 jan 2007 + Mofofied for SAM 4 # # You are allowed to modify this code. # ################################################################# # Do only use this on IRC networks without high flood excess rate # 0 = normal usage (putquick) # 1 = fast usage (putfast) set usefast 0 proc putfast {arg} { append arg "\n" putdccraw 0 [string length $arg] $arg } ####################################### # Configuration settings you may change set samdb(host) "localhost" set samdb(user) "sam" set samdb(pass) "pass" set samdb(dbname) "SAMBC" set streaminfo(web) "http://radio.com/" set streaminfo(shoutcast) "http://127.0.0.1:8000/" set streaminfo(commands) "!current !next !info !randomlist !request \[comment\]" set station(host) "127.0.0.1" set station(port) "1221" set broadcast(channel) "#radio" set showrequest 5 # # 1=on - 0=off set broadcast(inchannel) 1 set requests 1 ######################### # no need to change set buffer "" set myversion "SAMBCTCL V4.0.92705 (c) POEMA 2005-2008" ######################### # command binds bind pub - !current sam:current bind pub - !next sam:next bind pub - !info sam:info bind pub - !stream sam:stream bind pub - !randomlist sam:randomlist bind pub - !request sam:request # ########## # Timers bind time - "* * * * *" sam:announcer bind time - "00 * * * *" sam:randomlistannounce bind time - "15 * * * *" sam:randomlistannounce bind time - "30 * * * *" sam:randomlistannounce bind time - "45 * * * *" sam:randomlistannounce # package require http 2.4 # ############################################################################# # FASTBASE MYSQL ADDON # Google on fastbase fbsql and you can download it (linux and win32 versions) # Load: Linux version set fbsql "./fbsql.so" if {[glob -nocomplain $fbsql] != ""} { if {[catch {load $fbsql} error]} { putlog "ADDON::ERROR:: $error FIX THIS FIRST!" ; return 0} } else { putlog "ADDON::ERROR:: Addon $fbsql does not exist! FIX THIS FIRST!" ; return 0} putlog "$fbsql loaded" ########################### # Main code # ########################### # Global announcer proc ann {text} { global broadcast usefast set line [join ${text}] if {$usefast != 0} { putfast "PRIVMSG $broadcast(channel) :${line}" } else { putquick "PRIVMSG $broadcast(channel) :${line}" } } # proc htmlcodes {tempfile} { set mapfile [string map {" ' & & [ ( \ / ] ) { ( } ) £ £ ¨ ¨ © © « « ­ ­ ® ® } $tempfile] set mapfile [string map {´ ´ · · ¹ ¹ » » ¼ ¼ ½ ½ ¾ ¾ À À Á Á Â Â } $mapfile] set mapfile [string map {Ã Ã Ä Ä Å Å Æ Æ Ç Ç È È É É Ê Ê Ë Ë Ì Ì Í Í Î Î Ï Ï Ð Ð Ñ Ñ Ò Ò Ó Ó Ô Ô Õ Õ Ö Ö } $mapfile] set mapfile [string map {× × Ø Ø Ù Ù Ú Ú Û Û Ü Ü Ý Ý Þ Þ ß ß à à á á â â ã ã ä ä å å æ æ ç ç è è é é ê ê } $mapfile] set mapfile [string map {ë ë ì ì í í î î ï ï ð ð ñ ñ ò ò ó ó ô ô õ õ ö ö ÷ ÷ ø ø ù ù ú ú û û ü ü ý ý þ þ } $mapfile] return $mapfile } ################# # Requests proc sam:request {nick uhost hand chan args} { global samdb broadcast station requests if {$requests != 1} { ann "DJ turned off requests" ; return 0 } set line [join $args] set sid [lindex $line 0] set comment [lrange $line 1 end] set addhost [lindex [split [maskhost $uhost] @] 1] if {$sid == ""} { ann "Usage: !request \[comment\]" ; return 0 } if {[sam:hostcheck]} { ann "DJ Host not reachable. Try again later." ; return 0 } set req "req/?songID=$sid&host=" set samurl "http://" append samurl $station(host) ":" $station(port) "/" $req $addhost set page [::http::config -useragent "SAMTCL 1.0"] set page [::http::geturl ${samurl}] set html [::http::data $page] ::http::Finish $page #putlog "#DEBUG# $html" if [regexp {[^<]+} $html code] { set pos [expr [string last > $code] + 1] set code [string range $code $pos end] set code [htmlcodes $code] } if [regexp {[^<]+} $html htmsg] { set pos [expr [string last > $htmsg] + 1] set htmsg [string range $htmsg $pos end] set htmsg [htmlcodes $htmsg] } ######################## # Default responses set msg "$htmsg - $code" ######################## # Customized responses switch -exact $code { "800" { set msg "SAM host must be specified" } "801" { set msg "SAM host can not be 127.0.0.1 or localhost" } "802" { set msg "Song ID must be valid" } "803" { set msg "Unable to connect. Station might be offline." } "804" { set msg "Invalid data returned!" } "200" { set msg "Request added" } "700" { set msg "Invalid request" } "703" { set msg "Requested SID \"$sid\" invalid" } "707" { set msg "Wrong URL used, inform the owner to edit the settings." } "601" { set msg "Song recently played, request not added." } "608" { set msg "Album already in request list, request not added." } "602" { set msg "Artist recently played, request not added." } } # if {$code != "200"} { ann "$msg" ; return 0 } if [regexp {[^<]+} $html reqid] { set pos [expr [string last > $reqid] + 1] set reqid [string range $reqid $pos end] set reqid [htmlcodes $reqid] } if {$comment == ""} {set comment "I just love this song."} sql connect $samdb(host) $samdb(user) $samdb(pass) sql selectdb $samdb(dbname) sql "UPDATE requestlist SET msg='$comment' WHERE ID='$reqid'" sql "UPDATE requestlist SET name='$nick' WHERE ID='$reqid'" sql disconnect ann "Request is added." } ################################ # Check if the station is online proc sam:hostcheck {} { global station set samurl "http://" append samurl $station(host) ":" $station(port) "/" set page [::http::config -useragent "SAMTCL 1.0"] if {[catch {::http::geturl ${samurl}} error]} { return 1 } set page [::http::geturl ${samurl}] ::http::Finish $page return 0 } # ################################################################ # automatic announce every 15 minutes 5 random songs to channel proc sam:randomlistannounce {nick uhost hand chan args} { global broadcast if {$broadcast(inchannel) == 0} {return 0} if {[sam:hostcheck]} { return 0 } set dummy [sam:randomlist "nick" "uhost" "hand" $broadcast(channel) "none"] } ###################### # Show random list proc sam:randomlist {nick uhost hand chan args} { global samdb broadcast showrequest if {[sam:hostcheck]} { ann "DJ Host not reachable. Try again later." ; return 0 } set line [join $args] set igenre [lindex $line 0] sql connect $samdb(host) $samdb(user) $samdb(pass) sql selectdb $samdb(dbname) set top [sql "SELECT ID FROM songlist ORDER BY ID DESC LIMIT 0,1"] set foot [sql "SELECT ID FROM songlist ORDER BY ID ASC LIMIT 0,1"] # putlog "Top: $top Foot: $foot" set sreqc 0 set rshow(0) 0 while {$sreqc != $showrequest} { set rshow($sreqc) 999999 while {$rshow($sreqc) > $top || $rshow($sreqc) < $foot || [string match "0*" $rshow($sreqc)]} { set rshow($sreqc) [rand_2 [rand_1 1]] putlog "Trying... $rshow($sreqc)" } putlog "Get Song info..." set title [sql "SELECT title FROM songlist WHERE ID = '$rshow($sreqc)'"] set artist [sql "SELECT artist FROM songlist WHERE ID = '$rshow($sreqc)'"] set genre [sql "SELECT genre FROM songlist WHERE ID = '$rshow($sreqc)'"] set songtype [sql "SELECT songtype FROM songlist WHERE ID = '$rshow($sreqc)'"] if ([string match "S" $songtype]) { putlog "Using ID: $rshow($sreqc)" regsub -all {[{\}}{\{}]} $title "" title regsub -all {[{\}}{\{}]} $artist "" artist regsub -all {[{\}}{\{}]} $genre "" genre if {$title == ""} {set title "N/A"} if {$artist == ""} {set artist "N/A"} if {$genre == ""} {set genre "N/A"} ann "\0037\002:SID:\002\003\0034 $rshow($sreqc) \003\00312\002::\002\003 - \002(\002$title\002)-(\002$artist\002)-(\002$genre\002)\002" putlog "SongAnnounced: $title - $artist - $genre" # incr sreqc 1 } else { putlog "No songtype S found .. trying next one..." } # } sql disconnect } proc rand_1 {length {chars 123456123456123456123456123456123456123456123456}} { set count [string length $chars] for {set index 0} {$index < $length} {incr index} { append result [string index $chars [rand $count]] } return $result } proc rand_2 {length {chars 123456789046238591704620385910746238590174623805917}} { set count [string length $chars] for {set index 0} {$index < $length} {incr index} { append result [string index $chars [rand $count]] } return $result } ################################################################# # Automatic channel announcer on songchange (checks every minute) proc sam:announcer {nick uhost hand chan args} { global samdb broadcast buffer if {$broadcast(inchannel) == 0} {return 0} if {[sam:hostcheck]} {return 0} sql connect $samdb(host) $samdb(user) $samdb(pass) sql selectdb $samdb(dbname) set songid [sql "SELECT songID FROM historylist ORDER BY ID DESC LIMIT 0, 1"] sql disconnect if {$songid != $buffer} { set buffer $songid ann "\002\0039Now playing:\003\002" set dummy [sam:current "nick" "uhost" "hand" $broadcast(channel) "none"] } } ########### # current proc sam:current {nick uhost hand chan args} { global samdb broadcast if {[sam:hostcheck]} { ann "DJ Host not reachable. Try again later." ; return 0 } sql connect $samdb(host) $samdb(user) $samdb(pass) sql selectdb $samdb(dbname) sql startquery "SELECT * FROM historylist ORDER BY ID DESC LIMIT 0, 1" -array results while {[sql fetchrow] != ""} { set currentartist [join $results(artist)] set currenttitle [join $results(title)] set currentalbum [join $results(album)] set listeners $results(listeners) set requestid $results(requestID) set songid $results(songID) } sql endquery set played [sql "SELECT count_played FROM songlist WHERE ID='$songid'"] set requested [sql "SELECT count_requested FROM songlist WHERE ID='$songid'"] set genre [join [sql "SELECT genre FROM songlist WHERE ID='$songid'"]] set albumyear [join [sql "SELECT albumyear FROM songlist WHERE ID='$songid'"]] set currenttitle [lrange $currenttitle 0 end] set currentartist [lrange $currentartist 0 end] set currentalbum [lrange $currentalbum 0 end] set genre [lrange $genre 0 end] set albumyear [lrange $albumyear 0 end] regsub -all {[{\}}{\{}]} $currenttitle "" currenttitle regsub -all {[{\}}{\{}]} $currentartist "" currentartist regsub -all {[{\}}{\{}]} $currentalbum "" currentalbum regsub -all {[{\}}{\{}]} $genre "" genre regsub -all {[{\}}{\{}]} $albumyear "" albumyear if { $currenttitle == "" } { set currenttitle "N/A" } if { $currentartist == "" } { set currentartist "N/A" } if { $genre == "" } { set genre "N/A" } if { $albumyear == "" } { set albumyear "N/A" } if { $currentalbum == "" } { set currentalbum "N/A" } ann "\0037\002:SID:\002\003\0034 $songid \003\0037\002::\002\003 \002Artist\002: $currentartist \002Title\002: $currenttitle" ann "\0037\002:SID:\002\003\0034 $songid \003\0037\002::\002\003 \002Album\002: $currentalbum \002Genre\002: $genre \002AlbumYear\002: $albumyear" ann "\0037\002:SID:\002\003\0034 $songid \003\0037\002::\002\003 \002Stats\002: Played $played times and requested $requested times" ann "\0037\002:SID:\002\003\0034 $songid \003\0037\002::\002\003 There are \002$listeners\002 listeners to the stream" if {$requestid > 0} { set rmsg [join [sql "SELECT msg FROM requestlist WHERE ID='$requestid'"]] set rname [join [sql "SELECT name FROM requestlist WHERE ID='$requestid'"]] set rmsg [lrange $rmsg 0 end] set rname [lrange $rname 0 end] regsub -all {[{\}}{\{}]} $rmsg "" rmsg regsub -all {[{\}}{\{}]} $rname "" rname if { $rmsg == "" } { set rmsg "N/A" } if { $rname == "" } { set rname "N/A" } ann "\0037\002:SID:\002\003\0034 $songid \003\0037\002::\002\003 \002\0033Requested\003\002 By \002$rname\002 with the message \002$rmsg\002" } sql disconnect } ####### # Next proc sam:next {nick uhost hand chan args} { global samdb broadcast if {[sam:hostcheck]} { ann "DJ Host not reachable. Try again later." ; return 0 } sql connect $samdb(host) $samdb(user) $samdb(pass) sql selectdb $samdb(dbname) set qam 0 sql startquery "SELECT * FROM queuelist ORDER BY ID LIMIT 0, 10" -array results while {[sql fetchrow] != ""} { incr qam 1 set songid($qam) $results(songID) } sql endquery set qvm 0 while {$qam != $qvm} { incr qvm 1 set title [join [sql "SELECT title FROM songlist WHERE ID='$songid($qvm)'"]] set artist [join [sql "SELECT artist FROM songlist WHERE ID='$songid($qvm)'"]] set genre [join [sql "SELECT genre FROM songlist WHERE ID='$songid($qvm)'"]] set albumyear [join [sql "SELECT albumyear FROM songlist WHERE ID='$songid($qvm)'"]] set requestid [join [sql "SELECT requestID FROM queuelist WHERE songID='$songid($qvm)'"]] set title [lrange $title 0 end] set artist [lrange $artist 0 end] set genre [lrange $genre 0 end] set albumyear [lrange $albumyear 0 end] regsub -all {[{\}}{\{}]} $title "" title regsub -all {[{\}}{\{}]} $artist "" artist regsub -all {[{\}}{\{}]} $genre "" genre regsub -all {[{\}}{\{}]} $albumyear "" albumyear if { $title == "" } { set title "N/A" } if { $artist == "" } { set artist "N/A" } if { $genre == "" } { set genre "N/A" } if { $albumyear == "" } { set albumyear "N/A" } ann "\0037\002:SID:\002\003\0034 $songid($qvm) \003\0037\002::\002\003 \002$qvm\002 / $qam + \002(\002$artist\002)-(\002$title\002)-(\002$genre\002)-(\002$albumyear\002)\002" if {$requestid > 0} { set rmsg [join [sql "SELECT msg FROM requestlist WHERE ID='$requestid'"]] set rname [join [sql "SELECT name FROM requestlist WHERE ID='$requestid'"]] set rmsg [lrange $rmsg 0 end] set rname [lrange $rname 0 end] regsub -all {[{\}}{\{}]} $rmsg "" rmsg regsub -all {[{\}}{\{}]} $rname "" rname if { $rmsg == "" } { set rmsg "N/A" } if { $rname == "" } { set rname "N/A" } ann "\0037\002:SID:\002\003\0034 $songid($qvm) \003\0037\002::\002\003 \002$qvm\002 / $qam + \002\0033Requested\003\002 By \002$rname\002 with the message \002$rmsg\002" } } # sql disconnect } ####### # Info proc sam:info {nick uhost hand chan args} { global samdb broadcast if {[sam:hostcheck]} { ann "DJ Host not reachable. Try again later." ; return 0 } set line [join $args] set sid [lindex $line 0] if {$sid == ""} { ann "Usage: !info " ; return 0 } sql connect $samdb(host) $samdb(user) $samdb(pass) sql selectdb $samdb(dbname) set found 0 sql startquery "SELECT * FROM songlist where ID='$sid'" -array results while {[sql fetchrow] != ""} { set found 1 ann "\0037\002:SID:\002\003\0034 $sid \003\0037\002::\002\003 \002Artist\002: $results(artist) \002Title\002: $results(title)" ann "\0037\002:SID:\002\003\0034 $sid \003\0037\002::\002\003 \002Album\002: $results(album) \002Genre\002: $results(genre) \002AlbumYear\002: $results(albumyear)" ann "\0037\002:SID:\002\003\0034 $sid \003\0037\002::\002\003 \002Stats\002: Played $results(count_played) times and requested $results(count_requested) times" if {$results(count_played) != 0} { ann "\0037\002:SID:\002\003\0034 $sid \003\0037\002::\002\003 \002Played\002: Last played at $results(date_played)" } } sql endquery if {$found == 0} { ann "SID \"$sid\" not found in database." } sql disconnect } ######### # Stream proc sam:stream {nick uhost hand chan args} { global streaminfo broadcast myversion ann "\002Web\002: $streaminfo(web) \002ShoutcastStream\002: $streaminfo(shoutcast)" ann "\002ChannelCommands\002: $streaminfo(commands)" ann "$myversion" }