Requested by UnBlown
Youtube URL Checker for your eggdrop.
To use:
source scripts/youtubeurl.tcl
That's it. The script will respond in channels with the +youtubeURL flag.
See the top of the script to change the logo or text color.
##############################################################################################
## ## Youtube.tcl for eggdrop by Ford_Lawnmower irc.geekshed.net #Script-Help ## ##
##############################################################################################
## To use this script you must set channel flag +youtubeURL (ie .chanset #chan +youtubeURL) ##
##############################################################################################
package require tls
##############################################################################################
## ## Start Setup. ## ##
##############################################################################################
proc youtubesurl {nick host hand chan text} {
if {[lsearch -exact [channel info $chan] +youtubeURL] != -1} {
## Change the characters between the "" below to change the logo shown with each result. ##
set youtubelogo "\002\00301,00You\00300,04Tube\002\017"
## Change the format codes between the "" below to change the color/state of the text. ##
set textf "\002\017"
set tagcolor "\002"
set hostlang "en"
##############################################################################################
## ## End Setup. ## ##
##############################################################################################
set youtubecheck [regexp -all -nocase {(?:\/watch\?v=|youtu\.be\/)([\d\w-]{11})} $text match youtubeid]
if {$youtubeid != ""} {
set youtubesite www.youtube.com
set youtubeurl "/watch?v=${youtubeid}&hl=${hostlang}"
set youtubeviews ""
set youtubedesc ""
set youtubeuser ""
set youtubelikes ""
set youtubedislikes ""
set youtubedate ""
set youtubefound ""
set youtubeduration ""
if {[catch {set youtubesock [tls::socket $youtubesite 443]} sockerr]} {
putlog "$youtubesite $youtubeurl $sockerr error"
return 0
} else {
puts $youtubesock "GET $youtubeurl HTTP/1.0"
puts $youtubesock "Host: $youtubesite"
puts $youtubesock ""
flush $youtubesock
while {![eof $youtubesock]} {
set youtubevar " [gets $youtubesock] "
if {[regexp -nocase {<title>(.*?)\s-\sYouTube<\/title>} $youtubevar match youtubedesc]} {
set youtubedesc "${tagcolor}Title: ${textf}${youtubedesc}"
} elseif {[regexp -nocase {\/user\/(.*?)">} $youtubevar match youtubeuser]} {
set youtubeuser "${tagcolor}Uploader: ${textf}${youtubeuser}"
} elseif {[regexp -nocase {class="yt-user-info"><[^<]*>([^<]*)<} $youtubevar match youtubeuser]} {
set youtubeuser "${tagcolor}Uploader: ${textf}${youtubeuser}"
} elseif {[regexp -nocase {watch-view-count"\s?>([^\x20]*)<} $youtubevar match youtubeviews]} {
set youtubeviews "${tagcolor}Views: ${textf}${youtubeviews}"
} elseif {[regexp -nocase {watch-like\s[^<>]+><[^<>]+><[^<>]+>([^<>\s]+)\s?<} $youtubevar match youtubelikes]} {
set youtubelikes "${tagcolor}Likes: ${textf}${youtubelikes}"
} elseif {[regexp -nocase {watch-like\s.+>([^<>]+)\s?<\/span><\/button>} $youtubevar match youtubelikes]} {
set youtubelikes "${tagcolor}Likes: ${textf}${youtubelikes}"
} elseif {[regexp -nocase {watch-time-text..(.*)<\/strong>} $youtubevar match youtubedate]} {
set youtubedate "${tagcolor}Uploaded: ${textf}[string map -nocase {"uploaded on" ""} ${youtubedate}]"
putserv "PRIVMSG $chan :[yturldehex "${youtubelogo} ${youtubedesc} ${youtubeviews} ${youtubelikes} ${youtubedislikes} ${youtubeuser} ${youtubedate} ${youtubeduration}"]"
close $youtubesock
return 0
} elseif {[regexp -nocase {watch-dislike\s[^<>]+><[^<>]+><[^<>]+>([^<>\s]+)\s?<} $youtubevar match youtubedislikes]} {
set youtubedislikes "${tagcolor}Dislikes: ${textf}${youtubedislikes}"
} elseif {[regexp -nocase {watch-dislike\s.+>([^<>]+)\s?<\/span><\/button>} $youtubevar match youtubedislikes]} {
set youtubedislikes "${tagcolor}Dislikes: ${textf}${youtubedislikes}"
} elseif {[regexp -nocase {\"duration\"\scontent\=\"([^"]+)\"} $youtubevar match youtubeduration]} {
set youtubeduration "${tagcolor}Duration: ${textf}[string map {PT "" M " Minutes " S " Seconds "} $youtubeduration]"
} elseif {[string match {*id="watch-uploader-info">*} $youtubevar]} {
set youtubefound "found"
} elseif {[regexp {<\/body>} $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 [encoding convertfrom utf-8 [string map {" \" \xa0 "," & \&} $string]]
}
proc yturlencode {instring} {
return [subst [regsub -nocase -all {([^a-z0-9])} $instring {%[format %x [scan "\\&" %c]]}]]
}
bind pubm -|- "*youtube.*watch?v=*" youtubesurl
bind pubm -|- "*youtu.be/*" youtubesurl
setudef flag youtubeURL
putlog "\002*Loaded* \00301,00You\00300,04Tube\002\017 \002URL check V 00.06 by Ford_Lawnmower irc.GeekShed.net #Script-Help"
<@MRVO|KANO> http://www.youtube.com/watch?v=Bgu7tEu7kC4
•«14:48:36 pm»• ..::::::| @OuInPis |:::::.. YouTube Title: L'actualité québécoise en caricatures Uploader: magazinenagg" class="yt-user-photo yt-uix-sessionlink spf-link g-hovercard" data-ytid="UCzCmIGFy1d-fSYgIad4AKYw" data-sessionlink="itct= Uploaded: Published on Feb 7, 2015 Duration: 3 Minutes 10 Seconds
ya t-il quelqu'un qui pourrais m'aider
merci d'avance :P
cd #
wget http://sourceforge.net/projects/tls/files/tls/1.6/tls1.6-src.tar.gz/download
tar -xzvf tls1.6-src.tar.gz
cd tls1.6
./configure
make
make install
tclsh
package require tls
1.6 <<<THIS IS THE RETURNED VALUE
exit
The the script should work with TLS ok.
ive been using this script for a while now, it was all working fine, but last month or so it will only display the info randomly..like if I post a link, it will work...post the same link again..and it doesn't display anything..try another link..nothing again..try it again...and it may or may not work :/
ive tried adding debugging.. just a simple putlog after each regexp but its not really much help..it goes into the while loop, but theres no output...
is anyone else having similar issues?
I've modified this script with bits from RaZ's script to include length and format it to a human readable format, here's the pastebin for anyone that's interested (thanks RaZ and Fordlawnmower!!)
http://pastebin.com/LR41DzFs(OLD SEE EDIT NOTE)
EDIT: I've updated it to clean the titles of videos, using code from both scripts again; v2 is here:
http://pastebin.com/sFvHJnNd(OLD ALSO PLEASE SEE EDIT:EDIT)
EDIT:EDIT:
i've escaped the characters and more. Also enabled turning off of certain things in the output. Also enabled logging the output in the partyline(be default everything is on logging too, read the conf options at the top)\
Any errors please let me know!
@Ieatscrayons I updated to Fords when I saw my bot wasn't working. I decided to give your code a test to see what the length part you added looked like. If the Title has Quotation marks ( "" ) in it the bot don't display anything to the channel and throws an error in dcc chat. Sorry I didn't keep a copy of the error or I would post it. I just reloaded Ford's copy.
Have you by chance tried the v2 version of the modifications i made? I'll look at it later this weekend and see if I cant fix it. I can't say that I've tried any youtube urls with quotes in it.
EDIT: Just tried using v2 of the script and it seems that both ' and " work correctly. I did notice that & still comes up as & in the uploader field. That'll be fixed soon. But play4free2 if you would send me the videos that break the script and a copy of the error that it sends to the partyline maybe i can diagnose the issue better.
This EDIT version: work good without any error, i copy link again ~> http://pastebin.com/sFvHJnNd
thanx - Ieatscrayons you share!
I just reloaded the the same version I tried before from this link: http://pastebin.com/sFvHJnNd
This is the Youtube link: https://www.youtube.com/watch?v=kHue-HaXXzg&list=PLDcnymzs18LXX8I3ERVq0cgWnHE5ARBRc
This is the error I got: [20:14:27] Tcl error [youtubesurl]: invalid command name "Official"
Hope that helps
See image:
http://i.imgur.com/yIVSvEG.jpg
I just looked closer it seems the error is kinda the same as I had with a shoutcast.tcl I use, any songs with Brackets like these [ ] would always not put the correct response to the channel or would not put any response at all. Another coder friend of mine had to fix it. If you look at the error I get from the bot, invalid command name "Official" The title has [Official] in it.
thankyou #leatscrayons you fix this problem now this work like charm without any error
mate #play4free2 you put Youtube link: https://www.youtube.com/watch?v=kHue-HaXXzg&list=PLDcnymzs18LXX8I3ERVq0cgWnHE5ARBRc
on comment, now i'm check it work like charm
See Image - http://i.imgur.com/XQzdHDi.jpg
@Erroneus I have a few things to do this weekend, but I will take a look at this and post an update before monday.
Awesome script, any chance for an update so it understands URL where "feature=player_embedded" is in the url, eg. http://www.youtube.com/watch?feature=player_embedded&v=ND9jVZPG75E.
And as previously stated youtu.be support would be amazing :)
@iDLE I added a temporary fix for the "umnatched open quote" error.
Please try the updated code.
Hello.
All of these Youtube Scripts are for TCL.
I wanted to know if there is such a script for python?
Currently I am developing a python bot and i wanted my bot to be able to display the Information about a youtube link
Any help would be appreciated
Thanks :D
And if there is already a script for it. Please notify me at navbommer@hotmail.com
Hi again, I had to stop running my bot via mIRC because my connection was too unstable, so I'll be switching to eggdrop via shell. I saw it as unfortunate that I could no longer use the mIRC script but was delighted to find you had a TCL version... Just reminding you on the youtu.be links as the script was updated in July.
Blade
Ya know, good question. Its going to take me a while to scour through Youtube to find any, but I'll definitely keep posted.
[edit] Went through some youtube links, I haven't found any that were using non-alphanumeric characters other than the underscore _ - but that worked fine as I tested a couple different links with that. I think Google hasn't started on those yet, so everything is working good so far.
[edit2] I broke it again. XD - [14:01:29] Tcl error [youtubesurl]: invalid command name "HD-720p" :: The title of the video is [HD-720p]DD ED, I thought it was the underscore, but it wasn't.
Ok, I think I found what's causing that youtubeid error. If I post any link that contains a hypen as the ID of the video, it'll spit that error out. If I post a video that doesn't contain such a character, it'll work fine. So, the link in my last comment would work as a test, or I have several others that would suffice as a good test ground. But each link that contained a hyphen would cause the error, and each link that had only letters and numbers would work fine.
At first the script didn't want to do anything, after spamming my test channel, it finally decided to cooperate. It appears to be working fine, testing out various youtube links in my favorites that has both unicode and other odd characters. I'll keep testing every so often and see if I can find a way to break it again somehow. XD It did spit this out in the partyline though:
Tcl error [youtubesurl]: can't read "youtubeid": no such variable
That was when I posted this: http://www.youtube.com/watch?v=-KJOC0JBDt4 - it later decided to report it properly, so I dunno.
Thank you for update! What i have to install in my eggdrop to use this update? The line "package require tls" is the cause of the problem. Thx!