X-Git-Url: https://git.sesse.net/?p=pr0n;a=blobdiff_plain;f=perl%2Fmake-avif.pl;fp=perl%2Fmake-avif.pl;h=2db57091ac5c1d498cf698011c8ada58fb654102;hp=0000000000000000000000000000000000000000;hb=84460e4c9e238c3f3b661756796f764df2441aaa;hpb=98da70a27673e32530c404401d3e2c6dff3fcde4 diff --git a/perl/make-avif.pl b/perl/make-avif.pl new file mode 100755 index 0000000..2db5709 --- /dev/null +++ b/perl/make-avif.pl @@ -0,0 +1,45 @@ +#! /usr/bin/perl + +use lib qw(.); +use DBI; +use POSIX; +use Sesse::pr0n::Common; +use strict; +use warnings; + +use Sesse::pr0n::Config; +eval { + require Sesse::pr0n::Config_local; +}; + +my $dbh = DBI->connect("dbi:Pg:dbname=pr0n;host=" . $Sesse::pr0n::Config::db_host, + $Sesse::pr0n::Config::db_username, $Sesse::pr0n::Config::db_password) + or die "Couldn't connect to PostgreSQL database: " . DBI->errstr; +$dbh->{RaiseError} = 1; + +# TODO: Do we need to care about renders? +for my $id (@ARGV) { + my $dir = POSIX::floor($id / 256); + my $base = $Sesse::pr0n::Config::image_base . "cache/$dir"; + my @res = (); + for my $file (<$base/$id-*-nobox.jpg>) { # TODO: --1--1.jpg, too. + my $fname = File::Basename::basename($file); + my ($width, $height) = $fname =~ /^$id-(\d+)-(\d+)-nobox\.jpg$/ or die $fname; + (my $avif_file = $file) =~ s/jpg$/avif/; + unless (-r $avif_file) { + push @res, ($width, $height); + print "$id to $width x $height...\n"; + } + } + if (scalar @res > 0) { + my $filename = Sesse::pr0n::Common::get_disk_location({}, $id); + + # Look up the width/height in the database. + my ($dbwidth, $dbheight); + my $ref = $dbh->selectrow_hashref('SELECT width,height FROM images WHERE id=?', undef, $id); + $dbwidth = $ref->{'width'}; + $dbheight = $ref->{'height'}; + + Sesse::pr0n::Common::make_cache({}, $filename, $id, $dbwidth, $dbheight, 'avif', @res); + } +}