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") {
134 # Version information {{{
135 # Without version field (same as version 1):
137 # "(lat,lon)"-coordinates \t
144 # "(lat,lon)"-coordinates \t
151 postgresql_copy_safe
($date),
153 ? postgresql_copy_safe
($coor)
155 length($Opt{'description'})
156 ? postgresql_copy_safe
($Opt{'description'})
159 ? postgresql_copy_safe
($filename)
161 length($Opt{'author'})
162 ? postgresql_copy_safe
($Opt{'author'})
166 die("$progname: $Opt{'output-format'}: Unknown output format\n");
169 $Opt{'verbose'} && print(STDERR
$Output);
172 warn("$filename: $date: Invalid date format");
177 warn("$filename: Cannot open exifprobe(1) pipe: $!");
185 # Print program version {{{
186 for (@main::version_array
) {
193 # Send the help message to stdout {{{
196 if ($Opt{'verbose'}) {
202 Usage: $progname [options] [file [files [...]]]
204 Extract EXIF info from pictures for use with PostgreSQL's COPY command.
205 If no filenames are specified on the command line, file names are read
211 Specify author of picture.
213 Specify description for picture.
217 Increase level of verbosity. Can be repeated.
218 -o x, --output-format x
219 Create output of type x:
222 Default: "$Std{'output-format'}".
224 Print version information.
226 Print debugging messages.
234 # Print a status message to stderr based on verbosity level {{{
235 my ($verbose_level, $Txt) = @_;
237 if ($Opt{'verbose'} >= $verbose_level) {
238 print(STDERR
"$progname: $Txt\n");
244 # Print a debugging message {{{
246 my @call_info = caller;
247 chomp(my $Txt = shift);
248 my $File = $call_info[1];
250 $File =~ s
#^.*/(.*?)$#$1#;
251 print(STDERR
"$File:$call_info[2] $$ $Txt\n");
258 # Plain Old Documentation (POD) {{{
272 [options] [file [files [...]]]
282 =item B<-h>, B<--help>
284 Print a brief help summary.
286 =item B<-v>, B<--verbose>
288 Increase level of verbosity. Can be repeated.
292 Print version information.
296 Print debugging messages.
306 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
310 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
311 This is free software; see the file F<COPYING> for legalese stuff.
315 This program is free software; you can redistribute it and/or modify it
316 under the terms of the GNU General Public License as published by the
317 Free Software Foundation; either version 2 of the License, or (at your
318 option) any later version.
320 This program is distributed in the hope that it will be useful, but
321 WITHOUT ANY WARRANTY; without even the implied warranty of
322 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
323 See the GNU General Public License for more details.
325 You should have received a copy of the GNU General Public License along
326 with this program; if not, write to the Free Software Foundation, Inc.,
327 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
335 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :