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 script don't want it to work globally

Support & discussion of released scripts, and announcements of new releases.
Post Reply
v
vladdeh
Voice
Posts: 33
Joined: Wed Mar 23, 2011 1:52 pm

youtube script don't want it to work globally

Post by vladdeh »

So this script takes youtube links said on channel then replies with the title etc. but right now it does it on every channel the bot is on, I only want it to do it on the channels that I want it in, not in all, help me please?

Code: Select all

namespace eval etube {
foreach p [array names etube *] { catch {unset etube($p) } }
setudef flag etube
    variable etube
    array set etube {
    ignored "wordtoignore1 wordtoignore2"
    delay 10
    outtype 3
    bestcomment 1
    strlength 500
    color1 \00314
    color2 \00303
    color3 \00305
    version "etube.tcl version 1.0"
    author "tvrsh"
    }


    package require http 2.7  

    bind pubm - * ::etube::etube
    proc ::etube::petube {nick uhost hand text} {
        if {![channel get $chan etube]} { 
            return 0
        }
        ::etube::etube $nick $uhost $hand $nick $text
    }


    bind msgm - * ::etube::metube
    proc ::etube::metube {nick uhost hand text} {
        ::etube::etube $nick $uhost $hand $nick $text
    }

    proc ::etube::etube {nick uhost hand chan text} {
        variable etube

        if {[info exists etube(lasttime,$chan)] && [expr $etube(lasttime,$chan) + $etube(delay)] > [clock seconds]} {
            return 0
        }

        set etube(start) [clock clicks]

        regsub -all -- {\017|\002|\037|\026|\003(\d{1,2})?(,\d{1,2})?} $text "" text
        set url [lsearch -inline [split $text] *http://*youtube*watch*]

        if {$url == ""} {return 0}

        ::http::config -useragent "Yandex/1.01.001 (compatible; Win16; I)"
        set yt_tok [::http::geturl "$url" -timeout 20000]  
        set data [::http::data $yt_tok]

        ::http::cleanup $yt_tok
        putlog "\[etube\] $nick/$chan"

        regsub -all -- {\n} $data " " data
        set data [encoding convertto cp1251 [encoding convertfrom utf-8 $data]]

        set errormsg ""
        regexp -- {<div id="watch-player-unavailable-message-container">(.+?)</div>} $data - errormsg
        if {$errormsg != ""} {
            ::etube::largetext PRIVMSG $chan "\002$nick\002, $errormsg\003"
            set etube(lasttime,$chan) [clock seconds]
            return 0
        }

        set verifymsg ""
        regexp -- {<div id="verify-details">(.+?)</div>} $data - verifymsg
        if {$verifymsg != ""} {
            ::etube::largetext PRIVMSG $chan "\002$nick\002, $verifymsg\003"
            set etube(lasttime,$chan) [clock seconds]
            return 0
        }

        set title ""
        regexp {<span id="eow-title" .*? title="(.*?)"} $data "" title
        regsub -all -- {\<[^\>]*\>|\t} $title "" title
        set title [string trim $title]

        foreach ignword [split $etube(ignored)] {
            if {[string match -nocase *$ignword* $title]} {
                ::etube::largetext PRIVMSG $chan "\002$nick\002, title of this video contein forbidden words. You fail!"
                set etube(lasttime,$chan) [clock seconds]
                return 0
            }
        }

        set length "100"
        regexp {"length_seconds": (.*?),} $data "" length

        set views ""
        regexp {<span class="watch-view-count">(.*?)</span>} $data "" views
        regsub -all -- {\<[^\>]*\>|\t} $views "" views
        set views [string trim $views]

        set author ""
        regexp {<div id="watch-headline-user-info">(.*?)</a>} $data "" author
        regexp {title="(.*?)"} $author "" author
        regexp {<strong>(.*?)</strong>} $author "" author

        set date ""
        regexp {<span id="eow-date" class="watch-video-date" >(.*?)</span>} $data "" date
        set date [string trim $date]

        set desc ""
        regexp {<p id="eow-description" >(.*?)</p>} $data "" desc
        regsub -all -- {<br />} $desc " " desc
        regsub -all -- {\<[^\>]*\>|\t} $desc "" desc

        set category ""
        regexp {<p id="eow-category">(.*?)</p>} $data "" category
        regsub -all -- {\<[^\>]*\>|\t} $category "" category

        set tags ""
        regexp {<ul id="eow-tags" class="watch-info-tag-list">(.*?)</ul>} $data "" tags
        regsub -all -- {\<[^\>]*\>|\t} $tags "" tags
        set tags [join $tags ", "]

        set comments ""; set comment ""; set cauthor ""; set cdate ""
        regexp {<ul class="comment-list" >(.*?)</li>} $data "" comments
        regexp {<div class="comment-text" dir="ltr">(.*?)</p>} $comments "" comment
        regsub -all -- {\<[^\>]*\>|\t} $comment "" comment
        set comment "$etube(color1)Last comment: $etube(color3)[string trim $comment]"
        regexp {<a class="author".*?>(.*?)</a>} $comments "" cauthor
        regexp {<span class="time">(.*?)</span>} $comments "" cdate

        if {$etube(bestcomment) == "1"} {
            regexp {<h4>Ëó÷øèå.*?<li class="comment "(.*?)</li>} $data "" comments
            regexp {<div class="comment-text" dir="ltr">(.*?)</div>} $comments "" comment
            regsub -all -- {\<[^\>]*\>|\t} $comment "" comment
            set comment "$etube(color1)Top comment: $etube(color3)[string trim $comment]"
            regexp {<a class="author ".*?>(.*?)</a>} $comments "" cauthor
            regexp {<span class="time">(.*?)</span>} $comments "" cdate
        } 

        set likes ""; set dislikes ""
        regexp {<span class="likes">(.*?)</span>} $data "" likes
        regexp {<span class="dislikes">(.*?)</span>} $data "" dislikes

        set outstring1 "[string range "Video title: $title. Category: $category. Views: $views. Likes/Dislikes: $likes/$dislikes." 0 $etube(strlength)]"
        set outstring2 "[string range "$etube(color1)$desc\003" 0 $etube(strlength)]"
        set outstring3 "[string range "$comment $etube(color1)by $etube(color3)$cauthor$etube(color1)($etube(color3)$cdate$etube(color1)). \00315([expr ([clock clicks] - $etube(start))/1000.0]ms.)\003" 0 $etube(strlength)]"

        switch $etube(outtype) {
            1 {
            ::etube::largetext PRIVMSG $chan $outstring1
            }
            2 {
            ::etube::largetext PRIVMSG $chan $outstring1
            ::etube::largetext PRIVMSG $chan $outstring1
            }
            3 {
            ::etube::largetext PRIVMSG $chan $outstring1
            ::etube::largetext PRIVMSG $chan $outstring1
            ::etube::largetext PRIVMSG $chan $outstring1
            }
        }
        set etube(lasttime,$chan) [clock seconds]
        return 0
    }

    proc ::etube::largetext {type target text {delims {" "•,.!?}}} {
        set lineLen [expr 512 - [string length ":$::botname $type [join $target] :\r\n"]]
        if {[string length $text] <= $lineLen} { 
            putserv "$type $target :[::etube::strip.html $text]"
            return 0
        }
        set _text [split $text $delims]
        set x 0
        set i 0
        while {$x < $lineLen} {
            if {$i >= [llength $_text]} { 
                return 0
            }
            set wordlen [string length [lindex $_text $i]]
            if {$x + $wordlen > $lineLen} { 
                break
            }
            incr x $wordlen
            incr x
            incr i
        }
    putserv "$type $target :[::etube::strip.html [string range $text 0 [expr $x - 1]]]"
    set color [string range [lindex [split [string range $text 0 [expr $x - 1]] "\003"] [expr [llength [split [string range $text 0 [expr $x - 1]] "\003"]] - 1]] 0 1]
    if {![isnumber $color]} {set color ""}
    ::etube::largetext $type $target \003$color[string trimleft [string range $text $x end]] $delims
    }

    # (c) feed.tcl by Vertigo
    proc ::etube::strip.html {t} {
        regsub -all -nocase -- {<.*?>(.*?)</.*?>} $t {\1} t
        regsub -all -nocase -- {<.*?>} $t {} t
        set t [string map {{&} {&}} $t]
        set t [string map -nocase {{—} {-} {»} {»} {«} {«} {"} {"}  \
		{<} {<} {>} {>} { } { } {&} {&} {©} {©} {©} {©} {•} {•} {·} {-} {§} {§} {®} {®} \
		  ‖ || \
		&      &     [      (     \      /     ]      )      {     (     }     ) \
		£     £     ¨     ¨     ©     ©     «     «      ­     ­     ®     ® \
		¡     ¡     ¿     ¿     ´     ´     ·     ·      ¹     ¹     »     » \
		¼     ¼     ½     ½     ¾     ¾     À     À      Á     Á     Â     Â \
		Ã     Ã     Ä     Ä     Å     Å     Æ     Æ      Ç     Ç     È     È \
		É     É     Ê     Ê     Ë     Ë     Ì     Ì      Í     Í     Î     Î \
		Ï     Ï     Ð     Ð     Ñ     Ñ     Ò     Ò      Ó     Ó     Ô     Ô \
		Õ     Õ     Ö     Ö     ×     ×     Ø     Ø      Ù     Ù     Ú     Ú \
		Û     Û     Ü     Ü     Ý     Ý     Þ     Þ      ß     ß     à     à \
		á     á     â     â     ã     ã     ä     ä      å     å     æ     æ \
		ç     ç     è     è     é     é     ê     ê      ë     ë     ì     ì \
		í     í     î     î     ï     ï     ð     ð      ñ     ñ     ò     ò \
		ó     ó     ô     ô     õ     õ     ö     ö      ÷     ÷     ø     ø \
		ù     ù     ú     ú     û     û     ü     ü      ý     ý     þ     þ \
		°     °     ‧    ·     ˌ     .     ū     u      ī     i     ˈ     ' \
		ɔ     o     ɪ     i     &apos;     ' } $t]
	set t [string map -nocase {¡    \xA1  ¤   \xA4  ¢     \xA2  £    \xA3   ¥      \xA5  ¦   \xA6 \
		§     \xA7  ¨      \xA8  ©     \xA9  ª     \xAA   «    \xAB  ¬      \xAC \
		­      \xAD  ®      \xAE  ¯     \xAF  °      \xB0   ±   \xB1  ²     \xB2 \
		³     \xB3  ´    \xB4  µ    \xB5  ¶     \xB6   ·   \xB7  ¸    \xB8 \
		¹     \xB9  º     \xBA  »    \xBB  ¼   \xBC   ½   \xBD  ¾   \xBE \
		¿   \xBF  ×    \xD7  ÷   \xF7  À   \xC0   Á   \xC1  Â    \xC2 \
		Ã   \xC3  Ä     \xC4  Å    \xC5  Æ    \xC6   Ç   \xC7  È   \xC8 \
		É   \xC9  Ê    \xCA  Ë     \xCB  Ì   \xCC   Í   \xCD  Î    \xCE \
		Ï     \xCF  Ð      \xD0  Ñ   \xD1  Ò   \xD2   Ó   \xD3  Ô    \xD4 \
		Õ   \xD5  Ö     \xD6  Ø   \xD8  Ù   \xD9   Ú   \xDA  Û    \xDB \
		Ü     \xDC  Ý   \xDD  Þ    \xDE  ß    \xDF   à   \xE0  á   \xE1 \
		â    \xE2  ã   \xE3  ä     \xE4  å    \xE5   æ    \xE6  ç   \xE7 \
		è   \xE8  é   \xE9  ê    \xEA  ë     \xEB   ì   \xEC  í   \xED \
		î    \xEE  ï     \xEF  ð      \xF0  ñ   \xF1   ò   \xF2  ó   \xF3 \
		ô    \xF4  õ   \xF5  ö     \xF6  ø   \xF8   ù   \xF9  ú   \xFA \
		û    \xFB  ü     \xFC  ý   \xFD  þ    \xFE   ÿ     \xFF} $t]
        set t [[namespace current]::regsub-eval {&#([0-9]{1,5});} $t {string trimleft \1 "0"}]
        regsub -all {[\x20\x09]+} $t " " t
        regsub -all -nocase -- {<.*?>} $t {} t
        return $t
    }

    proc ::etube::regsub-eval {re string cmd} {
        return [subst [regsub -all $re [string map {\[ \\[ \] \\] \$ \\$ \\ \\\\} $string] "\[format %c \[$cmd\]\]"]]
    }

    proc ::etube::duration {s} {
        variable etube
        set minutes [expr {$s / 60}]
	  set seconds [expr {$s % 60}]
	  set res ""
        if {$minutes != 0} {
            lappend res "$etube(color3)$minutes$etube(color1):"
        }
	  if {$seconds != 0} {
            lappend res "$etube(color3)$seconds"
        }
	  return [string map {": " ":"} $res]
    }

    putlog "\[etube\] $etube(version) by $etube(author) loaded"
}
User avatar
username
Op
Posts: 196
Joined: Thu Oct 06, 2005 9:20 am
Location: Russian Federation, Podolsk
Contact:

Post by username »

Why did you start new topic? There is http://forum.egghelp.org/viewtopic.php?t=17168 with my answer to you with this script.
Replace

Code: Select all

proc bind pubm - * ::etube::etube 
    proc ::etube::petube {nick uhost hand text} { 
        if {![channel get $chan etube]} { 
            return 0 
        } 
        ::etube::etube $nick $uhost $hand $nick $text 
    } 
with

Code: Select all

bind pubm - * ::etube::petube 
    proc ::etube::petube {nick uhost hand chan text} { 
        if {![channel get $chan etube]} { 
            return 0 
        } 
        ::etube::etube $nick $uhost $hand $chan $text 
    } 
Архив TCL скриптов для ботов Eggdrop/Windrop:
http://egghelp.ru/
v
vladdeh
Voice
Posts: 33
Joined: Wed Mar 23, 2011 1:52 pm

Post by vladdeh »

Sorry, this wasn't even the section I wanted to post in, my apologies.

BTW it worked, thanks.
Post Reply