#!/usr/local/bin/perl # Hatena Screenshot Redirector # # This program is free software; you can redistribute it and/or modify # it under the same terms as Perl itself. use strict; use CGI qw/:standard/; use LWP::Simple qw/get/; use URI::Escape qw/uri_escape/; my $header = { -uri => 'http://screenshot.hatena.ne.jp/images/120x90/notfound.jpg', -status => '303 See Other' }; if (my $url = param('url')) { my $res = get('http://b.hatena.ne.jp/entry/json/?url=' . uri_escape($url)); if ($res and $res =~ /"screenshot":"(.*?)"/) { $header = {-uri => $1}; } } print redirect($header); exit;