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 #=======================================================================
17 push(@INC, "$ENV{'HOME'}/bin/src/gpstools");
38 $progname =~ s
#^.*/(.*?)$#$1#;
41 my $id_date = $rcs_id;
42 $id_date =~ s/^.*?\d+ (\d\d\d\d-.*?\d\d:\d\d:\d\d\S+).*/$1/;
44 Getopt
::Long
::Configure
("bundling");
46 "author|a=s" => \
$Opt{'author'},
47 "debug" => \
$Opt{'debug'},
48 "description|d=s" => \
$Opt{'description'},
49 "help|h" => \
$Opt{'help'},
50 "verbose|v+" => \
$Opt{'verbose'},
51 "version" => \
$Opt{'version'},
52 ) || die("$progname: Option error. Use -h for help.\n");
54 $Opt{'debug'} && ($Debug = 1);
55 $Opt{'help'} && usage
(0);
56 $Opt{'version'} && print_version
();
64 for my $fname (@ARGV) {
76 D
("filename = '$filename'");
77 if (open(PicFP
, "exifprobe -L \"$filename\" |")) { # FIXME: Quick & Dirty™
82 $date =~ s/^(\d\d\d\d)(.)(\d\d)(.)(\d\d)(.)(\d\d:\d\d:\d\d)(.*)/$1-$3-$5 $7$8/;
88 @Dates = reverse sort @Dates;
90 defined($date) || ($date = '');
91 D
("final date = '$date'");
92 if ($date =~ /^\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d$/) {
93 $filename =~ s/^.*\/(.*?)$/$1/;
94 my $Output = join("\t",
95 postgresql_copy_safe
($date),
96 length($coor) ? postgresql_copy_safe
($coor) : $NA,
97 length($Opt{'description'}) ? postgresql_copy_safe
($Opt{'description'}) : $NA,
98 length($filename) ? postgresql_copy_safe
($filename) : $NA,
99 length($Opt{'author'}) ? postgresql_copy_safe
($Opt{'author'}) : $NA
102 $Opt{'verbose'} && print(STDERR
$Output);
105 warn("$filename: $date: Invalid date format");
110 warn("$filename: Cannot open exifprobe(1) pipe: $!");
117 # Print program version {{{
124 # Send the help message to stdout {{{
131 Usage: $progname [options] [file [files [...]]]
133 Extract EXIF info from pictures for use with PostgreSQL's COPY command.
134 If no filenames are specified on the command line, file names are read
140 Specify author of picture.
142 Specify description for picture.
146 Increase level of verbosity. Can be repeated.
148 Print version information.
150 Print debugging messages.
158 # Print a status message to stderr based on verbosity level {{{
159 my ($verbose_level, $Txt) = @_;
161 if ($Opt{'verbose'} >= $verbose_level) {
162 print(STDERR
"$progname: $Txt\n");
168 # Print a debugging message {{{
170 my @call_info = caller;
171 chomp(my $Txt = shift);
172 my $File = $call_info[1];
174 $File =~ s
#^.*/(.*?)$#$1#;
175 print(STDERR
"$File:$call_info[2] $$ $Txt\n");
182 # Plain Old Documentation (POD) {{{
196 [options] [file [files [...]]]
206 =item B<-h>, B<--help>
208 Print a brief help summary.
210 =item B<-v>, B<--verbose>
212 Increase level of verbosity. Can be repeated.
216 Print version information.
220 Print debugging messages.
230 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
234 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
235 This is free software; see the file F<COPYING> for legalese stuff.
239 This program is free software; you can redistribute it and/or modify it
240 under the terms of the GNU General Public License as published by the
241 Free Software Foundation; either version 2 of the License, or (at your
242 option) any later version.
244 This program is distributed in the hope that it will be useful, but
245 WITHOUT ANY WARRANTY; without even the implied warranty of
246 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
247 See the GNU General Public License for more details.
249 You should have received a copy of the GNU General Public License along
250 with this program; if not, write to the Free Software Foundation, Inc.,
251 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
259 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :