#! /usr/bin/perl use open ":utf8"; use strict; use DBI; use Getopt::Std; BEGIN { binmode STDOUT, ":utf8"; } (my $prog = $0) =~ s:^.*/::; sub HELP_MESSAGE ($;@) { my ($fh) = @_; print $fh "usage: $prog [-ps] DISC-ID ...\n"; } my $ROOT = "/mnt/dvd/archive"; my $bogusp = 0; my %opt; getopts("hps", \%opt) or $bogusp = 1; if ($opt{"h"}) { HELP_MESSAGE \*STDOUT; exit 0; } @ARGV or $bogusp = 1; if ($bogusp) { HELP_MESSAGE \*STDERR; exit 2; } $opt{"p"} || $opt{"s"} or $opt{"p"} = 1; my $DB = DBI->connect("dbi:Pg:host=roadstar", "", "", { AutoCommit => 0, RaiseError => 1, ReadOnly => 1 }); my $st = $DB->prepare("SELECT s.name, d.disc, d.path FROM dvd_disc AS d JOIN dvd_set AS s ON d.set_id = s.id WHERE d.disc_id = ?"); my $rc = 0; for my $id (@ARGV) { $st->execute($id); my @r = $st->fetchrow_array; $st->finish; if (!@r) { print STDERR "$prog: unknown id `$id'\n"; $rc = 1; } else { my ($name, $disc, $path) = @r; @ARGV > 1 and print "$id: "; if ($opt{"s"}) { print "$name (#$disc)"; } if ($opt{"p"} && $opt{"s"}) { print " ["; } if ($opt{"p"}) { print $path; } if ($opt{"p"} && $opt{"s"}) { print "]"; } print "\n"; } } $DB->disconnect; exit $rc;