pldb (list): Add `-w' option to show a window around the group position(s).
[dvddb] / lookup-dvd-id
CommitLineData
14acb11f
MW
1#! /usr/bin/perl
2
3use open ":utf8";
4use strict;
5
6use DBI;
7use Getopt::Std;
8
9BEGIN { binmode STDOUT, ":utf8"; }
10
11(my $prog = $0) =~ s:^.*/::;
12sub HELP_MESSAGE ($;@) {
13 my ($fh) = @_;
14 print $fh "usage: $prog [-ps] DISC-ID ...\n";
15}
16my $ROOT = "/mnt/dvd/archive";
17
18my $bogusp = 0;
19my %opt;
20getopts("hps", \%opt) or $bogusp = 1;
21if ($opt{"h"}) { HELP_MESSAGE \*STDOUT; exit 0; }
22@ARGV or $bogusp = 1;
23if ($bogusp) { HELP_MESSAGE \*STDERR; exit 2; }
24$opt{"p"} || $opt{"s"} or $opt{"p"} = 1;
25
26my $DB = DBI->connect("dbi:Pg:host=roadstar", "", "",
27 { AutoCommit => 0,
28 RaiseError => 1,
29 ReadOnly => 1 });
30
b2a25885
MW
31my $st = $DB->prepare
32 ("SELECT s.name, d.disc, d.path
33 FROM dvd_disc AS d JOIN dvd_set AS s ON d.set_id = s.id
34 WHERE d.disc_id = ?");
14acb11f
MW
35
36my $rc = 0;
37for my $id (@ARGV) {
38 $st->execute($id);
39 my @r = $st->fetchrow_array; $st->finish;
40 if (!@r) { print STDERR "$prog: unknown id `$id'\n"; $rc = 1; }
41 else {
42 my ($name, $disc, $path) = @r;
43 @ARGV > 1 and print "$id: ";
44 if ($opt{"s"}) { print "$name (#$disc)"; }
45 if ($opt{"p"} && $opt{"s"}) { print " ["; }
46 if ($opt{"p"}) { print $path; }
47 if ($opt{"p"} && $opt{"s"}) { print "]"; }
48 print "\n";
49 }
50}
51
52$DB->disconnect;
53exit $rc;