Pour faire ça, il faut ajouter un timer (pour aller récupérer fréquement la page) et annoncer lorsque le titre lu n'est pas le titre mémorisé (donc déjà annoncé).
Voici un exemple (non testé) de script:
Avec ce script, la commande devient donc !titre [on|off] pour activer ou arrêter l'affichage automatique.
Voici un exemple (non testé) de script:
tcl
bind pub - "!titre" radio:go
set url "http://api.radionomy.com/currentsong.cfm?radiouid=6d854cc4-bb57-4339-b09f-2e5290a0bfda&apikey=6d854cc4-bb57-4339-b09f-2e5290a0bfda&type=xml"
# delay : temps en secondes entre 2 vérifications du titre
set delay 60
package require http
set radio "off"
set rchan ""
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 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
}
Avec ce script, la commande devient donc !titre [on|off] pour activer ou arrêter l'affichage automatique.