3 # Warning: This is sort of outdated now. :-/
13 use Sesse::pr0n::Config;
15 require Sesse::pr0n::Config_local;
18 my $dbh = DBI->connect("dbi:Pg:dbname=pr0n;host=" . $Sesse::pr0n::Config::db_host,
19 $Sesse::pr0n::Config::db_username, $Sesse::pr0n::Config::db_password)
20 or die "Couldn't connect to PostgreSQL database: " . DBI->errstr;
21 $dbh->{RaiseError} = 1;
23 my $q = $dbh->prepare('SELECT id FROM images WHERE id NOT IN ( SELECT DISTINCT image FROM exif_info ) ORDER BY id');
26 while (my $ref = $q->fetchrow_hashref) {
27 my $id = $ref->{'id'};
29 # Copied almost verbatim from Sesse::pr0n::Common::update_image_info
30 my $info = Image::ExifTool::ImageInfo(get_disk_location($id));
31 my $width = $info->{'ImageWidth'} || -1;
32 my $height = $info->{'ImageHeight'} || -1;
35 if (defined($info->{'DateTimeOriginal'})) {
36 # Parse the date and time over to ISO format
37 if ($info->{'DateTimeOriginal'} =~ /^(\d{4}):(\d\d):(\d\d) (\d\d):(\d\d):(\d\d)(?:\+\d\d:\d\d)?$/ && $1 > 1990) {
38 $datetime = "$1-$2-$3 $4:$5:$6";
43 local $dbh->{AutoCommit} = 0;
45 $dbh->do('UPDATE images SET width=?, height=?, date=? WHERE id=?',
46 undef, $width, $height, $datetime, $id)
47 or die "Couldn't update width/height in SQL: $!";
49 $dbh->do('DELETE FROM exif_info WHERE image=?',
51 or die "Couldn't delete old EXIF information in SQL: $!";
53 my $q = $dbh->prepare('INSERT INTO exif_info (image,tag,value) VALUES (?,?,?)')
54 or die "Couldn't prepare inserting EXIF information: $!";
56 for my $key (keys %$info) {
57 next if ref $info->{$key};
58 $q->execute($id, $key, guess_charset($info->{$key}))
59 or die "Couldn't insert EXIF information in database: $!";
62 # update the last_picture cache as well (this should of course be done
63 # via a trigger, but this is less complicated :-) )
64 $dbh->do('UPDATE last_picture_cache SET last_picture=GREATEST(last_picture, ?) WHERE event=(SELECT event FROM images WHERE id=?)',
65 undef, $datetime, $id)
66 or die "Couldn't update last_picture in SQL: $!";
69 print "Updated $id.\n";
72 sub get_disk_location {
74 my $dir = POSIX::floor($id / 256);
75 return "/srv/pr0n.sesse.net/images/$dir/$id.jpg";
83 $decoded = Encode::decode("utf-8", $text, Encode::FB_CROAK);
86 $decoded = Encode::decode("iso8859-1", $text);