On m'a demandé tout à l'heure s'il était possible d'avoir le nombre d'auditeurs sur une radio, voici le script modifié en conséquence:
tcl
set radiouid "your-radio-uid-to-use"
set apikey "apikeyforuser"
# delay : temps en secondes entre 2 vérifications du titre
set delay 60
package require http
set radio "off"
set rchan ""
bind pub - "!titre" radio:go
proc radio:go { nick uhost handle chan args } {
if { [llength $args] != 1} {
putserv "PRIVMSG $chan :Faites !titre [on|off] pour démarrer/arrêter l'annonce du titre"
return 0
}
if {[string tolower [lindex $args 0]]=="on"} {
if { $::radio == "on" } {
putserv "PRIVMSG $chan :L'affichage automatique est déjà en cours"
return 0
}
set ::radio "on"
set ::rchan $chan
radio:titre
return 1
} else {
if { $::radio != "on" } {
putserv "PRIVMSG $chan :L'affichage automatique n'est pas en cours"
return 0
}
set ::rchan ""
set ::radio "off"
return 1
}
}
set memo ""
proc radio:titre { } {
if { $::radio == "off" } { return 0; }
set url "http://api.radionomy.com/currentsong.cfm?type=xml&radiouid=$::radiouid&apikey=$::apikey"
set page [::http::geturl $url -timeout 3000]
set html [::http::data $page]
regexp -all -- {<title>(.+)?</title>} $html null title
regexp -all -- {<radioname>(.+)?</radioname} $html null radio
regexp -all -- {<artists>(.+)?</artists>} $html null artist
if { $title != $::memo } {
set ::memo $title
putserv "PRIVMSG $::rchan :En cours sur \002 .::. [htmlentities_decode $radio] .::. \002: \002[htmlentities_decode $title]\002 par \002[htmlentities_decode $artist]\002"
}
utimer $::delay radio:titre
}
bind pub - "!public" radio:audience
proc radio:audience {user host handle chan args} {
if { $::radio == "off" } { return 0; }
set url "http://api.radionomy.com/currentaudience.cfm?radiouid=$::radiouid&apikey=$::apikey"
set page [::http::geturl $url -timeout 3000]
set html [::http::data $page]
putserv "PRIVMSG $::rchan :$html auditeurs actuellement"
}