#!/usr/bin/perl -w

# find /var/cache/wwwoffle/http -type f | perl this-script > tmp.html

# Generate a really big page of small inline JPEG images from a
# listing of files in the WWWOFFLE cache.  The WWWOFFLE cache is in
# /var/cache/wwwoffle/http on my system, and it's not the most
# convenient possible structure for doing this kind of thing (it has
# files containing HTTP responses, not the actual resources), but it
# doesn't take all that much work to grab stuff out of it.  You still
# have to be running WWWOFFLE for the resulting page not to take an
# absurdly long time to load, and it still might hork your browser.

while (<>) {
  chomp;
  my $fname = $_;
  my ($path, $type, $id) = /^(.*)\/([DU])([^\/]*)$/;  # data or URL
  print STDERR "$_ path $path type $type id $id\n" if not defined $type;
  if ($type eq 'D') {
    open FILE, "<$fname" or die "Can't open $fname: $!";
    while (<FILE>) {  # grab content-type out of HTTP header, hope it's there
      if (/^Content-Type: (.*)\r\n/) {  # specify \r so . doesn't match it
        my $ctype = $1;
        #print STDERR "content-type: <$ctype>\n";
        if ($ctype eq 'image/jpeg') {
          open URL, "<$path/U$id" or die "Can't open $id: $!"; # crappy msg
          my $url = <URL>;
          print qq(<img src="$url" width="128" height="128" />\n);
        }
        last;  # don't bother reading the rest of the file
      }
    }
  }
}
__END__

-- 
Kragen Javier Sitaker in Caracas, trying to get a clue

Reply via email to