TinyUrl Previewer\Checker

By vSkyzv on Apr 15, 2009

This script allows you to see where a TinyUrl will go before you click it on.

If you wanted to check where http://tinyurl.com/1 redirected you could type either:

1) /tinyurl 1

or

2) /tinyurl http://tinyurl.com/1

The result either way would be:

alias tinyurl {
  sockopen tinyurl_check tinyurl.com 80
  sockmark tinyurl_check $gettok($1,1,61)
}
on *:sockopen:tinyurl_check:{
  echo 2 -a * Getting information for http://tinyurl.com/ $+ $sock($sockname).mark
  timertinyurlcheck 1 20 echo 2 -a * There appears to be no redirect for http://tinyurl.com/ $+ $sock($sockname).mark
  sockwrite -n $sockname GET /preview.php?num= $+ $sock($sockname).mark HTTP/1.0
  sockwrite -n $sockname Host: tinyurl.com
  sockwrite -n $sockname $crlf
}
on *:sockread:tinyurl_check:{
  var %x
  sockread -f %x
  if (<blockquote><b> isin %x) {
    timertinyurlcheck off
    echo 2 -a * http://tinyurl.com/ $+ $sock($sockname).mark redirects to $remove(%x,<blockquote><b>,<br /></b></blockquote>)
  }
}

Comments

Sign in to comment.
PATX   -  Apr 29, 2009

good script i like the point.

 Respond  
Kirby   -  Apr 15, 2009
 Respond  
Firstmate   -  Apr 15, 2009

I was gonna do this D:
No fair...
Btw, Kirby complicates things. All you have to do is:

;if you have a link returned
set -u10 %tinyurl.temp 1

;check for </html>
if (</html> isin %x) { sockclose tinyurl_check | if (!%tinyurl.temp) { echo -a can't find it }
 Respond  
Kirby   -  Apr 15, 2009

Cool, I really like the idea. :-)

Though your script works, I thought you can use some regex to make your sockread event a little shorter and add some error checks.

on *:sockread:tinyurl_check:{
  var %x
  sockread -f %x
  if (<blockquote><b> isin %x) {
    timertinyurlcheck off
    echo 2 -a * http://tinyurl.com/ $+ $sock($sockname).mark redirects to $remove(%x,<blockquote><b>,<br /></b></blockquote>)
  }
}

can be rewritten as:

on *:sockread:tinyurl_check:{
  sockread %x
  if ($regex(%x,<blockquote><b>(.*)<br /></b></blockquote>)) { echo -a $+(http://tinyurl.com/,$sock($sockname).mark) redirects to $regml(1) }
  elseif (class="intro"> isin %x) { echo -a * There appears to be no redirect for $+(http://tinyurl.com/, $sock($sockname).mark) }
}

I wouldn't use timers to check socket results, as sockets are quite (unbelievably) fast.
Instead of timers, resort to a unique tag that you will not find in a normal, working page. As the tags class="intro"> used in the code above, can be used to differentiate the two. You also don't need var %variable in the beginning of the sockread event.
Thus, you can remove

  timertinyurlcheck 1 20 echo 2 -a * There appears to be no redirect for http://tinyurl.com/ $+ $sock($sockname).mark

in the sockopen event.
I would also use a unique variable such as %tinyurl in this case, to prevent errors.

Although regex may seem complicated, in larger scripts, they will prove quite worthy. Most of all, they can shorten repetitiveness in scripts and even hasten them.
And yes, a Hotlink -> Echo would be nice.

On a second note, please make sure your code works.

2) /tinyurl http://tinyurl.com/1 does not work.

  sockmark tinyurl_check $gettok($1,1,61)

as specified in the alias means that you are getting the first token separated by equal signs =. In TinyURL links, there are no = signs in the URL.
And if you are going to use timers, put a dot . in front of them so they are silent.

Here's a rewrite of yours that works both ways as > If you wanted to check where http://tinyurl.com/1 redirected you could type either:
1) /tinyurl 1
or
2) /tinyurl http://tinyurl.com/1
The result either way would be:

alias tinyurl {
  if ($sock(tinyurl)) sockclose tinyurl
  sockopen tinyurl tinyurl.com 80
  sockmark tinyurl $iif($gettok($gettok($1,2,46),2,47),$v1,$1)
}
on *:sockopen:tinyurl: {
  echo -a * Getting information for $+(http://,$sock(tinyurl).addr,/,$sock(tinyurl).mark)
  sockwrite -n $sockname GET /preview.php?num= $+ $sock(tinyurl).mark HTTP/1.0
  sockwrite -n $sockname Host: tinyurl.com $+ $crlf $+ $crlf
}
on *:sockread:tinyurl: {
  sockread %tinyurl
  if ($regex(%tinyurl,<blockquote><b>(.*)<br /></b></blockquote>)) {
    echo -a * $+(http://tinyurl.com/,$sock(tinyurl).mark) redirects to $regml(1)
  }
  elseif (class="intro"> isin %x) {
    echo -a * There appears to be no redirect for $+(http://tinyurl.com/,$sock($sockname).mark)
  }
  unset %tinyurl
}
 Respond  
tv3636   -  Apr 15, 2009

That would have to be some serious spamming, but yeah HOTLINK does make more sense, shouldn't be too difficult to add either :)

 Respond  
vSkyzv   -  Apr 15, 2009

If somebody spammed a TinyUrl and this were on TEXT, your computer might lag a bit.

However, an on HOTLINK does make more sense... I might make it later.

 Respond  
Blitzjager   -  Apr 15, 2009

an on hotlink that does what tv suggested would be nice.

 Respond  
tv3636   -  Apr 15, 2009

Pretty cool, you should probably add an option to echo the redirects on TEXT too so that people can automatically see them when they're messaged.

 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.