Advertisement
Guest User

Untitled

a guest
Jun 6th, 2014
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 11.58 KB | None | 0 0
  1. ##############################################################################################
  2. ## Note I used the proc and bits from RaZ's youtube and information script to grab the                                                                                 ##
  3. ## length and added it to fordlawnmower's youtube script. Formats in correct time due to                                                                              ##
  4. ## the proc from RaZ and regex from his script also. Thanks both of you!                                                                                                    ##
  5. ## ford's original script: http://hawkee.com/snippet/8519/                                                                                                                          ##
  6. ## RaZ'a original script: http://hawkee.com/snippet/8520/                                                                                                                          ##
  7. ## v00.02.02 changes, used some of fordlawnmowers code and some of RaZ's to clean the title and                                                                ##
  8. ## - properly display things like & and quotes, see cleantitle proc                                                                                                                ##
  9. ##  - also fix a typo and spacing issue with the output                                                                                                                                  ##
  10. ## v00.02.03 Changes;                                                                                                                                                                             ##
  11. ##  -HUGE thanks to black for helping with cleaning the title more, nothing should throw errors now or break the script if its in the title, thanks   ##
  12. ##    to doggo @egghelp for the $escapes.    (I also added a few symbols to the escapes-IEC)                                                                        ##
  13. ##  -Added ability to easily turn on or turn off certain things in the output, and also to output to the partyline or not
  14. ##############################################################################################
  15. ## To use this script you must set channel flag +youtubeURL (ie .chanset #chan +youtubeURL)                                                                      ##
  16. ##############################################################################################
  17. proc youtubesurl {nick host hand chan text} {
  18.     if {[lsearch -exact [channel info $chan] +youtubeURL] != -1} {
  19. ##############################################################################################
  20. #####                                                                                     Start Setup                                                                                          ####
  21. ##############################################################################################
  22. ##                                            Change the characters between the "" below to change the logo shown with each result.                                ##
  23.     set youtubelogo "\002\00301,00You\00300,04Tube\002\017"
  24. ##                                             Change the format codes between the "" below to change the color/state of the text.                                    ##
  25.     set textf "\002\017"
  26.     set tagcolor "\002"
  27.     set hostlang "en"
  28. ##                                                                   Set the things you want in the output here, 0 = off 1 = on                                                     ##
  29. ##                                                                                                  Title                                                                                                  ##
  30.     set y(youtubedesc) "1"
  31. ##                                                                                                 Views                                                                                                 ##
  32.     set y(youtubeviews) "1"
  33. ##                                                                                           number of likes                                                                                         ##
  34.     set y(youtubelikes) "1"
  35. ##                                                                                         number of dislikes                                                                                       ##
  36.     set y(youtubedislikes) "1"
  37. ##                                                                                          Uploaded by user                                                                                       ##
  38.     set y(youtubeuser) "1"
  39. ##                                                                                            date uploaded                                                                                          ##
  40.     set y(youtubedate) "1"
  41. ##                                                                                           length of video                                                                                          ##
  42.     set y(youtubelength) "1"
  43. ##                                                                         set debug mode to output to partychan                                                                         ##
  44.     set y(debug) "1"
  45. ##############################################################################################
  46. ####                                                                                       End Setup                                                                                            ####
  47. ##############################################################################################
  48.  
  49.  
  50.     set y(youtubefound) "0"
  51.     set youtubecheck [regexp -all -nocase {(?:\/watch\?v=|youtu\.be\/)([\d\w-]{11})} $text match youtubeid]
  52.     if {$youtubeid != ""} {
  53.       set youtubesite www.youtube.com
  54.       set youtubeurl "/watch?v=${youtubeid}&hl=${hostlang}"
  55.       set youtubeviews ""
  56.       set youtubedesc ""
  57.       set youtubeuser ""
  58.       set youtubelikes ""
  59.       set youtubedislikes ""
  60.       set youtubedate ""
  61.       set youtubelength ""
  62.       set youtubefound ""
  63.       set output ""
  64.       if {[catch {set youtubesock [socket -async $youtubesite 80]} sockerr]} {
  65.         putlog "$youtubesite $youtubeurl $sockerr error"
  66.         return 0
  67.       } else {
  68.         puts $youtubesock "GET $youtubeurl HTTP/1.0"
  69.         puts $youtubesock "Host: $youtubesite"
  70.         puts $youtubesock ""
  71.         flush $youtubesock
  72.         while {![eof $youtubesock]} {
  73.           set youtubevar " [gets $youtubesock] "
  74.           if {[regexp -nocase {<title>(.*?)\s-\sYouTube<\/title>} $youtubevar match youtubedesc]} {
  75.             set youtubedesc "${tagcolor}Title: ${textf}${youtubedesc}"
  76.           } elseif {[regexp -nocase {\/user\/(.*?)">} $youtubevar match youtubeuser]} {
  77.            set youtubeuser "${tagcolor}Uploader: ${textf}${youtubeuser}"
  78.          } elseif {[regexp -nocase {<span class="yt-user-name[^>]*>([^<]*)<} $youtubevar match youtubeuser]} {
  79.             set youtubeuser "${tagcolor}Uploader: ${textf}${youtubeuser}"
  80.           } elseif {[regexp -nocase {watch-view-count">([^\x20]*)\s.*<\/span>} $youtubevar match youtubeviews]} {
  81.            set youtubeviews "${tagcolor}Views: ${textf}${youtubeviews}"
  82.          } elseif {[regexp -nocase {\"likes-count\">(.*?)<} $youtubevar match youtubelikes]} {
  83.            set youtubelikes "${tagcolor}Likes: ${textf}${youtubelikes}"
  84.          } elseif {[regexp -nocase {"length_seconds": (\d+),} $youtubevar match youtubelength]} {
  85.             set youtubelength "${tagcolor}Length:${textf}[duration ${youtubelength}] "         
  86.             } elseif {$youtubefound == "found" && [regexp -nocase {<strong>.*on (.*?)<\/strong>} $youtubevar match youtubedate]} {
  87.            set youtubedate "${tagcolor}Uploaded: ${textf}${youtubedate}"
  88.            if {$y(youtubedesc)} { append output "[fixtext ${youtubedesc}]" }
  89.            if {$y(youtubeviews)} { append output "${youtubeviews} " }
  90.            if {$y(youtubelikes)} { append output "${youtubelikes} " }
  91.            if {$y(youtubedislikes)} { append output "${youtubedislikes} " }
  92.            if {$y(youtubeuser)} { append output "[fixtext ${youtubeuser}] " }
  93.            if {$y(youtubedate)} { append output "${youtubedate} " }
  94.            if {$y(youtubelength)} { append output "${youtubelength} " }
  95.            putserv "PRIVMSG $chan :[yturldehex "${youtubelogo} $output"]"  
  96.            close $youtubesock
  97.            return 0
  98.          } elseif {[regexp -nocase {\"dislikes-count\">(.*?)<} $youtubevar match youtubedislikes]} {
  99.            set youtubedislikes "${tagcolor}Dislikes: ${textf}${youtubedislikes}"
  100.          } elseif {[string match {*id="watch-uploader-info">*} $youtubevar]} {
  101.            set youtubefound "found"
  102.          } elseif {[regexp {<\/body>} $youtubevar 1] != 0} {
  103.            close $youtubesock
  104.            return 0
  105.          }
  106.        }
  107.        close $youtubesock
  108.        return 0
  109.      }
  110.    }
  111.  }
  112. }
  113. proc yturldehex {string} {
  114.  regsub -all {[\[\]]} $string "" string
  115.  set string [subst [regsub -nocase -all {\&#([0-9]{2});} $string {[format %c \1]}]]
  116.  return [string map {&quot; \" \xa0 ","} $string]
  117. }
  118. proc fixtext {data} {
  119. set escapes {
  120.   &nbsp; \x20 &quot; \x22 &amp; \x26 &apos; \x27 &ndash; \x2D
  121.   &lt; \x3C &gt; \x3E &tilde; \x7E &euro; \x80 &iexcl; \xA1
  122.   &cent; \xA2 &pound; \xA3 &curren; \xA4 &yen; \xA5 &brvbar; \xA6
  123.   &sect; \xA7 &uml; \xA8 &copy; \xA9 &ordf; \xAA &laquo; \xAB
  124.   &not; \xAC &shy; \xAD &reg; \xAE &hibar; \xAF &deg; \xB0
  125.   &plusmn; \xB1 &sup2; \xB2 &sup3; \xB3 &acute; \xB4 &micro; \xB5
  126.   &para; \xB6 &middot; \xB7 &cedil; \xB8 &sup1; \xB9 &ordm; \xBA
  127.   &raquo; \xBB &frac14; \xBC &frac12; \xBD &frac34; \xBE &iquest; \xBF
  128.   &Agrave; \xC0 &Aacute; \xC1 &Acirc; \xC2 &Atilde; \xC3 &Auml; \xC4
  129.   &Aring; \xC5 &AElig; \xC6 &Ccedil; \xC7 &Egrave; \xC8 &Eacute; \xC9
  130.   &Ecirc; \xCA &Euml; \xCB &Igrave; \xCC &Iacute; \xCD &Icirc; \xCE
  131.   &Iuml; \xCF &ETH; \xD0 &Ntilde; \xD1 &Ograve; \xD2 &Oacute; \xD3
  132.   &Ocirc; \xD4 &Otilde; \xD5 &Ouml; \xD6 &times; \xD7 &Oslash; \xD8
  133.   &Ugrave; \xD9 &Uacute; \xDA &Ucirc; \xDB &Uuml; \xDC &Yacute; \xDD
  134.   &THORN; \xDE &szlig; \xDF &agrave; \xE0 &aacute; \xE1 &acirc; \xE2
  135.   &atilde; \xE3 &auml; \xE4 &aring; \xE5 &aelig; \xE6 &ccedil; \xE7
  136.   &egrave; \xE8 &eacute; \xE9 &ecirc; \xEA &euml; \xEB &igrave; \xEC
  137.   &iacute; \xED &icirc; \xEE &iuml; \xEF &eth; \xF0 &ntilde; \xF1
  138.   &ograve; \xF2 &oacute; \xF3 &ocirc; \xF4 &otilde; \xF5 &ouml; \xF6
  139.   &divide; \xF7 &oslash; \xF8 &ugrave; \xF9 &uacute; \xFA &ucirc; \xFB
  140.   &uuml; \xFC &yacute; \xFD &thorn; \xFE &yuml; \xFF
  141.   }
  142. regsub -all -- \\\\ $data \\\\\\\\ data
  143. regsub -all -- \\\[ $data \\\\\[ data
  144. regsub -all -- \\\] $data \\\\\] data
  145. regsub -all -- \\\} $data \\\\\} data
  146. regsub -all -- \\\{ $data \\\\\{ data
  147. regsub -all -- \\\" $data \\\\\" data
  148. return [string map -nocase $escapes $data]
  149. }  
  150.  
  151. proc yturlencode {instring} {
  152.  return [subst [regsub -nocase -all {([^a-z0-9])} $instring {%[format %x [scan "\\&" %c]]}]]
  153. }
  154. proc duration {s} {
  155.     variable etube
  156.     set hours [expr {$s / 3600}]
  157.     set minutes [expr {($s / 60) % 60}]
  158.     set seconds [expr {$s % 60}]
  159.     set res ""
  160.  
  161.     if {$hours != 0} {append res "$hours hours"}               
  162.     if {$minutes != 0} {append res " $minutes minutes"}
  163.     if {$seconds != 0} {append res " $seconds seconds"}
  164.     return $res
  165.  
  166. }
  167. bind pubm -|- "*youtube.*watch?v=*" youtubesurl
  168. bind pubm -|- "*youtu.be/*" youtubesurl
  169. setudef flag youtubeURL
  170. putlog "\002*Loaded* \00301,00You\00300,04Tube\002\017 \002URL check V 00.02.03 by Ford_Lawnmower modified by ieatscrayons with help from black and RaZ"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement