10 if (exists $ENV{"QUERY_STRING"}) {
11 $BASE=($ENV{"QUERY_STRING"}=~m{^url=([^&]*)})[0];
12 $BASE=URI::Escape::uri_unescape($BASE);
13 0==@ARGV or die "ARGV count != 0";
17 1==@ARGV or die "ARGV count != 1";
21 # Somehow Perl modules started reencoding windows-1250 -> utf-8.
23 if ($ENV{"GATEWAY_INTERFACE"}) {
24 my $future=HTTP::Date::time2str(2000000000);
25 my $past =HTTP::Date::time2str(1000000000);
27 Content-type: text/html; charset=utf-8
36 <title>iDNES foto@{[ (!$BASE ? "" : ": $BASE") ]}</title>
37 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
39 <form action="idnes-foto" method="get">
40 <input type="text" name="url" size="50" value="$BASE">
44 $BASE=~m{^http://\w+\Q.idnes.cz/foto.asp\Ex?[?](?:r=[-_\w]+&c=[-_\w]+|c=[-_\w]+&r=[-_\w]+)$} or $BASE="";
47 my $ua=LWP::UserAgent->new();
49 $ua->requests_redirectable([]);
55 # my $resp=$ua->get($url);
56 # if ($resp->is_redirect()) {
57 # my $relurl=$resp->header("Location");
58 # $relurl=~m{^foto.*[?]} or die;
61 # warn "Redirect to: $url\n";
62 # $resp=$ua->get($url);
64 # $resp->is_success() or die $url;
65 # return $resp->decoded_content();
73 my $pageurl=$BASE.'&strana='.$pageno;
74 my $page=LWP::Simple::get($pageurl) or die $pageurl;
77 while ($page=~m{<a href="([?]c=[^<>"]*&foto=[^<>"&]*(?:&inframe=1)?)"(?: target="foto-iframe")?>}gi) {
79 $relurl=~s{&}{&}g;
81 $frameurl=~s{[?].*}{};
83 my $frame=LWP::Simple::get($frameurl) or die $frameurl;
84 if ($frame=~m{<iframe name="foto-iframe" id="foto-iframe" [^<>]* src="([?]c=[^<>"]*&inframe=1&[^<>"]*foto=[^<>"]*)">}) {
86 $relurl=~s{&}{&}g;
87 $frameurl=~s{[?].*}{};
89 $frame=LWP::Simple::get($frameurl) or die $frameurl;
91 if ($frame!~m{<img\s+id="fotka"\s+alt="([^"]*)"\s+src="(http://\w+\Q.idnes.cz/\E[\d/]+)/(?:gal|cl6h|cl6)/([^<>"]+)" }is) {
94 die "No aspx image found: $frameurl";
99 my $img_src="$2/org/$3";
100 if (!LWP::Simple::head($img_src)) {
101 $img_src="$2/maxi/$3";
102 die $img_src if !LWP::Simple::head($img_src);
106 <img src="$img_src" border="0">
108 print <<"EOH" if !$seen_p_text{$text}++;
112 while (!$aspx && $page=~m{<img src="http://(?:\Qi.idnes.cz\E/\d{2}/\d{3}|\Qimgs.idnes.cz\E/\w+)(?:/\w+)?/([-.\w]+.jpg)" }gi) {
115 last PAGES if $seen{$base}++;
116 my $infourl=$BASE.'&styl=zoom&foto='.$base;
117 my $info=LWP::Simple::get($infourl) or die $infourl;
118 $info=~m{<img\s+id="fotka"\s+src="([^<>"]+)" }is
119 or die "No image found: $infourl";
123 <img src="$img_src" border="0">
127 $info=~m{<span>(.*?)</span>}s,
128 $info=~m{<p>([^<>]*)</p>},
129 $info=~m{<div class="text"><!--google_ad_section_start--><h4>([^<>]*)</h4><p>([^<>]*)<!--google_ad_section_end--></p><p>Autor:\s+(.*?)(?:, <a target="_blank" href="http://www.idnes.cz">iDNES.cz</a>)?</p></div>}s,
136 print <<"EOH" if !$seen_p_text{$text}++;
140 warn "No text found: $infourl" if !$hit;
142 die $pageurl if !$did;