7 use Encode
qw{encode_utf8 decode_utf8
};
10 BEGIN { binmode STDOUT
, ":utf8"; }
12 my $ROOT = "/mnt/dvd/archive";
13 my $DB = DBI
->connect("dbi:Pg:host=roadstar", "", "",
20 if (/\.iso$/ && ! -l
&& -f
) {
21 my $fn = decode_utf8
$File::Find
::name
;
30 my $st_set = $DB->prepare("SELECT id, name, n_disc FROM dvd_set");
31 my $st_disc = $DB->prepare
32 ("SELECT disc, path, box FROM dvd_disc WHERE set_id = ? ORDER BY disc");
35 while (my @r = $st_set->fetchrow_array) {
36 my ($id, $name, $ndisc) = @r;
39 $st_disc->execute($id);
40 while (my @r = $st_disc->fetchrow_array) {
41 my ($disc, $path, $box) = @r;
42 $disc == @path or die "bad disc sequence for `$name'";
43 $box{$path} = $box if defined $box;
46 @path == $ndisc or die "wrong number of discs for `$name'";
47 $set_path{$name} = \
@path; $set_id{$name} = $id;
50 for my $name (keys %set_path) {
52 for my $path (@
{$set_path{$name}}) {
53 if (defined $path && exists $iso{$path}) { delete $iso{$path}; }
56 ##if ($allp) { delete $set_path{$name}; }
59 my @iso = sort keys %iso;
64 if ($box ne $lastbox) { print "!box $box\n"; $lastbox = $box; }
67 for my $name (sort { $set_path{$a}[0] cmp $set_path{$b}[0] }
69 my $paths = $set_path{$name};
71 set_box
$box{$paths->[0]};
72 while (@iso && $iso[0] lt $paths->[0]) { push @unk, shift @iso; }
75 for my $path (@unk) { print "\t", $path, "\n"; }
77 printf "[#%d: %d] %s\n", $set_id{$name}, scalar @
$paths, $name;
79 for my $path (@
$paths) {
82 printf "\t!! (disc %d)\n", $i;
84 my $fn = "$ROOT/$path";
86 if (-f
$fn && ! -l
$fn) { print "\t" . $path . "\n"; }
87 else { print "\t!! ". $path . "\n"; }
94 for my $path (@iso) { print "\t", $path, "\n"; }