Advertisement
Guest User

Untitled

a guest
Mar 14th, 2017
988
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 3.29 KB | None | 0 0
  1.  
  2.  
  3.         ##############
  4.         #    Zurl    #
  5.         ##############
  6.          
  7.         ############## Zurl.tcl is based on two grabbers urls titles scripts:
  8.         ############## -The first one is a classic grabber who gets all (or most) of urls.
  9.         ############## (http://forum.eggdrop.fr/Titre-des-urls-diffusees-t-1331.html)
  10.         ############## - The second one is a youtube grabber.
  11.         ############## (http://forum.eggdrop.fr/youtube-tiltle-t-1393.html)
  12.         ##############
  13.         ############## So, the youtube and the classic grabber titles on
  14.         ############## one script was the point. I hope it'll be usefull.
  15.         ##############
  16.         ############## Easy to use; you only need to:
  17.         ############## - add the Zurl.tcl file in ../scripts/
  18.         ############## - add the line "source scripts/zurl.tcl" in eggdrop.conf
  19.         ############## - and enjoy.
  20.         ##############
  21.         ############## JazZ (jazz@epiknet.org)
  22.          
  23.         ##############
  24.         #   Script   #
  25.         ##############
  26.          
  27.         set Zurlversion "1.0"
  28.          
  29.         ############## Binds/Packages
  30.          
  31.         package require http
  32.         package require uri
  33.         package require tls
  34.          
  35.         tls::init -tls1 true -ssl2 false -ssl3 false
  36.         http::register https 443 tls::socket
  37.          
  38.         bind PUBM - * check_url
  39.          
  40.         ############## Classic Proc
  41.          
  42.         proc check_url {nick uhost handle chan text} {
  43.                 if {![string match "*?://*?" $text]} {
  44.                         set text "http://$text"
  45.                 }
  46.                 if {[regexp -- {([a-z0-9\-]+\://[a-z0-9\-]+\.[a-z0-9\-\.]+(?:/|(?:/[a-zA-Z0-9!#\$%&'\*\+,\-\.:;=\?@\[\]_~]+)*))} $text match url]} {
  47.                         if {[string match -nocase "*?/watch?v=*?" $url] || [string match -nocase "*?://youtu.be*?" $url]} {
  48.                                 return [get_ytube $chan $url]
  49.                         } else {
  50.                                 set url [string tolower $url]
  51.                                 set url [string map -nocase { "&" "&" } $url]
  52.                                 set token [geturl $url]
  53.                                 set html_data [::http::data $token]
  54.                                 ::http::cleanup $token
  55.                                 regexp -all -nocase -- "<title>(.*)</title>" $html_data match title
  56.                                 putserv "PRIVMSG $chan .: \002URL\002 :. '[html_entities_decode $title]'"
  57.                         }
  58.                 }
  59.                 return 0
  60.         }
  61.          
  62.         proc geturl {url args} {
  63.             array set URI [::uri::split $url];
  64.             while {1} {
  65.                set token [eval [list http::geturl $url] $args]
  66.                if {![string match {30[1237]} [::http::ncode $token]]} {return $token}
  67.                array set meta [set ${token}(meta)]
  68.                if {![info exist meta(Location)]} {
  69.                     return $token
  70.                }
  71.                array set uri [::uri::split $meta(Location)]
  72.                unset meta
  73.                if {$uri(host) == ""} { set uri(host) $URI(host) }
  74.                set url [eval ::uri::join [array get uri]]
  75.             }
  76.         }      
  77.         putlog "Zurl-$Zurlversion.tcl loaded"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement