Jump to content

Archived

This topic is now archived and is closed to further replies.

chain

Short URL Plus Website Title

Recommended Posts

  • Administrators

Short URL Plus Website Title

 

logo.jpg

 

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 http://www.youtube.com

URL: goo.gl/NlKL Title: YouTube - Broadcast Yourself.

http://www.tvguide.com

URL: goo.gl/EBFF Title: TV Guide, TV Listings, Online Videos, Entertainment News and Celebrity News | TVGuide.com

Go to http://www.hawkee.com

URL: goo.gl/IM7Ti Title: Hawkee Technology Social Network

http://www.mirc.com

URL: goo.gl/YwVB Title: mIRC: Internet Relay Chat client

 

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

 

>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+)/) {       $1 $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)(\s*\K.+?(?=\s*))/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;),®,$chr(174))  }}on $*:text:/((?i)(https?\72\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w\s\.-]*)*\/?)/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 $regsubex($str($chr(32),$lines(info)),//g,$read(info,\n))    unset %info %chash  }}

Link to comment
Share on other sites



×
×
  • Create New...