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");
42 $progname =~ s/^.*\/(.*?)$/$1/;
45 my $id_date = $rcs_id;
46 $id_date =~ s/^.*?\d+ (\d\d\d\d-.*?\d\d:\d\d:\d\d\S+).*/$1/;
48 push(@main::version_array
, $rcs_id);
50 Getopt
::Long
::Configure
("bundling");
52 "author|a=s" => \
$Opt{'author'},
53 "debug" => \
$Opt{'debug'},
54 "description|d=s" => \
$Opt{'description'},
55 "help|h" => \
$Opt{'help'},
56 "verbose|v+" => \
$Opt{'verbose'},
57 "version" => \
$Opt{'version'},
58 ) || die("$progname: Option error. Use -h for help.\n");
60 $Opt{'debug'} && ($Debug = 1);
61 $Opt{'help'} && usage
(0);
62 $Opt{'version'} && print_version
();
70 for my $fname (@ARGV) {
83 D
("filename = '$filename'");
84 if (open(PicFP
, "exifprobe -L \"$filename\" |")) { # FIXME: Quick & Dirty™
89 $date =~ s/^(\d\d\d\d)(.)(\d\d)(.)(\d\d)(.)(\d\d:\d\d:\d\d)(.*)/$1-$3-$5 $7$8/;
95 @Dates = reverse sort @Dates;
97 defined($date) || ($date = '');
98 D
("final date = '$date'");
99 if ($date =~ /^\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d$/) {
100 $filename =~ s/^.*\/(.*?)$/$1/;
101 my $Output = join("\t",
102 postgresql_copy_safe
($date),
103 length($coor) ? postgresql_copy_safe
($coor) : $NA,
104 length($Opt{'description'}) ? postgresql_copy_safe
($Opt{'description'}) : $NA,
105 length($filename) ? postgresql_copy_safe
($filename) : $NA,
106 length($Opt{'author'}) ? postgresql_copy_safe
($Opt{'author'}) : $NA
109 $Opt{'verbose'} && print(STDERR
$Output);
112 warn("$filename: $date: Invalid date format");
117 warn("$filename: Cannot open exifprobe(1) pipe: $!");
125 # Print program version {{{
126 for (@main::version_array
) {
134 # Send the help message to stdout {{{
141 Usage: $progname [options] [file [files [...]]]
143 Extract EXIF info from pictures for use with PostgreSQL's COPY command.
144 If no filenames are specified on the command line, file names are read
150 Specify author of picture.
152 Specify description for picture.
156 Increase level of verbosity. Can be repeated.
158 Print version information.
160 Print debugging messages.
168 # Print a status message to stderr based on verbosity level {{{
169 my ($verbose_level, $Txt) = @_;
171 if ($Opt{'verbose'} >= $verbose_level) {
172 print(STDERR
"$progname: $Txt\n");
178 # Print a debugging message {{{
180 my @call_info = caller;
181 chomp(my $Txt = shift);
182 my $File = $call_info[1];
184 $File =~ s
#^.*/(.*?)$#$1#;
185 print(STDERR
"$File:$call_info[2] $$ $Txt\n");
192 # Plain Old Documentation (POD) {{{
206 [options] [file [files [...]]]
216 =item B<-h>, B<--help>
218 Print a brief help summary.
220 =item B<-v>, B<--verbose>
222 Increase level of verbosity. Can be repeated.
226 Print version information.
230 Print debugging messages.
240 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
244 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
245 This is free software; see the file F<COPYING> for legalese stuff.
249 This program is free software; you can redistribute it and/or modify it
250 under the terms of the GNU General Public License as published by the
251 Free Software Foundation; either version 2 of the License, or (at your
252 option) any later version.
254 This program is distributed in the hope that it will be useful, but
255 WITHOUT ANY WARRANTY; without even the implied warranty of
256 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
257 See the GNU General Public License for more details.
259 You should have received a copy of the GNU General Public License along
260 with this program; if not, write to the Free Software Foundation, Inc.,
261 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
269 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :