TinyURL shortener/Preview Customized URL

By _Dean_ on Jan 28, 2011

i saw here some URL shorteners, but some of them dont have a option to do a ''customized URL''

• copy this code and put into a new remote page (alt+r)

type !tinyurl http://www.example.com [CUSTOM URL OPTIONAL]

you can make customized URL or just get a random one

example:

[20:52:47] <_Teen_> !tinyurl http://www.hawkee.com Hawkee
[20:52:48] http://tinyurl.com/Hawkee
[20:52:48] http://preview.tinyurl.com/Hawkee

if the url customized you choose just exist, it will return a random one

[20:53:57] <_Teen_> !tinyurl http://www.google.com Google
[20:53:58] The custom alias you've chosen is not available. We've created a random one for you instead, but you can try assigning a different custom alias again below. Use 6 characters or more for the best chance of getting a unique unassigned alias.
[20:53:58] http://tinyurl.com/1c2
[20:53:58] http://preview.tinyurl.com/1c2

you can preview what is behind from that URL

!preview http://tinyurl.com/ [url]

example:

[20:55:39] <_Teen_> !preview http://tinyurl.com/1c2
[20:55:40] This TinyURL redirects to: http://www.google.com

i know that you can get the same information using method GET but i prefered method POST

on *:text:!tinyurl *:#:{
  if (%Floods) { notice $nick 4You need to wait 5 seconds till you do this command again | return } 
  if ($sock(Tinys)) sockclose Tinys
  if $regex($2-,/(http:\/\/(.+)|www\.(.+))/i) {
    sockopen Tinys tinyurl.com 80  
    sockmark Tinys $chan $regml(1) 
    inc -u5 %floods
  }
  else { 
    msg $chan 4You need to specify a valid link | halt
  }
}

on *:Sockopen:Tinys:{
  var %Tinyurl $+(?source=indexpage&url=,$gettok($sock(Tinys).mark, 2, 32),&submit=Make+TinyURL!&alias=,$gettok($sock(Tinys).mark, 3, 32)))
  sockwrite -nt $sockname POST /create.php  HTTP/1.1
  sockwrite -nt $sockname Host: tinyurl.com
  sockwrite -nt $sockname Content-Type: application/x-www-form-urlencoded
  sockwrite -nt $sockname Content-Length: $len(%Tinyurl)
  sockwrite -nt $sockname $crlf $+ %Tinyurl

}
on *:sockread:Tinys:{
  var %x, %y msg $gettok($sock(Tinys).mark, 1, 32)
  sockread %x 
  if $regex(%x,/<a href="(.+)" target="_blank">Open in new window</a>/) {
    %y 12 $regml(1)
  }
  if (*The*custom*alias* iswm %x) {
    %y  4 $kks(%x)
  }
}

on *:text:!preview *:#:{
  if (%Floods) { notice $nick 4You need to wait 5 seconds till you do this command again | return }
  if ($sock(preview)) sockclose preview
  if $regex($1-,/http://tinyurl.com/(.+)/) {
    sockopen preview preview.tinyurl.com 80 
    sockmark preview $chan $regml(1)
    inc -u5 %floods 
  }
  else { 
    msg $chan 4You need to specify a valid link | halt
  }
}

on *:Sockopen:preview:{
  sockwrite -n $sockname GET $+(/,$gettok($sock(preview).mark, 2, 32))  HTTP/1.1
  sockwrite -n $sockname Host: preview.tinyurl.com
  sockwrite -n $sockname $crlf
}

on *:sockread:preview:{
  var %x, %y msg $gettok($sock(preview).mark, 1, 32)
  sockread %x 
  if $regex(%x,/<blockquote><b>(.+)<br \/></b></blockquote>/) {
    %y 12 This TinyURL redirects to: $regml(1)
  }
  if (*Error* iswm %x) {
    %y 4 $kks(%x)
  }
  if (*terminated* iswm %x) {
    %y 4 $kks(%x)
  }
}

alias kks {
  var %x = $regsubex($1-,/<[^<>]+>/g,$null)
  return $remove(%x, $chr(3), $chr(9), &nbsp;)
}

Comments

Sign in to comment.
_Dean_   -  Feb 15, 2011

thanks =)

 Respond  
Reborg   -  Feb 15, 2011

Works great. Nice going.

 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.