egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

youtube script don't want it to work globally

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Support & Releases
View previous topic :: View next topic  
Author Message
vladdeh
Voice


Joined: 23 Mar 2011
Posts: 33

PostPosted: Mon Nov 28, 2011 4:38 am    Post subject: youtube script don't want it to work globally Reply with quote

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:
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 {{&amp;} {&}} $t]
        set t [string map -nocase {{&mdash;} {-} {&raquo;} {»} {&laquo;} {«} {&quot;} {"}  \
      {&lt;} {<} {&gt;} {>} {&nbsp;} { } {&amp;} {&} {&copy;} {©} {©} {©} {&bull;} {•} {·} {-} {&sect;} {§} {&reg;} {®} \
        ‖ || \
      &      &     [      (     \      /     ]      )      {     (     }     ) \
      £     £     ¨     ¨     ©     ©     «     «      ­     ­     ®     ® \
      ¡     ¡     ¿     ¿     ´     ´     ·     ·      ¹     ¹     »     » \
      ¼     ¼     ½     ½     ¾     ¾     À     À      Á     Á     Â     Â \
      Ã     Ã     Ä     Ä     Å     Å     Æ     Æ      Ç     Ç     È     È \
      É     É     Ê     Ê     Ë     Ë     Ì     Ì      Í     Í     Î     Î \
      Ï     Ï     Ð     Ð     Ñ     Ñ     Ò     Ò      Ó     Ó     Ô     Ô \
      Õ     Õ     Ö     Ö     ×     ×     Ø     Ø      Ù     Ù     Ú     Ú \
      Û     Û     Ü     Ü     Ý     Ý     Þ     Þ      ß     ß     à     à \
      á     á     â     â     ã     ã     ä     ä      å     å     æ     æ \
      ç     ç     è     è     é     é     ê     ê      ë     ë     ì     ì \
      í     í     î     î     ï     ï     ð     ð      ñ     ñ     ò     ò \
      ó     ó     ô     ô     õ     õ     ö     ö      ÷     ÷     ø     ø \
      ù     ù     ú     ú     û     û     ü     ü      ý     ý     þ     þ \
      °     °     ‧    ·     ˌ     .     ū     u      ī     i     ˈ     ' \
      ɔ     o     ɪ     i     &apos;     ' } $t]
   set t [string map -nocase {&iexcl;    \xA1  &curren;   \xA4  &cent;     \xA2  &pound;    \xA3   &yen;      \xA5  &brvbar;   \xA6 \
      &sect;     \xA7  &uml;      \xA8  &copy;     \xA9  &ordf;     \xAA   &laquo;    \xAB  &not;      \xAC \
      &shy;      \xAD  &reg;      \xAE  &macr;     \xAF  &deg;      \xB0   &plusmn;   \xB1  &sup2;     \xB2 \
      &sup3;     \xB3  &acute;    \xB4  &micro;    \xB5  &para;     \xB6   &middot;   \xB7  &cedil;    \xB8 \
      &sup1;     \xB9  &ordm;     \xBA  &raquo;    \xBB  &frac14;   \xBC   &frac12;   \xBD  &frac34;   \xBE \
      &iquest;   \xBF  &times;    \xD7  &divide;   \xF7  &Agrave;   \xC0   &Aacute;   \xC1  &Acirc;    \xC2 \
      &Atilde;   \xC3  &Auml;     \xC4  &Aring;    \xC5  &AElig;    \xC6   &Ccedil;   \xC7  &Egrave;   \xC8 \
      &Eacute;   \xC9  &Ecirc;    \xCA  &Euml;     \xCB  &Igrave;   \xCC   &Iacute;   \xCD  &Icirc;    \xCE \
      &Iuml;     \xCF  &ETH;      \xD0  &Ntilde;   \xD1  &Ograve;   \xD2   &Oacute;   \xD3  &Ocirc;    \xD4 \
      &Otilde;   \xD5  &Ouml;     \xD6  &Oslash;   \xD8  &Ugrave;   \xD9   &Uacute;   \xDA  &Ucirc;    \xDB \
      &Uuml;     \xDC  &Yacute;   \xDD  &THORN;    \xDE  &szlig;    \xDF   &agrave;   \xE0  &aacute;   \xE1 \
      &acirc;    \xE2  &atilde;   \xE3  &auml;     \xE4  &aring;    \xE5   &aelig;    \xE6  &ccedil;   \xE7 \
      &egrave;   \xE8  &eacute;   \xE9  &ecirc;    \xEA  &euml;     \xEB   &igrave;   \xEC  &iacute;   \xED \
      &icirc;    \xEE  &iuml;     \xEF  &eth;      \xF0  &ntilde;   \xF1   &ograve;   \xF2  &oacute;   \xF3 \
      &ocirc;    \xF4  &otilde;   \xF5  &ouml;     \xF6  &oslash;   \xF8   &ugrave;   \xF9  &uacute;   \xFA \
      &ucirc;    \xFB  &uuml;     \xFC  &yacute;   \xFD  &thorn;    \xFE   &yuml;     \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"
}
Back to top
View user's profile Send private message
username
Op


Joined: 06 Oct 2005
Posts: 196
Location: Russian Federation, Podolsk

PostPosted: Mon Nov 28, 2011 4:51 am    Post subject: Reply with quote

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:
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:
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/
Back to top
View user's profile Send private message Send e-mail Visit poster's website
vladdeh
Voice


Joined: 23 Mar 2011
Posts: 33

PostPosted: Mon Nov 28, 2011 5:10 am    Post subject: Reply with quote

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

BTW it worked, thanks.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Support & Releases All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber