Youtube URL Checker

By FordLawnmower on Apr 02, 2011

Requested by UnBlown
Youtube URL Checker for your eggdrop.

To use:

  • Copy this code and paste to a new file in wordpad or w/e not notepad
  • Save with a unique filename with the extension .tcl
  • Copy/Upload the .tcl file to your eggdrops scripts directory.
  • Add a line like this to your eggdrop.conf -:
source scripts/youtubeurl.tcl
  • Rehash or restart the eggdrop.
  • (In the Party Line) Type .chanset #ChannelName +youtubeURL
  • +/- youtubeURL as needed.

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 {&quot; \" \xa0 "," &amp; \&} $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"

Comments

Sign in to comment.
Mr-Steph   -  Feb 07, 2015

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

 Respond  
FordLawnmower   -  Nov 23, 2014

Updated

buffer  -  Nov 24, 2014

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!

beyondthepale  -  Nov 26, 2014

For Centos or RHEL you could try installing TLS package WHILE IN ROOT

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


TO CHECK IT WORKED DO:

tclsh

package require tls

1.6 <<<THIS IS THE RETURNED VALUE

exit

The the script should work with TLS ok.

one  -  Nov 29, 2014

i successfully installed this in ubuntu without root access.. but i accidentally deleted the file and when i tried to re-install it again - it says that permission denied - do you have any solution to install this without root priveledges?

thank you.

Sign in to comment

FordLawnmower   -  Sep 27, 2014

Updated and working again.

Keiro  -  Sep 29, 2014

Thanks for the quick work.

I dropped into the IRC and passed it along. Glad to see you got it updated. Excellent work, as always... and what happened to your Google repository?

WacKEDmaN  -  Oct 15, 2014

thanks for the update..appreciated..

fred``  -  Nov 14, 2014

Looks like smth changed again on youtube - doesnt work for me anymore :(

Sign in to comment

WacKEDmaN   -  Aug 28, 2014

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?

 Respond  
botinha   -  Jul 06, 2014

hi mr lawnmower. Nice script. however the views seems not working
here is an output. YouTube Title: Creedence - Live and Rare Likes: 265 Dislikes: 14 Uploader: Dino GT Uploaded: Published on Feb 16, 2013 Length: 47 minutes 55 seconds

 Respond  
beyondthepale   -  Jun 11, 2014

Hi Mr Lawnmower - the "Views: 123456" doesn't seem to be working?

[09:24] <+bot> YouTube Title: Black Sabbath - Vol. 4 Full album Likes: 1,982 Dislikes: 43 Uploader: blissy3 Uploaded: Published on May 30, 2013

edit: thanks for your scripts

 Respond  
Ieatscrayons   -  May 19, 2014

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

http://pastebin.com/9q4fTShY

Any errors please let me know!

play4free2  -  May 20, 2014

@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.

Ieatscrayons  -  May 23, 2014

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.

prashant179  -  May 25, 2014

This EDIT version: work good without any error, i copy link again ~> http://pastebin.com/sFvHJnNd

thanx - Ieatscrayons you share!

play4free2  -  May 28, 2014

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

prashant179  -  May 29, 2014

play4free2 - hello friend i check about you link, my bot also not respond on your link but not get any error i have no idea why not respond on your youtube videos link otherwise script is good work fine... i test more youtube video and work fine

See image:
http://i.imgur.com/yIVSvEG.jpg

play4free2  -  May 29, 2014

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.

Ieatscrayons  -  Jun 04, 2014

I'll see what I can do to escape the [] characters. i can see why that would be a probem since the script uses those as brackets.

Ieatscrayons  -  Jun 06, 2014

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

http://pastebin.com/9q4fTShY

Any errors please let me know!

prashant179  -  Jun 06, 2014

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

fred``  -  Sep 24, 2014

i still have problems with some fast pasted urls - especially if http and https mix

Sign in to comment

FordLawnmower   -  May 17, 2014

Updated

 Respond  
nickbailey   -  Dec 14, 2013

great worked first time, cheers ;o)

 Respond  
jeefo.w32   -  Jun 06, 2013

hello Ford :)

it is very cool code by you, i really enjoy using it .. but there is something missing i hope u add - duration ( length ) - feature in it ..

prashant179  -  Jan 14, 2014

Me Too Miss ~ Duration (Length) Feature
Otherwise That is Awesome!

Sign in to comment

[85]   -  Jan 23, 2013

gj...

 Respond  
FordLawnmower   -  Sep 29, 2012

updated Added some functionality. See the setup at the top of the script.

 Respond  
FordLawnmower   -  Sep 29, 2012

@Erroneus I have a few things to do this weekend, but I will take a look at this and post an update before monday.

 Respond  
Erroneus   -  Sep 24, 2012

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

 Respond  
Fuzion   -  Jul 01, 2012

fantastic work once again ford :)

 Respond  
Dramakus   -  May 30, 2012

Can anyone tell me how to include youtu.be/VIDEOID in the search as well? I am having people bypass this script using those urls. I just need to know where I should add in a or statement for it

 Respond  
FordLawnmower   -  May 14, 2012

@iDLE I added a temporary fix for the "umnatched open quote" error.
Please try the updated code.

 Respond  
iDLE   -  Apr 23, 2012

Hi! eggdrop v1.6.21 :)

 Respond  
FordLawnmower   -  Apr 19, 2012

What eggdrop version are you using iDLE ?

 Respond  
iDLE   -  Apr 19, 2012

[11:25:21] Tcl error [youtubesurl]: unmatched open quote in list

Any idea? :(

 Respond  
aw9292929296983244   -  Apr 19, 2012

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

 Respond  
Bladerunner   -  Feb 22, 2012

I'm also wondering if the Upload Date went out of wack since the other one did. Haven't gotten a chance to test it out yet as my bot won't be online 'til tomorrow.

 Respond  
Bladerunner   -  Feb 22, 2012

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

 Respond  
FordLawnmower   -  Jul 08, 2011

Updated , thanks TwinShadow

 Respond  
TwinShadow   -  Jul 06, 2011

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.

 Respond  
FordLawnmower   -  Jul 06, 2011

Thanks TwinShadow :)
Updated to allow for the dash "-" in the id.
Are there any other non-alphanumeric characters in youtube id's ?
Sorry, I don't use youtube at all.

 Respond  
TwinShadow   -  Jul 06, 2011

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.

 Respond  
TwinShadow   -  Jul 04, 2011

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.

 Respond  
FordLawnmower   -  Jul 02, 2011

@TwinShadow The code at the top of the page has been updated and should be working correctly. Let me know if you have any problems and thanks for helping me debug this script. The person who requested this script has never contacted me again so I just assumed it was working right.

 Respond  
TwinShadow   -  Jul 02, 2011
YouTube Melfina's song(English), Hiiru No Tsuki That was one output. I also jumped the gun on the japaense text, it actually doesn't respond at all with those. I didn't pay attention much since someone else had a similar script that was replying to youtube links. Would be nice if it was supported, but that may require some hefty rewriting maybe.
 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.