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,&quot;,$chr(34),&#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;;;;;;;;;;;;;;;;;;;;;;
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.
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.
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
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
}
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
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.
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
Below is the original source where thejman obtained the code from:
http://www.hawkee.com/snippet/5931/
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.
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
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.
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
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.
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
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: