Yet Another Youtube Title grabber

By TehJibba on Feb 24, 2012

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
  }
}

Comments

Sign in to comment.
Spinti89   -  Jul 13, 2014

How can i make this work with echo ? But i don't want to echo to the active chan, insted i want it to echo in the chan or query that the link was given...
Can someone help me ?

 Respond  
Rfsancho   -  Jun 22, 2013

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.

 Respond  
dreamphreak2   -  Aug 04, 2012

A warning, do not private message yourself with a youtube link, or else you get infinite spam and have to restart irc client.

 Respond  
  -  Feb 27, 2012

I had copied it wrong, it works thank you for sharing it.

 Respond  
TehJibba   -  Feb 27, 2012

all mine grabs is the id of the video after v= no matter where v= is for normal links or anything after / for the short urls. it should work for you as well just fine :) and ty :)

 Respond  
  -  Feb 27, 2012

lol at of all the videos that is the first one to fail LOL saddly for me the fix for you is not what I need, Mine has to be the the id in order to work in my script.. (U) now I have to fix that LOL... great job glad that you got it done looks awesome

 Respond  
TehJibba   -  Feb 27, 2012

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

 Respond  
  -  Feb 26, 2012

glad I could help, and yes the pattern will work for all the types of youtube urls I use this in my own script for my webchat to be able to watch the vidoes check out my profile to look at the screenshot

 Respond  
TehJibba   -  Feb 26, 2012

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 :)

 Respond  
  -  Feb 25, 2012

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;amp;,$chr(38),&amp;#39;,$chr(39),&#39;,$chr(39),&amp;quot;,$chr(34),&quot;,$chr(34),&amp;,$chr(38))
    sockclose yt
} }

you dont need the vars, Good idea on the replace tho you only need it once.

 Respond  
  -  Feb 25, 2012

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,

  • Edit due to my rudeness of not giving props to a good job.
 Respond  
ProIcons   -  Feb 25, 2012
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;amp;,$chr(38)),&amp;#39;,$chr(39)),&#39;,$chr(39)),&amp;quot;,$chr(34)),&quot;,$chr(34)),&amp;,$chr(38)) | /unset %yt.*  }
  }
}
 Respond  
ProIcons   -  Feb 25, 2012

Don't need to have 2 Codes,
this Covers and Queries, and Channel Texts.

 Respond  
FelicianoX   -  Feb 24, 2012

Just copy paste a YouTube link in the channel and it will trigger @ Eminama

 Respond  
EminamaDron   -  Feb 24, 2012

lol but how the hell do you access it?

 Respond  
TehJibba   -  Feb 24, 2012

Ty for the update. ill test it out and then edit the post :)

 Respond  
ProIcons   -  Feb 24, 2012

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 }
}

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.