Skip to content

Instantly share code, notes, and snippets.

@tuxity
Created March 6, 2012 12:40
Show Gist options
  • Save tuxity/1986067 to your computer and use it in GitHub Desktop.
Save tuxity/1986067 to your computer and use it in GitHub Desktop.
Display video name with youtube logo when there is a youtube link.
bind pubm -|- "*youtube.*watch*v=*" youtubesurl
proc youtubesurl {nick host hand chan text} {
set youtubelogo "\002\00301,00You\00300,04Tube\002\017"
set textf "\002\017"
set youtubecheck [regexp -all -nocase {(v=[\d\w-]{11})} $text youtubeid]
if {$youtubeid != ""} {
set youtubesite www.youtube.com
set youtubeurl "/watch?$youtubeid"
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 "User-Agent: Opera 9.6"
puts $youtubesock ""
flush $youtubesock
while {![eof $youtubesock]} {
set youtubedesc ""
set youtubevar " [gets $youtubesock] "
set youtubedesc [regexp -all -nocase -inline {<meta name="title" content="(.*)">} $youtubevar]
if {$youtubedesc != ""} {
putserv "PRIVMSG $chan :$youtubelogo [yturldehex ${textf}[lindex $youtubedesc 1]]"
close $youtubesock
return 0
} elseif {[regexp {</head>} $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 {&quot; \"} $string]
}
proc yturlencode {instring} {
return [subst [regsub -nocase -all {([^a-z0-9])} $instring {%[format %x [scan "\\&" %c]]}]]
}
putlog "Loaded youtubeURL by Ford_Lawnmower and modify by Flemzard ..."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment