summaryrefslogtreecommitdiff
path: root/util/unusedimages.pl
diff options
context:
space:
mode:
Diffstat (limited to 'util/unusedimages.pl')
-rwxr-xr-xutil/unusedimages.pl30
1 files changed, 18 insertions, 12 deletions
diff --git a/util/unusedimages.pl b/util/unusedimages.pl
index 55797c97..01678f77 100755
--- a/util/unusedimages.pl
+++ b/util/unusedimages.pl
@@ -14,10 +14,13 @@ use Cwd 'abs_path';
my $ROOT;
BEGIN { ($ROOT = abs_path $0) =~ s{/util/unusedimages\.pl$}{}; }
+$ENV{VNDB_VAR} //= 'var';
+
my $db = DBI->connect('dbi:Pg:dbname=vndb', 'vndb', undef, { RaiseError => 1 });
my $count = 0;
-my $fnmatch = '/(cv|ch|sf|st)/[0-9][0-9]/([1-9][0-9]{0,6})\.jpg';
+my $dirmatch = '/(cv|ch|sf|st)(?:\.orig|\.t)?/';
+my $fnmatch = $dirmatch.'[0-9][0-9]/([1-9][0-9]{0,6})\.(?:jpg|webp|png|avif|jxl)?';
my(%scr, %cv, %ch);
my %dir = (cv => \%cv, ch => \%ch, sf => \%scr, st => \%scr);
@@ -48,20 +51,24 @@ sub cleandb {
SELECT vndbid(case when img[1] = 'st' then 'sf' else img[1] end, img[2]::int)
FROM ( SELECT content FROM docs
UNION ALL SELECT content FROM docs_hist
- UNION ALL SELECT "desc" FROM vn
- UNION ALL SELECT "desc" FROM vn_hist
- UNION ALL SELECT "desc" FROM chars
- UNION ALL SELECT "desc" FROM chars_hist
- UNION ALL SELECT "desc" FROM producers
- UNION ALL SELECT "desc" FROM producers_hist
+ UNION ALL SELECT description FROM vn
+ UNION ALL SELECT description FROM vn_hist
+ UNION ALL SELECT description FROM chars
+ UNION ALL SELECT description FROM chars_hist
+ UNION ALL SELECT description FROM producers
+ UNION ALL SELECT description FROM producers_hist
UNION ALL SELECT notes FROM releases
UNION ALL SELECT notes FROM releases_hist
- UNION ALL SELECT "desc" FROM staff
- UNION ALL SELECT "desc" FROM staff_hist
+ UNION ALL SELECT description FROM staff
+ UNION ALL SELECT description FROM staff_hist
UNION ALL SELECT description FROM tags
+ UNION ALL SELECT description FROM tags_hist
UNION ALL SELECT description FROM traits
+ UNION ALL SELECT description FROM traits_hist
UNION ALL SELECT comments FROM changes
UNION ALL SELECT msg FROM threads_posts
+ UNION ALL SELECT msg FROM reviews_posts
+ UNION ALL SELECT text FROM reviews
) x(text), regexp_matches(text, '}.$fnmatch.q{', 'g') as y(img)
)
) x
@@ -89,11 +96,10 @@ sub findunused {
my $left = 0;
find {
no_chdir => 1,
- follow => 1,
wanted => sub {
return if -d "$File::Find::name";
if($File::Find::name !~ /($fnmatch)$/) {
- print "# Unknown file: $File::Find::name\n";
+ print "# Unknown file: $File::Find::name\n" if $File::Find::name =~ /$dirmatch/;
return;
}
if(!$dir{$2}{$3}) {
@@ -105,7 +111,7 @@ sub findunused {
$left++;
}
}
- }, "$ROOT/static/cv", "$ROOT/static/ch", "$ROOT/static/sf", "$ROOT/static/st";
+ }, "$ENV{VNDB_VAR}/static";
printf "# Deleted %d files, left %d files, saved %d KiB\n", $count, $left, $size;
}