Youtube Link Information --WORKING--

By thejman on Feb 22, 2011

Screenshots

It took me a long time to get this working, but it finally does!

It shows information of a youtube video, when posting a youtube link.

It shows, Title + Views + User that posted the video + Rating and positive/negative votes.

This Script works for DUTCH users.

Didn't test on English.

;;;;;;;;;;;;;;;;;*YOUTUBE* info script by Thejman;;;;;;;;;;;;;;;;;;;;;;
on *:TEXT:*youtube.com/watch?v=*:#: {
  if (!$sock(youtube)) {
    noop $regex($strip($1-),http:\/\/.*youtube.*\/watch\?v=(.{11})&?.*)
    sockopen youtube www.youtube.com 80 | sockmark youtube $+(#,>,$regml(1))
  }
}

on *:SOCKOPEN:youtube: {
  sockwrite -n $sockname GET $+(/watch?v=,$gettok($sock(youtube).mark,2,62)) HTTP/1.0
  sockwrite -n $sockname Host: www.youtube.com
  sockwrite -n $sockname $crlf
}

on *:SOCKREAD:youtube: {
  var %ytx | sockread %ytx
  if ($regex(%ytx,<meta name="title" content="(.+)">))  set %yttitle $regml(1)
  elseif ($regex(%ytx,<strong>(\d+)</strong>))  set %ytviews $regml(1)
  elseif ($regex(%ytx,<span class="likes">(.+)</span>\s))  set %ytpos $regml(1)
  elseif ($regex(%ytx,<a id="watch-username" class="inline-block" rel="author" href="/user/(.+)">))  set %ytuser $regml(1)
  elseif ($regex(%yty,(\d+) stemmen voor niet leuk))  set %ytneg $regml(1) 
  var %yty $regsub(%ytx,/<[^<>]+>/g,$null,%yty)
}

on *:SOCKCLOSE:youtube: {
  set %ytrate $int($calc((%ytpos / (%ytpos + %ytneg)) * 100))
  msg $chan $chr(91) $+ 1,0You0,4Tube $+ $chr(93) $chr(34) $+ $replace(%yttitle,&amp;quot;,$chr(34),&amp;#39;,$chr(39)) $+ $chr(34) - Viewed: %ytviews $+ x - User: %ytuser - Rating: %ytrate $+ $chr(37) - Positive: %ytpos Negative: %ytneg
  unset %yt*
}
;;;;;;;;;;;;;;;;;*YOUTUBE* info script by Thejman;;;;;;;;;;;;;;;;;;;;;;

Comments

Sign in to comment.
bone282   -  Feb 25, 2011

jethro, 99% of all youtube snippets on here are obselete, im well aware how easy scraping html is... have you checked a youtube page source lately? half of the data you want is nested in lengthy functions
did you even check the google youtube api jethro?

 Respond  
Jethro   -  Feb 25, 2011

The main challenge may be something like this:

The string you want to match Where the string you want to match is sandwiched between two tags. But that shouldn't be a problem with regex, as it supports multi-line mode...
 Respond  
bone282   -  Feb 25, 2011

i know youtube is changing its html all the time, and parsing it is becoming harder.
One alternative to get youtube info cleanly, from a more stable source is googles own youtube api
http://code.google.com/apis/youtube/2.0/developers_guide_protocol.html

but the real challenge lies in someone making their own json_decode alias. but hell, you could just regex match the json string instead.
heres an example url for one result. and the query = the youtube url
http://gdata.youtube.com/feeds/api/videos?q=http://www.youtube.com/watch?v=Nrm8-vnSEfc&start-index=1&max-results=1&v=2&alt=json

ps: json services are very fast indeed
have phun.

 Respond  
Jethro   -  Feb 23, 2011

thejman's script needs to change > msg $chanto

msg $gettok($sock(youtube).mark,1,62)

because the $chan returns $null within the socket routine. It's not a perfect, workable script if you don't mind the leftover html strings in the output. Regardless, one nice thing about jman's is that it works on every youtube link.

 Respond  
blackvenomm666   -  Feb 23, 2011

don't use the rewrites use the original version that thejman posted

 Respond  
Callumlord   -  Feb 23, 2011

I am having some problems with this, its not showing the info when a youtube link is posted.

 Respond  
Jethro   -  Feb 23, 2011

joelp54, you have my comments confused for an argument rather than a constructive criticism. Argument is not what I've had in mind.

 Respond  
joelp54   -  Feb 23, 2011

Jethro_ And DEAN You two need to kiss and make up lol, Every comment is you two arguing not really what people want to see while browsing for snippets, Just My Opinion Don't hate on me BTW lol :-)

 Respond  
Jethro   -  Feb 23, 2011

Never mind of this comment.

 Respond  
Jethro   -  Feb 23, 2011

Also, you close the socket via sockread, your sockclose event won't activate because the socket has been closed.

You have to remember this, Dean: > The sockclose event is triggered when a connection is closed by the remote connection (not you).

 Respond  
Jethro   -  Feb 23, 2011

Dean,the latest edit is deemed nonfunctional...:/ Just as Orion has said and I'm using mIRC v7.17

 Respond  
blackvenomm666   -  Feb 22, 2011

or maybe how to use the edit feature to add more to a previous comment?

 Respond  
Orion   -  Feb 22, 2011

i tested it on 6.2 mirc... one day i will learn to post all in one comment -.- sorry again

 Respond  
Orion   -  Feb 22, 2011

norhing ocurred, still not working.. im sorry

05:38:51 :       No|Over ¦ http://www.youtube.com/watch?v=artTgg_gxZw
05:39:35 :       No|Over ¦ http://www.youtube.com/watch?v=artTgg_gxZw
05:41:00 :       No|Over ¦ http://www.youtube.com/watch?v=Nrm8-vnSEfc

 Respond  
_Dean_   -  Feb 22, 2011

i really dont know, i didnt say u was lying

look i tested on 6.17 and that version really showed a problem, but on 7.14 no

try this alternative edit
i edited it, and this one will recognize the sockclose to hfree the hash

on *:TEXT:*youtube.com/watch?v=*:#: {
  if (!$sock(youtube)) && (!%t) {
    noop $regex($strip($1-),http:\/\/.*youtube.*\/watch\?v=(.+))
    sockopen youtube www.youtube.com 80 | sockmark youtube $chan $regml(1)
    inc -u3 %t
  }
}

on *:SOCKOPEN:youtube: {
  var %x = sockwrite -n $sockname
  %x GET $+(/watch?v=,$gettok($sock(youtube).mark,2,32)) HTTP/1.1
  %x Host: www.youtube.com
  %x $crlf
}

on *:SOCKREAD:youtube: {
  var %ytx | sockread %ytx
  if $regex(%ytx,/<meta name="title" content="(.+)"/) { hadd -m youtube 1 1[1,0You0,4Tube] $qt($regml(1))  }
  if $regex(%ytx,/<a id="watch-username".*><strong>(.+)<\/strong><\/a>/) { hadd -m youtube 2 User: $regml(1)  }
  if $regex(%ytx,/<strong>(\d+)<\/strong>/) { hadd -m youtube 3 Viewed: $regml(1) }
  if $regex(%ytx,<span class="likes">(\d+)<\/span>.*<span class="dislikes">(\d+)<\/span>\s) { 
    msg $gettok($sock(youtube).mark,1,32) $hget(ytb,1) - $hget(ytb,2) - $hget(ytb,3) - Likes: $regml(1) Dislikes: $regml(2) 
    sockclose youtube
  }
}
on *:sockclose:youtube:{
  hfree youtube
}
 Respond  
Jethro   -  Feb 22, 2011

See, Dean I ain't lyin' to you. Orion's living proof.

 Respond  
Orion   -  Feb 22, 2011

it worked one time, others allways says:

  • /hmake: table 'ytb' exists (line 5, script3.mrc)
  • /hmake: table 'ytb' exists (line 5, script3.mrc)
 Respond  
Jethro   -  Feb 22, 2011

Thus far it still does the same thing for the aforementioned link...it doesn't help to change the regex bit. I'm running a clean copy of mIRC with the latest version without a single script installed but your code.

 Respond  
_Dean_   -  Feb 22, 2011

its really strange it cause i tested and worked

[00:08:56] <~Dean> http://www.youtube.com/watch?v=8PTgnEmlLWI&feature=topvideos
[00:08:59] <&Botname> [YouTube] "Aref Ghafouri-Yetenek sizsiniz Turkiye yari final" - Viewed: 2368298 - - User: MrArefgh - Likes: 1272 Dislikes: 272

using the fix for regex

$regex($strip($1-),http:\/\/.*youtube.*\/watch\?v=(.*))

i dont know what are you doing, but the hash works fine

 Respond  
Jethro   -  Feb 22, 2011

Yes, your partial rewrite works on other links, just not the one I've pointed out here:
http://www.youtube.com/watch?v=8PTgnEmlLWI&feature=topvideos

The data has been fetched into the hash table but does not yield an output for the result. Then when you attempt to execute the code again, the error persists. This behavior doesn't occur to the original code.

I'd assume there may be other similar links that MAY or MAY NOT work for this little drawback of your rewrite.

 Respond  
_Dean_   -  Feb 22, 2011

your rewrite version gave me an error saying hash table already exists upon executing your code the second time.

you probably didnt check the hfree after the sockclose, i tested it with many link and worked
by the way, you're not the only one who saw that this script its probably not the original one... i remember that i saw something like this on the request forum

 Respond  
Jethro   -  Feb 22, 2011

Below is the original source where thejman obtained the code from:
http://www.hawkee.com/snippet/5931/

 Respond  
Jethro   -  Feb 22, 2011

First of all, this script is not originally written by thejman. I think the original one was written by kirby whom I believe has left mIRC for good. He's made it work again but not completely 100%, hence the leftover html strings.

But then again, I tried his original version with the link I showed you above and it gave me an output, just not your partial rewrite. At the end, your rewrite version gave me an error saying hash table already exists upon executing your code the second time. (This matters merely applies to the link I showed you above and other similar ones that may or may not activate)

I'm not trying to pick on your rewrite, just pointing out that it doesn't work fully anymore as the original snippet has intended.

 Respond  
Jethro   -  Feb 22, 2011

your rewrite version gave me an error saying hash table already exists upon executing your code the second time.

you probably didnt check the hfree after the sockclose, i tested it with many link and worked
by the way, you're not the only one who saw that this script its probably not the original one... i remember that i saw something like this on the request forum

 Respond  
Jethro   -  Feb 22, 2011

First of all, this script is not originally written by thejman. I think the original one was written by kirby whom I believe has left mIRC for good. He's made it work again but not completely 100%, hence the leftover html strings.

But then again, I tried his original version with the link I showed you above and it gave me an output, just not your partial rewrite. At the end, your rewrite version gave me an error saying hash table already exists upon executing your code the second time. (This matters merely applies to the link I showed you above and other similar ones that may or may not activate)

I'm not trying to pick on your rewrite, just pointing out that it doesn't work fully anymore as the original snippet has intended.

 Respond  
_Dean_   -  Feb 22, 2011

Jethro_, if you stop trying to find errors on ppl script, and read the posts, you will see what i wrote:

i just added a hmake on text event, and edited the entire sockread event

i didnt modified the regex that will catch the link, if you check the code, i didnt even modified the protocol HTTP/1.0
to HTTP/1.1

by the way, this problem could be easy fixed just using this

$regex($strip($1-),http:\/\/.*youtube.*\/watch\?v=(.*))

i just dont know why if he used regex on the text event, why didnt he use it on the match

 Respond  
Jethro   -  Feb 22, 2011

Unfortunately, Dean, your edit won't work for a similar youtube link. This one, for instance, won't yield any result:

http://www.youtube.com/watch?v=8PTgnEmlLWI&feature=topvideos

Try it and and see what I mean.

 Respond  
_Dean_   -  Feb 22, 2011

you could do like this

on *:TEXT:*youtube.com/watch?v=*:#: {
  if (!$sock(youtube)) {
    noop $regex($strip($1-),http:\/\/.*youtube.*\/watch\?v=(.{11})&?.*)
    sockopen youtube www.youtube.com 80 | sockmark youtube $+(#,>,$regml(1))
    hmake ytb 10
  }
}

on *:SOCKOPEN:youtube: {
  sockwrite -n $sockname GET $+(/watch?v=,$gettok($sock(youtube).mark,2,62)) HTTP/1.0
  sockwrite -n $sockname Host: www.youtube.com
  sockwrite -n $sockname $crlf
}

on *:SOCKREAD:youtube: {
  var %ytx | sockread %ytx
  if $regex(%ytx,/<meta name="title" content="(.+)"/) { hadd ytb 1 1[1,0You0,4Tube] $qt($regml(1)) }
  if $regex(%ytx,/<strong>(\d+)<\/strong>/) { hadd ytb 2 Viewed: $regml(1) }
  if $regex(%ytx,/<a id="watch-username".*><strong>(.+)<\/strong><\/a>/) { hadd ytb 3 - User: $regml(1) }
  if $regex(%ytx,/<span class="likes">(\d+)<\/span>.*<span class="dislikes">(\d+)<\/span>/) { msg $gettok($sock($sockname).mark,1,62) $hget(ytb,1) - $hget(ytb,2) - $hget(ytb,3) - Likes: $regml(1) Dislikes: $regml(2) | sockclose $sockname | hfree ytb }
}

i created a hash to use it to put the data, so no need the sockclose event, by the way, it will return without the html tags, i just added a hmake on text event, and edited the entire sockread event, its just a tip test it

using this one the return will be this

[22:49:29] <~Dean> http://www.youtube.com/watch?v=TRE6smcyDF4&feature=feedrec_grec_index
[22:49:31] <&Botname> [YouTube] "Simunition: US Military Using New Simulation Round" - Viewed: 21196 - - User: MilitaryNewsNetwork - Likes: 18 Dislikes: 2

 Respond  
_Dean_   -  Feb 22, 2011

the sockclose event will not recognize any channel dude...

 msg $chan

i didnt understand why dont u put the channel on sockmark
then you can use this on sockclose to recognize the channel

the return will be this

[22:20:12] <~Dean> http://www.youtube.com/watch?v=TRE6smcyDF4&feature=feedrec_grec_index
[22:20:17] <&Botname> [YouTube] "Simunition: US Military Using New Simulation Round" - Viewed: 21196x - User: MilitaryNewsNetwork - Rating: 0% - Positive: 18 pessoa(s) gosta(m), 2 Negative:

 Respond  
thejman   -  Feb 22, 2011

Fixed Dean

 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.