just a simple channel and pm youtube title grabber. just paste this in your remotes and any youtube url will be parsed for its title.
*** I realize there is a huge replace line in the script. if anyone can suggest an easier or better way to replace html ascii or a better way of going about this i welcome your comments. The script is still functional and nearly instant. Ive been getting same second replies.
Tested and added ProIcons line to it. good call on the shortlink catcher
****This is meant to be put on a bot. when someone posts a youtube link either in the channel or in pm it will grab the title @ EminamaDron
UPDATE 2/27/2012
Ok so to start credits to MakiMaki for the no var's version posted. After extensive testing and reworking this is the finalized version. A major thanks goes to my m8 ex0a for an improved regex and alias to eliminate the need for a loop.
This new version will now properly grab any number of youtube url's posted in the channel or pm no matter how fast they are posted and will return the title for each one with a youtube shorturl for each as well. I would highly recommend putting a spam protection on it.
;-------------------------------------------;
; Youtube Title Grabber ;
;-------------------------------------------;
alias -l sockopenmark { sockopen $1-3 | sockmark $1 $4- }
on $*:text:/(youtube\.com)\/.*v=([^&]+)|(youtu\.be)\/(.+)/Si:*: {
sockopenmark $+(yt.,$calc($ticks + $rand(1,99))) www.youtube.com 80 $regml(2) msg $iif($chan,$v1,$nick) $+($chr(02),$chr(03),01,$chr(44),00,You,$chr(3),00,$chr(44),04,Tube,$chr(3)) $+($chr(02),@,$chr(32),$chr(31),http://youtu.be/,$regml(2))
}
on *:sockopen:yt.*:{
tokenize 32 $sock($sockname).mark
sockwrite -n $sockname GET /watch?v= $+ $1 HTTP/1.0
sockwrite -n $sockname HOST: www.youtube.com $+ $str($crlf,2)
}
on *:sockread:yt.*:{
var %v | sockread %v
if ($regex(%v,/"name" content="(.+)"/)) {
tokenize 32 $sock($sockname).mark
$2-4 $replace($regml(1),&,$chr(38),',$chr(39),',$chr(39),",$chr(34),",$chr(34),&,$chr(38)) $5-
sockclose $sockname
}
}
Doesn't seem to respond when there is anything written after the link.
[21:49:48] <@user> http://www.youtube.com/watch?v=7kuUHEyCV9g
[21:49:48] <&bot> YouTube Maximum Destruction DOUBLE BACKFLIP ENCORE http://youtu.be/7kuUHEyCV9g
[21:50:01] <@user> test http://www.youtube.com/watch?v=7kuUHEyCV9g
[21:50:02] <&bot> YouTube Maximum Destruction DOUBLE BACKFLIP ENCORE http://youtu.be/7kuUHEyCV9g
[21:50:08] <@user> test http://www.youtube.com/watch?v=7kuUHEyCV9g test test
[21:50:17] <@user> test http://youtu.be/7kuUHEyCV9g test test
[21:50:30] <@user> :<
Though responds perfectly fine to anything as long as the link is last.
major update posted. bugs fixed and completely redone the code :)
@ MakiMaki First let me say thank you for posting the no vars version i love it and it works great. But your regex was a bit flawed as it would catch: OAAAAAAAAAA in: http://www.youtube.com/watch?feature=g-logo&v=BqMIGC1tx3s&context=G2747d50FOAAAAAAAAAA
the new regex corrects this :)
TY to everyones post. still waiting to see someone come up with a better way to do the $replace tho :D
Nice guys thank you all for your suggestions. i will test and implement the changes today.
@ ProIcons i only seperated it out as the pm one isnt really for a bot you can put it into your personal remotes and use it to grab urls pm'd to you. but yes combining them is doable.
@MakiMaki ty for the new regex lines. Im fairly new at using regex , als youtube has been messing with the url formating so all i want to grab is whats after v= no matter where it is in the url. if that regex does it ( at the time of writing this i havent tested) then sweet ill use it.
As for the replace line i couldnt think of a better/simpler way to do it and i tried to do just one and it threw out error's on me and i couldnt get it to work so i just did multiples. ty for showing me how to use just one :)
Just playing with it some..
on $*:text:/(youtube.com|youtu.be)\/(.*|v=)?([\w-]{11})/Si:*: {
if ($sock(yt)) { sockclose yt }
sockopen yt www.youtube.com 80
sockmark yt $regml(3) msg $iif($chan,$v1,$nick) $+(You,$chr(3),0,$chr(44),04,Tube,$chr(3)) Title:
}
on *:sockopen:yt:{
tokenize 32 $sock(yt).mark
sockwrite -n yt GET /watch?v= $+ $1 HTTP/1.1
sockwrite -n yt HOST: www.youtube.com $+ $str($crlf,2)
}
on *:sockread:yt:{
var %v
sockread %v
tokenize 32 $sock(yt).mark
if ($regex(%v,/"name" content="(.+)"/)) {
$2- $replace($regml(1),&amp;,$chr(38),&#39;,$chr(39),',$chr(39),&quot;,$chr(34),",$chr(34),&,$chr(38))
sockclose yt
} }
you dont need the vars, Good idea on the replace tho you only need it once.
Here is a regex pattern to use for your event triggers
on $*:text:/(youtube.com|youtu.be)\/(.*|v=)?([\w-]{11})/Si:#: { your code }
on $*:text:/(youtube.com|youtu.be)\/(.*|v=)?([\w-]{11})/Si:?: { your code }
;youtube id = $regml(3)
Nice job none the less,
on *:text:*:*: {
if ($regex($1-,/youtube.com.*v=([^&]+)/)) { /set %yt.target $iif($chan,$v1,$nick) | /set %yt.url /watch?v= $+ $regml(1) | /sockclose yt | /sockopen yt youtube.com 80 }
if ($regex($1-,/youtu.be.([^/]+[^/])/)) { /set %yt.target $iif($chan,$v1,$nick) | /set %yt.url /watch?v= $+ $regml(1) | /sockclose yt | /sockopen yt youtube.com 80 }
}
;-------------------------------------------;
; Socket for yt title ;
;-------------------------------------------;
on *:SOCKOPEN:yt: {
sockwrite -n $sockname GET %yt.url HTTP/1.1
sockwrite -n $sockname Host: www.youtube.com
sockwrite -n $sockname User-Agent: IRCSpider/mIRC $version
sockwrite -n $sockname Accept: *.*, */*
sockwrite -n $sockname Referer: $server
sockwrite -n $sockname Connection: Keep-Alive
sockwrite -n $sockname Content-Type: text/html
sockwrite -n $sockname $crlf
}
on *:SOCKREAD:yt: {
/var %yt.temp | /sockread %yt.temp
if ($regex(%yt.temp,/<meta name="title" content="(.*?)">/)) {
/set %yt.title $regml(1)
if (%yt.target != $null) { /sockclose yt | /msg %yt.target 1,0You0,4Tube14,1: $replace($replace($replace($replace($replace($replace(%yt.title,&amp;,$chr(38)),&#39;,$chr(39)),',$chr(39)),&quot;,$chr(34)),",$chr(34)),&,$chr(38)) | /unset %yt.* }
}
}
on :text::: {
if ($regex($1-,/youtube.com.v=([^&]+)/)) { /set %yt.chan $iif($chan,$v1,$nick) | /set %yt.url /watch?v= $+ $regml(1) | /sockclose yt | /sockopen yt youtube.com 80 }
if ($regex($1-,/youtu.be.([^/]+[^/])/)) { /set %yt.chan $iif($chan,$v1,$nick) | /set %yt.url /watch?v= $+ $regml(1) | /sockclose yt | /sockopen yt youtube.com 80 }
}