3 #=======================================================================
5 # Extract EXIF data from pictures for use with COPY in Postgres
8 # ©opyleft 2008– Øyvind A. Holm <sunny@sunbase.org>
9 # License: GNU General Public License version 2 or later, see end of
10 # file for legal stuff.
11 #=======================================================================
21 push(@INC, "$ENV{'HOME'}/bin/src/gpstools");
33 'output-format' => 'pgtab',
40 'output-format' => $Std{'output-format'},
46 $progname =~ s/^.*\/(.*?)$/$1/;
49 my $id_date = $rcs_id;
50 $id_date =~ s/^.*?\d+ (\d\d\d\d-.*?\d\d:\d\d:\d\d\S+).*/$1/;
52 push(@main::version_array
, $rcs_id);
54 Getopt
::Long
::Configure
("bundling");
56 "author|a=s" => \
$Opt{'author'},
57 "debug" => \
$Opt{'debug'},
58 "description|d=s" => \
$Opt{'description'},
59 "help|h" => \
$Opt{'help'},
60 "output-format|o=s" => \
$Opt{'output-format'},
61 "verbose|v+" => \
$Opt{'verbose'},
62 "version" => \
$Opt{'version'},
63 ) || die("$progname: Option error. Use -h for help.\n");
65 $Opt{'debug'} && ($Debug = 1);
66 $Opt{'help'} && usage
(0);
67 if ($Opt{'version'}) {
72 if ($Opt{'output-format'} eq "xml") {
73 print("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<gpstpic>\n");
82 for my $fname (@ARGV) {
87 if ($Opt{'output-format'} eq "xml") {
88 print("</gpstpic>\n");
99 D
("filename = '$filename'");
100 if (open(PicFP
, "exifprobe -L \"$filename\" |")) { # FIXME: Quick & Dirty™
105 $date =~ s/^(\d\d\d\d)(.)(\d\d)(.)(\d\d)(.)(\d\d:\d\d:\d\d)(.*)/$1-$3-${5}T$7$8/;
111 @Dates = reverse sort @Dates;
113 defined($date) || ($date = '');
114 D
("final date = '$date'");
115 if ($date =~ /^\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d$/) {
116 $filename =~ s/^.*\/(.*?)$/$1/;
118 if ($Opt{'output-format'} eq "xml") {
119 if (length("$filename$date")) {
123 ?
sprintf(" <filename>%s</filename>\n",
124 txt_to_xml
($filename))
127 ?
sprintf(" <date>%s</date>\n",
133 } elsif ($Opt{'output-format'} eq "pgtab") {
135 postgresql_copy_safe
($date),
137 ? postgresql_copy_safe
($coor)
139 length($Opt{'description'})
140 ? postgresql_copy_safe
($Opt{'description'})
143 ? postgresql_copy_safe
($filename)
145 length($Opt{'author'})
146 ? postgresql_copy_safe
($Opt{'author'})
150 die("$progname: $Opt{'output-format'}: Unknown output format\n");
153 $Opt{'verbose'} && print(STDERR
$Output);
156 warn("$filename: $date: Invalid date format");
161 warn("$filename: Cannot open exifprobe(1) pipe: $!");
169 # Print program version {{{
170 for (@main::version_array
) {
177 # Send the help message to stdout {{{
180 if ($Opt{'verbose'}) {
186 Usage: $progname [options] [file [files [...]]]
188 Extract EXIF info from pictures for use with PostgreSQL's COPY command.
189 If no filenames are specified on the command line, file names are read
195 Specify author of picture.
197 Specify description for picture.
201 Increase level of verbosity. Can be repeated.
202 -o x, --output-format x
203 Create output of type x:
206 Default: "$Std{'output-format'}".
208 Print version information.
210 Print debugging messages.
218 # Print a status message to stderr based on verbosity level {{{
219 my ($verbose_level, $Txt) = @_;
221 if ($Opt{'verbose'} >= $verbose_level) {
222 print(STDERR
"$progname: $Txt\n");
228 # Print a debugging message {{{
230 my @call_info = caller;
231 chomp(my $Txt = shift);
232 my $File = $call_info[1];
234 $File =~ s
#^.*/(.*?)$#$1#;
235 print(STDERR
"$File:$call_info[2] $$ $Txt\n");
242 # Plain Old Documentation (POD) {{{
256 [options] [file [files [...]]]
266 =item B<-h>, B<--help>
268 Print a brief help summary.
270 =item B<-v>, B<--verbose>
272 Increase level of verbosity. Can be repeated.
276 Print version information.
280 Print debugging messages.
290 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
294 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
295 This is free software; see the file F<COPYING> for legalese stuff.
299 This program is free software; you can redistribute it and/or modify it
300 under the terms of the GNU General Public License as published by the
301 Free Software Foundation; either version 2 of the License, or (at your
302 option) any later version.
304 This program is distributed in the hope that it will be useful, but
305 WITHOUT ANY WARRANTY; without even the implied warranty of
306 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
307 See the GNU General Public License for more details.
309 You should have received a copy of the GNU General Public License along
310 with this program; if not, write to the Free Software Foundation, Inc.,
311 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
319 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :