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/ ##
- ## v2 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 ##
- ##############################################################################################
- ## To use this script you must set channel flag +youtubeURL (ie .chanset #chan +youtubeURL) ##
- ##############################################################################################
- ##############################################################################################
- ## ## Start Setup. ## ##
- ##############################################################################################
- proc youtubesurl {nick host hand chan text} {
- if {[lsearch -exact [channel info $chan] +youtubeURL] != -1} {
- ## 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"
- ##############################################################################################
- ## ## End Setup. ## ##
- ##############################################################################################
- 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 ""
- 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>(.*)<\/strong>} $youtubevar match youtubedate]} {
- set youtubedate "${tagcolor}Uploaded: ${textf}${youtubedate}"
- putserv "PRIVMSG $chan :[yturldehex "${youtubelogo} [cleantitle ${youtubedesc}] ${youtubeviews} ${youtubelikes} ${youtubedislikes} ${youtubeuser} ${youtubedate} ${youtubelength}"]"
- 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 cleantitle {string} {
- regsub -all {<.*?>} $string "" string
- set string [subst [regsub -nocase -all {\&#([0-9]{2});} $string {[format %c \1]}]]
- return [string map -nocase {\&\#39; \x27 & \x26 " \x22} $string]
- }
- 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 by Ford_Lawnmower irc.GeekShed.net #Script-Help"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement