17 |
my $exclude; |
my $exclude; |
18 |
|
|
19 |
#$verbose = 1; |
#$verbose = 1; |
20 |
|
my $debug = 0; |
21 |
|
my $force = 0; |
22 |
|
|
23 |
my $result = GetOptions( |
my $result = GetOptions( |
24 |
"collection=s" => \$collection, |
"collection=s" => \$collection, |
25 |
"path=s" => \$path_add, |
"path=s" => \$path_add, |
26 |
"verbose!" => \$verbose, |
"verbose!" => \$verbose, |
27 |
"debug!" => \$verbose, |
"debug!" => \$debug, |
28 |
"exclude=s" => \$exclude, |
"exclude=s" => \$exclude, |
29 |
"node=s" => \$node_url, |
"node=s" => \$node_url, |
30 |
|
"force!" => \$force, |
31 |
); |
); |
32 |
|
|
33 |
my $dir = shift @ARGV || die "usage: $0 [dir]"; |
my $dir = shift @ARGV || die "usage: $0 [dir]"; |
101 |
# create a document object |
# create a document object |
102 |
my $doc = HyperEstraier::Document->new; |
my $doc = HyperEstraier::Document->new; |
103 |
|
|
104 |
my $title = $1 if ($contents =~ m#<title>(.+)</title>#is); |
my $title = $1 if ($contents =~ m#<title>(.+?)</title>#is); |
105 |
|
|
106 |
# chop long titles to 100 chars |
# chop long titles to 100 chars |
107 |
$title = substr($title, 0, 100) . '...' if ($title && length($title) > 100); |
$title = substr($title, 0, 100) . '...' if ($title && length($title) > 100); |
136 |
my $path = $_; |
my $path = $_; |
137 |
my $contents; |
my $contents; |
138 |
|
|
139 |
return if (-l $path || $path =~ m#/.svn#); |
return if (! $force && -l $path || $path =~ m#/.svn# || $path =~ m/(~|.bak)$/); |
140 |
|
|
141 |
|
my $mtime = (stat($path))[9]; |
142 |
|
my $mtime_db = $db->get_doc_attr_by_uri("file:///$path", '@mtime') || -2; |
143 |
|
|
144 |
|
if ($mtime == $mtime_db) { |
145 |
|
print STDERR "# same: $path $mtime\n" if ($verbose); |
146 |
|
return unless($force); |
147 |
|
} else { |
148 |
|
print STDERR "# changed: $path $mtime != $mtime_db\n" if ($debug); |
149 |
|
} |
150 |
|
|
151 |
|
# skip files on which File::MMagic::XS croaks |
152 |
|
return if ($path =~ m#\.au$#); |
153 |
|
|
154 |
my $type = $mm->checktype_filename($path); |
my $type = $mm->checktype_filename($path); |
155 |
$type =~ s/\s+/ /gs; |
$type =~ s/\s+/ /gs; |
156 |
|
|
157 |
print STDERR "# $path $type\n" if ($verbose); |
print STDERR "# $path $type\n" if ($debug); |
158 |
|
|
159 |
if ($pdftotext && -f $path && $type =~ m/pdf/i) { |
if ($pdftotext && -f $path && $type =~ m/pdf/i) { |
160 |
|
|
191 |
print STDERR " $page_nr" if ($verbose); |
print STDERR " $page_nr" if ($verbose); |
192 |
my $pre_tmp = $pre_html; |
my $pre_tmp = $pre_html; |
193 |
$pre_tmp =~ s/##page_nr##/$page_nr<\/title>/s; |
$pre_tmp =~ s/##page_nr##/$page_nr<\/title>/s; |
194 |
dump_contents($db, $pre_tmp . $page . $post_html,time(), $path) if ($page !~ m/^\s*$/s); |
dump_contents($db, $pre_tmp . $page . $post_html, $mtime, "$path#$page_nr") if ($page !~ m/^\s*$/s); |
195 |
$page_nr++; |
$page_nr++; |
196 |
} |
} |
197 |
|
|
198 |
} else { |
} else { |
199 |
|
|
200 |
# return if (! -f $path || ! m/\.(html*|php|pl|txt|info|log|text)$/i); |
# return if (! -f $path || ! m/\.(html*|php|pl|txt|info|log|text)$/i); |
201 |
return if (! -f $path || ( |
return unless (-f $path && $type =~ m/html/ || |
202 |
$type !~ m/html/ || |
($type =~ m#text# && $path =~ m/\.(php|pl|txt|info|log|text)$/io) |
203 |
($type !~ m#text/plain# && m/\.(php|pl|txt|info|log|text)$/) |
); |
|
)); |
|
204 |
|
|
205 |
# skip index files |
# skip index files |
206 |
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); |
217 |
# add optional components to path |
# add optional components to path |
218 |
$path .= " $path_add" if ($path_add); |
$path .= " $path_add" if ($path_add); |
219 |
|
|
220 |
dump_contents($db, $contents,time(), $path); |
dump_contents($db, $contents, $mtime, $path); |
221 |
} |
} |
222 |
|
|
223 |
print STDERR "\n" if ($verbose); |
print STDERR "\n" if ($verbose); |