Advertisement
Guest User

fordlawnmower + RaZ youtube script length mod v2

a guest
May 19th, 2014
737
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 6.21 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. ## v2 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. ##############################################################################################
  11. ## To use this script you must set channel flag +youtubeURL (ie .chanset #chan +youtubeURL) ##
  12. ##############################################################################################
  13. ##############################################################################################
  14. ##  ##                             Start Setup.                                         ##  ##
  15. ##############################################################################################
  16. proc youtubesurl {nick host hand chan text} {
  17.   if {[lsearch -exact [channel info $chan] +youtubeURL] != -1} {
  18. ## Change the characters between the "" below to change the logo shown with each result.    ##
  19.     set youtubelogo "\002\00301,00You\00300,04Tube\002\017"
  20. ## Change the format codes between the "" below to change the color/state of the text.      ##
  21.     set textf "\002\017"
  22.     set tagcolor "\002"
  23.     set hostlang "en"
  24. ##############################################################################################
  25. ##  ##                           End Setup.                                              ## ##
  26. ##############################################################################################
  27.     set youtubecheck [regexp -all -nocase {(?:\/watch\?v=|youtu\.be\/)([\d\w-]{11})} $text match youtubeid]
  28.     if {$youtubeid != ""} {
  29.       set youtubesite www.youtube.com
  30.       set youtubeurl "/watch?v=${youtubeid}&hl=${hostlang}"
  31.       set youtubeviews ""
  32.       set youtubedesc ""
  33.       set youtubeuser ""
  34.       set youtubelikes ""
  35.       set youtubedislikes ""
  36.       set youtubedate ""
  37.       set youtubelength ""
  38.       set youtubefound ""
  39.       if {[catch {set youtubesock [socket -async $youtubesite 80]} sockerr]} {
  40.         putlog "$youtubesite $youtubeurl $sockerr error"
  41.         return 0
  42.       } else {
  43.         puts $youtubesock "GET $youtubeurl HTTP/1.0"
  44.         puts $youtubesock "Host: $youtubesite"
  45.         puts $youtubesock ""
  46.         flush $youtubesock
  47.         while {![eof $youtubesock]} {
  48.           set youtubevar " [gets $youtubesock] "
  49.           if {[regexp -nocase {<title>(.*?)\s-\sYouTube<\/title>} $youtubevar match youtubedesc]} {
  50.             set youtubedesc "${tagcolor}Title: ${textf}${youtubedesc}"
  51.           } elseif {[regexp -nocase {\/user\/(.*?)">} $youtubevar match youtubeuser]} {
  52.            set youtubeuser "${tagcolor}Uploader: ${textf}${youtubeuser}"
  53.          } elseif {[regexp -nocase {<span class="yt-user-name[^>]*>([^<]*)<} $youtubevar match youtubeuser]} {
  54.             set youtubeuser "${tagcolor}Uploader: ${textf}${youtubeuser}"
  55.           } elseif {[regexp -nocase {watch-view-count">([^\x20]*)\s.*<\/span>} $youtubevar match youtubeviews]} {
  56.            set youtubeviews "${tagcolor}Views: ${textf}${youtubeviews}"
  57.          } elseif {[regexp -nocase {\"likes-count\">(.*?)<} $youtubevar match youtubelikes]} {
  58.            set youtubelikes "${tagcolor}Likes: ${textf}${youtubelikes}"
  59.          } elseif {[regexp -nocase {"length_seconds": (\d+),} $youtubevar match youtubelength]} {
  60.             set youtubelength "${tagcolor}Length:${textf}[duration ${youtubelength}] "         
  61.             } elseif {$youtubefound == "found" && [regexp -nocase {<strong>(.*)<\/strong>} $youtubevar match youtubedate]} {
  62.            set youtubedate "${tagcolor}Uploaded: ${textf}${youtubedate}"
  63.            putserv "PRIVMSG $chan :[yturldehex "${youtubelogo} [cleantitle ${youtubedesc}] ${youtubeviews} ${youtubelikes} ${youtubedislikes} ${youtubeuser} ${youtubedate} ${youtubelength}"]"  
  64.            close $youtubesock
  65.            return 0
  66.          } elseif {[regexp -nocase {\"dislikes-count\">(.*?)<} $youtubevar match youtubedislikes]} {
  67.            set youtubedislikes "${tagcolor}Dislikes: ${textf}${youtubedislikes}"
  68.          } elseif {[string match {*id="watch-uploader-info">*} $youtubevar]} {
  69.            set youtubefound "found"
  70.          } elseif {[regexp {<\/body>} $youtubevar 1] != 0} {
  71.            close $youtubesock
  72.            return 0
  73.          }
  74.        }
  75.        close $youtubesock
  76.        return 0
  77.      }
  78.    }
  79.  }
  80. }
  81. proc yturldehex {string} {
  82.  regsub -all {[\[\]]} $string "" string
  83.  set string [subst [regsub -nocase -all {\&#([0-9]{2});} $string {[format %c \1]}]]
  84.  return [string map {&quot; \" \xa0 ","} $string]
  85. }
  86.    
  87. proc cleantitle {string} {
  88.  regsub -all {<.*?>} $string "" string
  89.  set string [subst [regsub -nocase -all {\&#([0-9]{2});} $string {[format %c \1]}]]
  90.  return [string map -nocase {\&\#39; \x27 &amp; \x26 &quot; \x22} $string]
  91. }
  92. proc yturlencode {instring} {
  93.  return [subst [regsub -nocase -all {([^a-z0-9])} $instring {%[format %x [scan "\\&" %c]]}]]
  94. }
  95. proc duration {s} {
  96.     variable etube
  97.     set hours [expr {$s / 3600}]
  98.     set minutes [expr {($s / 60) % 60}]
  99.     set seconds [expr {$s % 60}]
  100.     set res ""
  101.  
  102.     if {$hours != 0} {append res "$hours hours"}               
  103.     if {$minutes != 0} {append res " $minutes minutes"}
  104.     if {$seconds != 0} {append res " $seconds seconds"}
  105.     return $res
  106.  
  107. }
  108. bind pubm -|- "*youtube.*watch?v=*" youtubesurl
  109. bind pubm -|- "*youtu.be/*" youtubesurl
  110. setudef flag youtubeURL
  111. putlog "\002*Loaded* \00301,00You\00300,04Tube\002\017 \002URL check V 00.02 by Ford_Lawnmower irc.GeekShed.net #Script-Help"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement