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 

[YouTitle] tcl error + small changes

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
Nash
Voice


Joined: 29 Jul 2012
Posts: 6

PostPosted: Mon Jul 30, 2012 5:37 pm    Post subject: [YouTitle] tcl error + small changes Reply with quote

Greetings Smile

I've found this youtube script and it's working pretty well so far:
Code:
package require http 2.4
bind PUBM - * mu
proc mu {nick uhost hand chan text} {
   set web(page) http://www.youtube.com
   set watch [regexp -nocase -- {\/watch\?v\=([^\s]{11})} $text youtubeid]
   if { $watch == 0 } {
      set watch [regexp -nocase -- {youtu\.be\/([^\s]{11})} $text a youtubeid]
      set youtubeid "/watch?v=$youtubeid"
   }
   
   set logoo "\002\00301,00You\00300,04Tube\002\017"
 
   if {$watch && $youtubeid != ""} {
      putlog "$web(page)$youtubeid"
      set agent "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1"     
      set t [::http::config -useragent $agent]
      set t [::http::geturl "$web(page)$youtubeid" -timeout 30000]
      set data [::http::data $t]
      ::http::cleanup $t
 
      set l [regexp -all -inline -- {<meta name="title" content="(.*?)">.*?<span class="watch-view-count">.*?<strong>(.*?)</strong>} $data]
 
      regexp {"length_seconds": (\d+),} $data "" length
 
      foreach {black a b c d e} $l {
 
         set a [string map -nocase {\&\#39; \x27 &amp; \x26 &quot; \x22} $a]
         set b [string map [list \n ""] $b]
         set c [string map [list \n ""] $c]
         set d [string map [list \n ""] $d]
         set e [string map -nocase {\&\#39; \x27 &amp; \x26 &quot; \x22} $e]
 
         regsub -all {<.*?>} $a {} a
         regsub -all {<.*?>} $b {} b
         regsub -all {<.*?>} $c {} c
         regsub -all {<.*?>} $d {} d
         regsub -all {<.*?>} $e {} e         
 
   #      putserv "PRIVMSG $chan :YouTube: $a ( [duration $length] ) Viewed $b"
         putserv "PRIVMSG $chan :YouTube: $a - Duration: [duration $length] - Views: $b"
 
             proc duration {s} {
            variable etube
            set hours [expr {$s / 3600}]
            set minutes [expr {($s / 60) % 60}]
            set seconds [expr {$s % 60}]
            set res ""
 
            if {$hours != 0} {append res "$hours hours"}            
            if {$minutes != 0} {append res " $minutes minutes"}
            if {$seconds != 0} {append res " $seconds seconds"}
            return $res
         }   
      }
   }
}
 
putlog "_____ YouTitle loaded..."


However, when it's loaded it gives me this error message in the partyline:
"Tcl error [mu]: can't read "youtubeid": no such variable"
The script works so far, but i would like to get rid off this error message.
EDIT: it appears that this error msg comes up everytime someone writes something in the channel. Shocked

Also, currently the script displays the youtube info like this:
YouTube: Bill Hicks salvation (FULL) - Duration: 1 hour 54 minutes 36 seconds - Views: 34.405

1.) Would it be possible to change the format of the duration to 1:54:36 or something simliar?
2.) Would it be possible to add likes /dislikes / author to the script?


Disclaimer: i've absolutely zero scripting knowledge so adding this by myself is practially impossible.
All i can do really is change the appearance Embarassed


Anyways, i'm highly grateful for every help i can get!!
Thanks in advance! Smile
Back to top
View user's profile Send private message
McGuyver
Voice


Joined: 31 Aug 2011
Posts: 14

PostPosted: Mon Jul 30, 2012 7:52 pm    Post subject: Reply with quote

I suggest adding
Code:
set youtubeid ""
right under the "proc mu" line
Back to top
View user's profile Send private message
Nash
Voice


Joined: 29 Jul 2012
Posts: 6

PostPosted: Tue Jul 31, 2012 12:05 am    Post subject: Reply with quote

Hey McGuyver, thanks for the tip! It worked! Smile
Any idea on the 2.) maybe? Wink
Back to top
View user's profile Send private message
doggo
Halfop


Joined: 05 Jan 2010
Posts: 97

PostPosted: Tue Jul 31, 2012 6:16 pm    Post subject: Reply with quote

try this, i made it a while ago for the bot in my websites irc channel, i hate clicking links when i dont know what the content will be! it should do everything you said you wanted already.. if not its easy enough to change a few bits here and there Wink

heres what it looks like http://i.imgur.com/FQRHu.png

Code:
# youtube.tcl
# by doggo #omgwtfnzbs@EFNET
#########################
package require http

bind pubm -|- * youtube:match

proc youtube:match {nick uhost hand chan text} {
   
   if {[regexp -nocase {http://.*youtube.com/watch\?(.*)v=([A-Za-z0-9_\-]+)} $text match fluff youtubeid]} {
   } elseif {[regexp -nocase {http://.*youtu.be/([A-Za-z0-9_\-]+)} $text match youtubeid]} {
   } else { return }

   set youtube_query "http://www.youtube.com/watch?v=$youtubeid"
   set html [youtube:getdata $youtube_query]

   regexp -nocase {<meta name="title" content="(.*?)">} $html match title
   regexp -nocase {<span class="watch-view-count">.*?<strong>(.*?)</strong>} $html match views
   regexp -nocase {<span class="likes">(.*?)</span> likes, <span class="dislikes">(.*?)</span>} $html match likes dislikes
   regexp -nocase {<span class="comments-section-stat">\((.*?)\)</span>} $html match comments
   regexp {"length_seconds": ([0-9]+),} $html match length

   set title [youtube:htmlcodes $title]
   if {$title==0} {return}

   if {$length > 3600} {
   set length [clock format $length -format %H:%M:%S]
   } else {
   set length [clock format $length -format %M:%S]
   }

   if {$comments == 1} {
   set com "comment"
   } else {
   set com "comments"
   }

   set logo "\002\0031,00 You\0031,00 \00300,04 Tube \00300,04\003\002\00314"
   set views "($views views)"
   set likes "$likes likes,"
   set dislikes "$dislikes dislikes"
   set comments "& $comments $com"

   puthelp "privmsg $chan :$logo \"$title\" $length $views $likes $dislikes $comments"
   
}

proc youtube:getdata {data} {

   ::http::config -useragent "Mozilla/5.0 (X11; U; Linux i686; ru-RU; rv:1.8.1) Gecko/2006101023 Firefox/2.0"
   set url [::http::geturl $data -timeout 5000]
   set html [::http::data $url]
   ::http::cleanup $html

   return $html

}

# borrowed from an old imdb script
proc youtube:htmlcodes {content} {
   if {$content == ""} {
   return 0
   }
   if {![string match *&* $content]} {
   return $content
   }
   set escapes {
   &nbsp; \x20 &quot; \x22 &amp; \x26 &apos; \x27 &ndash; \x2D
   &lt; \x3C &gt; \x3E &tilde; \x7E &euro; \x80 &iexcl; \xA1
   &cent; \xA2 &pound; \xA3 &curren; \xA4 &yen; \xA5 &brvbar; \xA6
   &sect; \xA7 &uml; \xA8 &copy; \xA9 &ordf; \xAA &laquo; \xAB
   &not; \xAC &shy; \xAD &reg; \xAE &hibar; \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
   &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 &times; \xD7 &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
   &divide; \xF7 &oslash; \xF8 &ugrave; \xF9 &uacute; \xFA &ucirc; \xFB
   &uuml; \xFC &yacute; \xFD &thorn; \xFE &yuml; \xFF
   }
   set content [string map $escapes $content]
   set content [string map [list "\]" "\\\]" "\[" "\\\[" "\$" "\\\$" "\\" "\\\\"] $content]
   regsub -all -- {&#([[:digit:]]{1,5});} $content {[format %c [string trimleft "\1" "0"]]} content
   regsub -all -- {&#x([[:xdigit:]]{1,4});} $content {[format %c [scan "\1" %x]]} content
   regsub -all -- {&#?[[:alnum:]]{2,7};} $content "?" content
   return [subst $content]
}

_________________
NON geeky!! http://gotcode4u.com/
Back to top
View user's profile Send private message Visit poster's website
Nash
Voice


Joined: 29 Jul 2012
Posts: 6

PostPosted: Fri Aug 03, 2012 8:22 pm    Post subject: Reply with quote

Hey, thanks for your reply aswell!
I'm good on this issue now. Thanks alot tho!! Smile
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 Requests 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