This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

youtube tcl with protection

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
C
Cr0ntab
Voice
Posts: 22
Joined: Fri Mar 26, 2010 11:31 am

youtube tcl with protection

Post by Cr0ntab »

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

Thank you
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

Give this a try.

Code: Select all

# 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 **
I must have had nothing to do
Post Reply