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