Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##############################################################################################
- ## Note I used the proc and bits from RaZ's youtube and information script to grab the ##
- ## length and added it to fordlawnmower's youtube script. Formats in correct time due to ##
- ## the proc from RaZ and regex from his script also. Thanks both of you! ##
- ## ford's original script: http://hawkee.com/snippet/8519/ ##
- ## RaZ'a original script: http://hawkee.com/snippet/8520/ ##
- ## v00.02.02 changes, used some of fordlawnmowers code and some of RaZ's to clean the title and ##
- ## - properly display things like & and quotes, see cleantitle proc ##
- ## - also fix a typo and spacing issue with the output ##
- ## v00.02.03 Changes; ##
- ## -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 ##
- ## to doggo @egghelp for the $escapes. (I also added a few symbols to the escapes-IEC) ##
- ## -Added ability to easily turn on or turn off certain things in the output, and also to output to the partyline or not
- ##############################################################################################
- ## To use this script you must set channel flag +youtubeURL (ie .chanset #chan +youtubeURL) ##
- ##############################################################################################
- proc youtubesurl {nick host hand chan text} {
- if {[lsearch -exact [channel info $chan] +youtubeURL] != -1} {
- ##############################################################################################
- ##### Start Setup ####
- ##############################################################################################
- ## Change the characters between the "" below to change the logo shown with each result. ##
- set youtubelogo "\002\00301,00You\00300,04Tube\002\017"
- ## Change the format codes between the "" below to change the color/state of the text. ##
- set textf "\002\017"
- set tagcolor "\002"
- set hostlang "en"
- ## Set the things you want in the output here, 0 = off 1 = on ##
- ## Title ##
- set y(youtubedesc) "1"
- ## Views ##
- set y(youtubeviews) "1"
- ## number of likes ##
- set y(youtubelikes) "1"
- ## number of dislikes ##
- set y(youtubedislikes) "1"
- ## Uploaded by user ##
- set y(youtubeuser) "1"
- ## date uploaded ##
- set y(youtubedate) "1"
- ## length of video ##
- set y(youtubelength) "1"
- ## set debug mode to output to partychan ##
- set y(debug) "1"
- ##############################################################################################
- #### End Setup ####
- ##############################################################################################
- set y(youtubefound) "0"
- set youtubecheck [regexp -all -nocase {(?:\/watch\?v=|youtu\.be\/)([\d\w-]{11})} $text match youtubeid]
- if {$youtubeid != ""} {
- set youtubesite www.youtube.com
- set youtubeurl "/watch?v=${youtubeid}&hl=${hostlang}"
- set youtubeviews ""
- set youtubedesc ""
- set youtubeuser ""
- set youtubelikes ""
- set youtubedislikes ""
- set youtubedate ""
- set youtubelength ""
- set youtubefound ""
- set output ""
- if {[catch {set youtubesock [socket -async $youtubesite 80]} sockerr]} {
- putlog "$youtubesite $youtubeurl $sockerr error"
- return 0
- } else {
- puts $youtubesock "GET $youtubeurl HTTP/1.0"
- puts $youtubesock "Host: $youtubesite"
- puts $youtubesock ""
- flush $youtubesock
- while {![eof $youtubesock]} {
- set youtubevar " [gets $youtubesock] "
- if {[regexp -nocase {<title>(.*?)\s-\sYouTube<\/title>} $youtubevar match youtubedesc]} {
- set youtubedesc "${tagcolor}Title: ${textf}${youtubedesc}"
- } elseif {[regexp -nocase {\/user\/(.*?)">} $youtubevar match youtubeuser]} {
- set youtubeuser "${tagcolor}Uploader: ${textf}${youtubeuser}"
- } elseif {[regexp -nocase {<span class="yt-user-name[^>]*>([^<]*)<} $youtubevar match youtubeuser]} {
- set youtubeuser "${tagcolor}Uploader: ${textf}${youtubeuser}"
- } elseif {[regexp -nocase {watch-view-count">([^\x20]*)\s.*<\/span>} $youtubevar match youtubeviews]} {
- set youtubeviews "${tagcolor}Views: ${textf}${youtubeviews}"
- } elseif {[regexp -nocase {\"likes-count\">(.*?)<} $youtubevar match youtubelikes]} {
- set youtubelikes "${tagcolor}Likes: ${textf}${youtubelikes}"
- } elseif {[regexp -nocase {"length_seconds": (\d+),} $youtubevar match youtubelength]} {
- set youtubelength "${tagcolor}Length:${textf}[duration ${youtubelength}] "
- } elseif {$youtubefound == "found" && [regexp -nocase {<strong>.*on (.*?)<\/strong>} $youtubevar match youtubedate]} {
- set youtubedate "${tagcolor}Uploaded: ${textf}${youtubedate}"
- if {$y(youtubedesc)} { append output "[fixtext ${youtubedesc}]" }
- if {$y(youtubeviews)} { append output "${youtubeviews} " }
- if {$y(youtubelikes)} { append output "${youtubelikes} " }
- if {$y(youtubedislikes)} { append output "${youtubedislikes} " }
- if {$y(youtubeuser)} { append output "[fixtext ${youtubeuser}] " }
- if {$y(youtubedate)} { append output "${youtubedate} " }
- if {$y(youtubelength)} { append output "${youtubelength} " }
- putserv "PRIVMSG $chan :[yturldehex "${youtubelogo} $output"]"
- close $youtubesock
- return 0
- } elseif {[regexp -nocase {\"dislikes-count\">(.*?)<} $youtubevar match youtubedislikes]} {
- set youtubedislikes "${tagcolor}Dislikes: ${textf}${youtubedislikes}"
- } elseif {[string match {*id="watch-uploader-info">*} $youtubevar]} {
- set youtubefound "found"
- } elseif {[regexp {<\/body>} $youtubevar 1] != 0} {
- close $youtubesock
- return 0
- }
- }
- close $youtubesock
- return 0
- }
- }
- }
- }
- proc yturldehex {string} {
- regsub -all {[\[\]]} $string "" string
- set string [subst [regsub -nocase -all {\&#([0-9]{2});} $string {[format %c \1]}]]
- return [string map {" \" \xa0 ","} $string]
- }
- proc fixtext {data} {
- set escapes {
- \x20 " \x22 & \x26 ' \x27 – \x2D
- < \x3C > \x3E ˜ \x7E € \x80 ¡ \xA1
- ¢ \xA2 £ \xA3 ¤ \xA4 ¥ \xA5 ¦ \xA6
- § \xA7 ¨ \xA8 © \xA9 ª \xAA « \xAB
- ¬ \xAC ­ \xAD ® \xAE &hibar; \xAF ° \xB0
- ± \xB1 ² \xB2 ³ \xB3 ´ \xB4 µ \xB5
- ¶ \xB6 · \xB7 ¸ \xB8 ¹ \xB9 º \xBA
- » \xBB ¼ \xBC ½ \xBD ¾ \xBE ¿ \xBF
- À \xC0 Á \xC1 Â \xC2 Ã \xC3 Ä \xC4
- Å \xC5 Æ \xC6 Ç \xC7 È \xC8 É \xC9
- Ê \xCA Ë \xCB Ì \xCC Í \xCD Î \xCE
- Ï \xCF Ð \xD0 Ñ \xD1 Ò \xD2 Ó \xD3
- Ô \xD4 Õ \xD5 Ö \xD6 × \xD7 Ø \xD8
- Ù \xD9 Ú \xDA Û \xDB Ü \xDC Ý \xDD
- Þ \xDE ß \xDF à \xE0 á \xE1 â \xE2
- ã \xE3 ä \xE4 å \xE5 æ \xE6 ç \xE7
- è \xE8 é \xE9 ê \xEA ë \xEB ì \xEC
- í \xED î \xEE ï \xEF ð \xF0 ñ \xF1
- ò \xF2 ó \xF3 ô \xF4 õ \xF5 ö \xF6
- ÷ \xF7 ø \xF8 ù \xF9 ú \xFA û \xFB
- ü \xFC ý \xFD þ \xFE ÿ \xFF
- }
- regsub -all -- \\\\ $data \\\\\\\\ data
- regsub -all -- \\\[ $data \\\\\[ data
- regsub -all -- \\\] $data \\\\\] data
- regsub -all -- \\\} $data \\\\\} data
- regsub -all -- \\\{ $data \\\\\{ data
- regsub -all -- \\\" $data \\\\\" data
- return [string map -nocase $escapes $data]
- }
- proc yturlencode {instring} {
- return [subst [regsub -nocase -all {([^a-z0-9])} $instring {%[format %x [scan "\\&" %c]]}]]
- }
- 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
- }
- bind pubm -|- "*youtube.*watch?v=*" youtubesurl
- bind pubm -|- "*youtu.be/*" youtubesurl
- setudef flag youtubeURL
- 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