Hello. i would like a tcl that shows the artist and title of a youtube link when it is posted to a channel but with 2 main protections:
1. flood protection with limiting 1 link per 4-5sec
2. a protection that if the title has one of the words i set in the tcl the title is NOT shown in the channel and the user gets a notice that the title of the Youtube videoo has a forbidden word in it
# youtitle.tcl
# to function in #channelname requires in the partyline .chanset #channelname +youtitle
# requires that coloured text can be displayed in #channelname (eg. not +c on DALnet)
###################################################################################################
########## configuration ##########################################################################
# set here the minimum time in seconds that must elapse before another channel input is parsed
set vYoutitleThrottleTime 5
# set here a list of words considered forbidden in YouTube video titles
set vYoutitleForbidden {
dead
sex
}
########## end of configuration ###################################################################
###################################################################################################
set vYoutitleVersion 11.03.20.17.47
package require http
setudef flag youtitle
set vYoutitleThrottled 0
bind PUBM - * pYoutitleTrigger
proc pYoutitleTrigger {nick uhost hand chan text} {
global vYoutitleThrottled vYoutitleThrottleTime
if {[channel get $chan youtitle]} {
if {!$vYoutitleThrottled} {
set vYoutitleThrottled 1
utimer $vYoutitleThrottleTime pYoutitleRelease
if {[regexp -nocase -- {youtube\.com/watch\?v\=([^\s]{11})} $text -> link]} {
pYoutitleParse $nick $chan $link
}
}
}
return 0
}
proc pYoutitleParse {nick chan link} {
global vYoutitleForbidden
set url http://www.youtube.com/watch?v=$link
set agent [::http::config -useragent "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)"]
if {![catch {set token [::http::geturl $url -timeout 10000]}]} {
switch -- [::http::status $token] {
ok {
switch -- [::http::ncode $token] {
200 {
set data [::http::data $token]
regexp -nocase -- {<span id=\"eow-title\"[^>]+>([^<]+)</span>} $data -> title
if {[info exists title]} {
set title [regsub -all -- {[\t\n]} $title ""]
set title [regsub -all -- {\:} $title " - "]
set title [string trim [regsub -all -- {[\s]{2,}} $title " "]]
set title [string map -nocase {\&\#39; \x27 & \x26 " \x22} $title]
foreach word $vYoutitleForbidden {
if {[regexp -nocase -- [subst -nobackslashes {(\A|\s)${word}(\s|\Z)}] $title]} {
putserv "NOTICE $nick :forbidden word(s) detected in the title of your YouTube link"
return 0
}
}
set page You\00300,04Tube\003
putserv "PRIVMSG $chan :$page $title"
} else {}
}
default {}
}
}
default {}
}
::http::cleanup $token
}
return 0
}
proc pYoutitleRelease {} {
global vYoutitleThrottled
set vYoutitleThrottled 0
return 0
}
putlog "youtitle.tcl version $vYoutitleVersion loaded"
# eof
** edited 21/03/11 14:14pm to translate html ampersands **