Short URL Plus Website Title

By Jethro on Apr 26, 2011

This is a forum request asked by the member StonaJakey to have any posted URL shortened using Google's URL Shortener, along with the ability to display the URL leading to its website title. I thought it'd be useful to submit this code as a snippet and for those who find it for some related beneficial uses.

If you want to make the short URL clickable, parenthesize the whole regex match as such:

/(http:\/\/\S+)/

You must start a URL either with www. or http:// in a sentence. Please note that some websites may not return their titles.

A personal thanks to jaytea for the heads up on the regex.

Visit www.youtube.com **Title:** YouTube - Broadcast Yourself. **URL:** goo.gl/NlKL www.tvguide.com **Title:** TV Guide, TV Listings, Online Videos, Entertainment News and Celebrity News | TVGuide.com **URL:** goo.gl/EBFF Go to http://www.hawkee.com **Title:** Hawkee Technology Social Network **URL:** goo.gl/IM7Ti www.mirc.com **Title:** mIRC: Internet Relay Chat client **URL:** goo.gl/YwVB**-Edit-** Script updated to make the socket events regex, thanks to Ford's suggestion that it may cause a conflict with people who have similar socket names while having this script installed.

-Edit-Rearranged the output to have the website title displayed first before its URL.

on *:exit:$iif($exists(info),.remove info)
on $*:sockopen:/^goo$|^goo\.title$/:{
  if $sockerr { msg %chash I'm experiencing a connection error! | halt }
  if $sock(goo).name = goo {
    tokenize 124 $sock(goo).mark
    var %goo $+(url=http%3A%2F%2F,$2,&security_token)
    $3 POST /api/shorten HTTP/1.0 | $3 Host: goo.gl
    $3 Content-Type: application/x-www-form-urlencoded;charset=utf-8
    $3 Connection: close 
    $3 Content-Length: $len(%goo) 
    $3 $crlf $+ %goo
  }
  else {
    var %title sockwrite -nt goo.title 
    %title GET / HTTP/1.1
    %title Host: $sock(goo.title).addr 
    %title Connection: close | %title
  }
}
on $*:sockread:/^goo$|^goo\.title$/:{
  if $sockerr { msg %chash I'm experiencing a reading error! | halt }
  if $sock(goo).name = goo {
    tokenize 124 $sock(goo).mark | sockread &goo
    if $regex($bvar(&goo,1-).text,/http:\/\/(\S+)/) { 
      write info $addtok(%info,$+($chr(2),URL:,$chr(2)) $regml(1) $chr(160),94)
    }
    halt
  }
  sockread &title
  if $bvar(&title,0) && $regex($bvar(&title,1-).text,/(?s)<title>(\s*\K.+?(?=\s*))<\/title>/i) {
    var %t-- $iif($istok(object moved|error page|301 moved permanently,$regml(1),124),N/A,$regml(1))
    write info $+($chr(2),Title:,$chr(2)) $replace($remove(%t--,amp;),&reg;,$chr(174))
  }
}
on $*:text:/((?i)(https?\72\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6}))/S:#:{
  if !%tc { 
    inc -u4 %tc | set %chash # | write -c info
    var %- $iif(http:// isin $regml(1),$remove($v2,$v1),$v2) 
    $iif($sock(goo),sockclose $v1) | sockopen goo goo.gl 80 
    sockmark goo $+(set $+(%,info),|,%-,|,sockwrite -nt goo,|,$&
      $iif($regex($regml(1),/(w{3}\.|http:\/\/)?(\S+)\./),$remove($regml(2),www.)))
  }
}
on $*:sockclose:/^goo$|^goo\.title$/:{
  if $sock(goo).name = goo {
    tokenize 124 $sock(goo).mark
    if $sock(goo.title) { sockclose $v1 }
    sockopen goo.title $+(www.,$4,.com) 80
    sockmark goo.title .msg %chash
  }
  else {
    tokenize 94 %info 
    $sock(goo.title).mark $1 $+($read(info,2),$str($chr(160),2),$read(info,1))
    unset %chash
  }
}

Comments

Sign in to comment.
dma   -  Jul 16, 2015

after all these years still not working,, day 3 I got it only half working

dma  -  Jul 21, 2015

had to delete it to many errors

Sign in to comment

^WeSt   -  Feb 08, 2014

not working..

32 Unknown command

POST is a server only command

HOST: Unknown command

CONTENT-TYPE: Unknown command

CONNECTION: Unknown command

CONTENT-LENGTH: Unknown command

URL=HTTP%3A%2F%2F&SECURITY_TOKEN Unknown command

 Respond  
cptpan   -  Feb 05, 2014

All I get is: I'm experiencing a connection error!

 Respond  
KryptonCnR   -  Nov 28, 2013

Hey Jethro,

Is there a way to add a !snipr into this script? to bring back a link that would define http://snipr.me/489T3 (for short URL) ? instead of having http:// or www. ? thanks for your time :)

 Respond  
DJScias   -  Mar 17, 2013

Jethro,

Do you think you could update it again? Lately the only thing that gets messaged is Title: and the Url: part is completely voided for some reason.

Thank you in advance.

 Respond  
chachin   -  Jun 06, 2012

woohoo jethro is the man. this works like a new charm! :D

 Respond  
RoflCopter   -  Mar 02, 2012

The error he's referring to is just a misplace in his scripts editor. Place this script on top of any script you currently have.

~RoflCopter

 Respond  
Jethro   -  Oct 05, 2011

Ok, I've updated the code to catch only the section for www.sitename.com or http://www.sitename.com. Everything should work correctly now. So, say, if someone posts a link like this in a channel:> http://www.newegg.com/Product/Product.aspx?Item=079-0001-000T2The script should read the bit for http://www.newegg.com and returns its title.

The error occurred on account of the sub-path existed in the URL.

 Respond  
MashhitDK   -  Oct 05, 2011

Just tested it here... get the same error with the link posted above ^^^

 Respond  
Jethro   -  Oct 04, 2011

Does any of you get the same error as chachin's? I can't reproduce the error he's experiencing. :/

 Respond  
chachin   -  Oct 04, 2011

i know why the script isnt working for me... you need to update it :D its something with goole.. please fix the: HTTP part i dont know how sorry D:

<~chachin> http://www.newegg.com/Product/Product.aspx?Item=079-0001-000T2

I'm experiencing a connection error!
 Respond  
Jethro   -  Sep 24, 2011

I'm deeply puzzled why this error only occurred to you but not other people...

 Respond  
chachin   -  Sep 24, 2011

I'll try to move the bot to a clean version of mirc7.19 and see if that works...
k i did that. and still im getting same error :S

 Respond  
Jethro   -  Sep 24, 2011

I can't reproduce the error you're having. Everything is working fine for me running mIRC version 7.19.

 Respond  
chachin   -  Sep 24, 2011

ok i installed it on chickenbot and this is what it did.

  • /sockwrite: 'goo.title' not connected (line 14, linkinfo.mrc)
 Respond  
Jethro   -  Sep 24, 2011

chachin, use this one here and see how it goes for you: http://pastebin.com/Rqxw96er

 Respond  
chachin   -  Sep 24, 2011

no sir. its only inside chicken not me... :S

 Respond  
Jethro   -  Sep 24, 2011

chachin, did you and your bot chicken run the script at the same time? If so, please install the script in chicken's remote only.

 Respond  
chachin   -  Sep 23, 2011

http://kpaste.net/2c829 here's the script. you see i only modded the line that needed to be modded to make the links clickable. line 24 should be it. its highlighted with @@ so you know i did it the way you want. oh now the bot says this every time on any and every link:

[9:01:53pm] <~chachin> http://kpaste.net/2c829
[9:01:56pm] <@chicken> I'm experiencing a connection error!

 Respond  
Jethro   -  Sep 23, 2011

You're not spamming. You're asking related, on-topic question under my snippet thread. Don't you fret about it. No worries. lol

 Respond  
chachin   -  Sep 23, 2011

Jethro where can I find you so we dont keep spamming on here :S

 Respond  
Jethro   -  Sep 23, 2011

You misplaced the parentheses incorrectly that resulted in the error. Here is what you should have done:

if ($regex($bvar(&goo,1-).text,/(http:\/\/\S+)/)) {

All the shortened URLs should also be clickable now.

 Respond  
chachin   -  Sep 23, 2011

So far all of the scripts i've use that you made. work awsome 10/10 but this one is the only one that gave me error. im using it on a clean 6.35mIRC.

 Respond  
chachin   -  Sep 23, 2011

yeah i know thats the line.. i put a " ( " by "/http:\/\/(\S+)/))

like this if ($regex($bvar(&goo,1-).text,(/http:\/\/(\S+)/)) {

 Respond  
Jethro   -  Sep 23, 2011

I don't get that error using my mIRC. Locate and change it to this one:

 if ($regex($bvar(&goo,1-).text,/http:\/\/(\S+)/)) {
 Respond  
chachin   -  Sep 23, 2011

i got an error: * Invalid format: $regex (line 24, linkinfo.mrc)

 Respond  
Jethro   -  Sep 23, 2011

How come you have two URL outputs? Did you have the original script loaded in another remote somewhere?

I updated the script on Sep. 2nd to have the output rearranged. The title of a website will come out first before its URL.

Check your mIRC remote and make sure you have the old one removed, and then copy and paste the script again.

 Respond  
chachin   -  Sep 23, 2011

i keep getting this error i dont know if i didnt load it right or wtf i dont have other url checkers or title scripts only this one.

[6:17:23pm] <@chachin> www.youtube.com
[6:17:24pm] <+chicken> URL: goo.gl/NJwy   Title:  URL: goo.gl/NJwy  ^URL: goo.gl/NlKL  

Jethro: see its not suppose to be like that its suppose to look like your example.

 Respond  
Jethro   -  Sep 23, 2011

chanchin, what error are you referring to?

If you want to make the shortened URL clickable, I've mentioned this matter in my description, and here is the re-post:

If you want to make the short URL clickable, parenthesize the whole regex match as such:

/(http:\/\/\S+)/

I'm sure you can do the adding in my script; if you can't, let me know.

 Respond  
chachin   -  Sep 23, 2011

hmm I don't know if this is a problem But I'm getting an error of some kind. as you see it posts tiny url 3 times. and i cant find the line to make it clickable :( I still give it a 7/10 :)

[3:49:19pm] <~chachin> http://www.iheart.com/#/live/2281/
[3:49:20pm] URL: goo.gl/NJwy   Title: Real & Custom Radio Stations | Listen Free Online | iHeartRadio  URL: goo.gl/NJwy  ^URL: goo.gl/tC3f2  

 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.