/[swish]/trunk/spider/progspider
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/spider/progspider

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 63 by dpavlin, Fri Feb 6 13:29:39 2004 UTC revision 84 by dpavlin, Sun Aug 29 21:19:13 2004 UTC
# Line 1  Line 1 
1  #!/usr/local/bin/perl -w  #!/usr/bin/perl -w
2  use strict;  use strict;
3  use File::Find;  use File::Find;
4  use Getopt::Long;  use Getopt::Long;
# Line 25  require "$basedir/filter.pm"; Line 25  require "$basedir/filter.pm";
25    
26  my $pdftotext = which('pdftotext');  my $pdftotext = which('pdftotext');
27    
28    select(STDERR); $|=1;
29    select(STDOUT); $|=1;
30    
31  print STDERR "using $pdftotext to convert pdf into html\n" if ($pdftotext && $verbose);  print STDERR "using $pdftotext to convert pdf into html\n" if ($pdftotext && $verbose);
32    
33  find({ wanted => \&file,  find({ wanted => \&file,
# Line 32  find({ wanted => \&file, Line 35  find({ wanted => \&file,
35          no_chdir => 1          no_chdir => 1
36  }, $dir);  }, $dir);
37    
38    sub dump_contents($$$) {
39            my ($contents,$mtime,$path) = @_;
40    
41            return if (! $contents);        # don't die on empty files
42    
43            use bytes;
44            my $size = length $contents;
45    
46            print STDERR " [$size]" if ($verbose);
47    
48            # Output the document (to swish)
49            print <<EOF;
50    Path-Name: $path
51    Content-Length: $size
52    Last-Mtime: $mtime
53    Document-Type: html*
54    
55    EOF
56            print $contents;
57    
58    }
59    
60  sub file {  sub file {
61    
62          my $path = $_;          my $path = $_;
# Line 41  sub file { Line 66  sub file {
66    
67                  print STDERR "$path {converting}" if ($verbose);                  print STDERR "$path {converting}" if ($verbose);
68    
69                  open(F,"$pdftotext -htmlmeta $path - |") || die "can't open $pdftotext with '$path'";                  open(F,"$pdftotext -htmlmeta \"$path\" - |") || die "can't open $pdftotext with '$path'";
70                  my $html;                  my $html;
71                  while(<F>) {                  while(<F>) {
72                          # XXX why pdftotext barks if I try to use this is beyond me.                          # XXX why pdftotext barks if I try to use this is beyond me.
# Line 51  sub file { Line 76  sub file {
76                  }                  }
77                  close(F);                  close(F);
78    
79                  $contents = "<!-- html from $path -->\n$html\n";                  return if (! $html);
80    
81                    my $file_only = $path;
82                    $file_only =~ s/^.*\/([^\/]+)$/$1/g;
83    
84                    my ($pre_html,$pages,$post_html) = ('<html><head><title>$path :: page ##page_nr##</title></head><body><pre>',$html,'</pre></body></html>');
85    
86                    ($pre_html,$pages,$post_html) = ($1,$2,$3) if ($html =~ m/^(<html>.+?<pre>)(.+)(<\/pre>.+?)$/si);
87    
88                    if ($collection) {
89                            $pre_html =~ s/<title>(.+?)<\/title>/<title>$collection :: page ##page_nr##<\/title>/si;
90                    } else {
91                            $pre_html =~ s/<title>(.+?)<\/title>/<title>$1 :: page ##page_nr##<\/title>/si ||
92                            $pre_html =~ s/<title><\/title>/<title>$file_only :: page ##page_nr##<\/title>/si;
93                    }
94    
95                    my $page_nr = 1;
96                    foreach my $page (split(/\f/s,$pages)) {
97                            print STDERR " $page_nr" if ($verbose);
98                            my $pre_tmp = $pre_html;
99                            $pre_tmp =~ s/##page_nr##/$page_nr<\/title>/s;
100                            dump_contents($pre_tmp . $page . $post_html,time(), $path) if ($page !~ m/^\s*$/s);
101                            $page_nr++;
102                    }
103    
104          } else {          } else {
105    
106                  return if (! -f $path || ! m/\.html*$/i);                  return if (! -f $path || ! m/\.(html*|php|pl|txt|info|log|text)$/i);
107    
108                  # skip index files                  # skip index files
109                  return if (m/index_[a-z]\.html*/i || m/index_symbol\.html*/i);                  return if (m/index_[a-z]\.html*/i || m/index_symbol\.html*/i);
# Line 68  sub file { Line 116  sub file {
116                  $contents .= "\n\n";                  $contents .= "\n\n";
117    
118                  $contents = filter($contents,$collection);                  $contents = filter($contents,$collection);
         }  
   
 #       die "zero size content in '$path'" if (! $contents);  
         return if (! $contents);        # don't die on empty files  
   
         my $mtime = time;  
         use bytes;  
         my $size = length $contents;  
119    
120          print STDERR " [$size]\n" if ($verbose);                  # add optional components to path
121                    $path .= " $path_add" if ($path_add);
122    
123          # add optional components to path                  dump_contents($contents,time(), $path);
124          $path .= " $path_add" if ($path_add);          }
   
         # Output the document (to swish)  
         print <<EOF;  
 Path-Name: $path  
 Content-Length: $size  
 Last-Mtime: $mtime  
 Document-Type: HTML  
125    
126  EOF          print STDERR "\n" if ($verbose);
127          print $contents;  #       die "zero size content in '$path'" if (! $contents);
128    
129  }  }
130    

Legend:
Removed from v.63  
changed lines
  Added in v.84

  ViewVC Help
Powered by ViewVC 1.1.26