]> git.sesse.net Git - pr0n/blob - perl/make-jxl.pl
Fix an (irrelevant) confusion about addEventListener.
[pr0n] / perl / make-jxl.pl
1 #! /usr/bin/perl
2
3 use lib qw(.);
4 use DBI;
5 use POSIX;
6 use Sesse::pr0n::Common;
7 use strict;
8 use warnings;
9
10 use Sesse::pr0n::Config;
11 eval {
12         require Sesse::pr0n::Config_local;
13 };
14
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;
19
20 # TODO: Do we need to care about renders?
21 for my $id (@ARGV) {
22         my $dir = POSIX::floor($id / 256);
23         my $base = $Sesse::pr0n::Config::image_base . "cache/$dir";
24         my @res = ();
25         for my $file (<$base/$id-*-nobox.jpg>) {   # TODO: --1--1.jpg, too.
26                 my $fname = File::Basename::basename($file);
27                 my ($width, $height) = $fname =~ /^$id-(\d+)-(\d+)-nobox\.jpg$/ or die $fname;
28                 (my $jxl_file = $file) =~ s/jpg$/jxl/;
29                 unless (-r $jxl_file) {
30                         push @res, ($width, $height);
31                         print "$id to $width x $height...\n";
32                 }
33         }
34         if (scalar @res > 0) {
35                 my $filename = Sesse::pr0n::Common::get_disk_location({}, $id);
36
37                 # Look up the width/height in the database.
38                 my ($dbwidth, $dbheight);
39                 my $ref = $dbh->selectrow_hashref('SELECT width,height FROM images WHERE id=?', undef, $id);
40                 $dbwidth = $ref->{'width'};
41                 $dbheight = $ref->{'height'};
42
43                 Sesse::pr0n::Common::make_cache({}, $filename, $id, $dbwidth, $dbheight, 'jxl', @res);
44         }       
45 }