--- /dev/null
+#! /usr/bin/perl
+use strict;
+use warnings;
+require LWP::Simple;
+require URI::Escape;
+
+$|=1;
+my $BASE;
+if (exists $ENV{"QUERY_STRING"}) {
+ $BASE=($ENV{"QUERY_STRING"}=~m{^url=([^&]*)})[0];
+ $BASE=URI::Escape::uri_unescape($BASE);
+ 0==@ARGV or die "ARGV count != 0";
+ $BASE||="";
+ }
+else {
+ 1==@ARGV or die "ARGV count != 1";
+ $BASE=$ARGV[0];
+ }
+
+if ($ENV{"GATEWAY_INTERFACE"}) {
+ print <<"EOH";
+Content-type: text/html; charset=windows-1250
+
+EOH
+ }
+print <<"EOH";
+<html><head>
+<title>iDNES foto@{[ (!$BASE ? "" : ": $BASE") ]}</title>
+<meta http-equiv="Content-Type" content="text/html; charset=windows-1250">
+</head><body>
+<form action="idnes-foto" method="get">
+ <input type="text" name="url" size="50" value="$BASE">
+ <input type="submit">
+</form>
+EOH
+$BASE=~m{^http://\w+\Q.idnes.cz/foto.asp?\E(?:r=\w+&c=\w+|c=\w+&r=\w+)$} or $BASE="";
+if ($BASE) {
+ my $pageno=1;
+ my %seen;
+ my %seen_p_text;
+PAGES: for (;;) {
+ my $pageurl=$BASE.'&strana='.$pageno;
+ my $page=LWP::Simple::get($pageurl) or die $pageurl;
+ my $did=0;
+ while ($page=~m{<img src="(http://(?:\Qi.idnes.cz\E/\d{2}/\d{3}|\Qimgs.idnes.cz\E/\w+))(/midi)?/([-\w]+.jpg)" }gi) {
+ $did=1;
+ my($start,$mid,$base)=($1,$2,$3);
+ last PAGES if $seen{$base}++;
+ # FIXME: Sometimes "/maxi" does not exist.
+ $mid&&="/maxi";
+ $base=~s/_1M.JPG$/_V.JPG/;
+ my $maxi=$start.($mid||"")."/".$base;
+ print <<"EOH";
+<hr>
+<img src="$maxi" border="0">
+EOH
+ my $infourl=$BASE.'&styl=zoom&foto='.$base;
+ my $info=LWP::Simple::get($infourl) or die $infourl;
+ $info=~m{<p>[^<]*</p>} or die "No text found: $infourl";
+ my $p_text=$&;
+ print <<"EOH" if !$seen_p_text{$p_text}++;
+$p_text
+EOH
+ }
+ die $pageurl if !$did;
+ $pageno++;
+ }
+ }
+print <<"EOH";
+<hr>
+<p>EOF</p>
+</body></html>
+EOH