Google URL Shortener v1

By SplitFire on Jan 15, 2011

Just a basic Google URL Shortener

;-- Google URL Shortener
;-- SplitFire aka X-System
;-- #mircscripting @ UnderNeet

alias -l rawurlencode {
  return $regsubex($1-,/\G(.)/g,$iif(\t !isalnum && \t !isin -_.,$chr(37) $+ $base($asc(\t),10,16,2),\t))

alias -l urlencode {
  return $replace($rawurlencode($1-),$+($chr(37),20),+)
alias hfree GglShrt
alias g.logo return 2G4o7o2g3l4e URL Shortener

alias {
  if (!$hget(GglShrt,output)) { hadd -mu40 GglShrt output echo $color(normal) -ati2 * }
  if (!$1) { $hget(GglShrt,output) $g.logo error: insufficient parameters | | halt }
  if ($sock(googleshort)) { $hget(GglShrt,output) $g.logo error: socket in use | | halt }

  var %s $1, %r /(?:^|[][()<>{}'"\s])((?:(?:irc|s?ftp|https?:)\/\/|www\d*\.)[^\s./]+\.(?:\[\S*?]|\(\S*?\)|\{\S*?}|[^][()<>{}'"\s]|['"](?!\s|$|[()\[\]<>]))++)/giS
  if (!$regex(%s,%r)) { $hget(GglShrt,output) $g.logo error: invalid URL format | | halt }

  sockopen googleshort 80
  sockmark googleshort $1

on *:sockopen:googleshort:{
  var %s sockwrite -tn $sockname
  var %p = url= $+ $urlencode($sock($sockname).mark) $+ &security_token=null, %clen = $len(%p)
  %s POST /api/shorten HTTP/1.1
  %s Host:
  %s User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)
  %s Connection: close
  %s X-Auth-Google-Url-Shortener: true
  %s Content-Type: application/x-www-form-urlencoded;charset=utf-8
  %s Content-Length: %clen
  %s $crlf
  %s %p

on *:sockread:googleshort:{
  var %g
  sockread %g
  if ($regex(%g,/Location:\s(.+)/)) {
    $hget(GglShrt,output) $g.logo $+ :12 $sock($sockname).mark <->12 $regml(1)
    sockclose $sockname
on *:text:! &:#:{
  if (!$hget(GglShrt,output)) { hadd -mu40 GglShrt output msg # } $2


Sign in to comment.
WingmaN   -  Apr 28, 2012

Not working anymore ..

Jethro   -  Mar 21, 2011

The script still works. You either enter the alias command:

/ URL_Here

(The alias command is for the client that runs the code to use.) Or the text trigger command from people:

! URL_Here

(This trigger is for people who activate it from the client who runs the code.)

Replace URL_Here with an actual website address to shorten.

The author should have included the instruction when he submitted this snippet, which would've made it easy for newbies to use it.

jasonh   -  Mar 20, 2011

doesnt work

DimensionX   -  Mar 17, 2011

how does it works?

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.