use -V0 --vbr-new by default; add -O option
[soepkiptng.git] / soepkiptng_show_lyrics
blob23863999f720e1a142401ed93cb8593c67a79324
1 #!/usr/bin/perl
2 ############################################################################
3 # soepkiptng (c) copyright 2000 Eric Lammerts <eric@lammerts.org>.
4 ############################################################################
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License, version 2, as
7 # published by the Free Software Foundation.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # A copy of the GNU General Public License is available on the World Wide Web
15 # at `http://www.gnu.org/copyleft/gpl.html'. You can also obtain it by
16 # writing to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 # Boston, MA 02111-1307, USA.
18 ############################################################################
20 use integer;
21 use Cwd 'abs_path';
22 use DBI;
23 use Socket;
24 use Getopt::Std;
25 use POSIX ":sys_wait_h";
27 # find program directory
28 $_ = $0;
29 while(-l) {
30 my $l = readlink or die "readlink $_: $!\n";
31 if($l =~ m|^/|) { $_ = $l; } else { s|[^/]*$|/$l|; }
33 m|(.*)/|;
34 my $progdir = abs_path($1);
36 require "$progdir/soepkiptng.lib";
38 getopts('avnc:g');
40 read_configfile(\%conf, $opt_c);
42 $dbh = connect_to_db(\%conf);
44 $pid = 0;
45 open STDOUT, ">/dev/null";
46 $SIG{CHLD} = sub {
47 while(waitpid(-1,WNOHANG) > 0) {
48 exit 0 if $@ == 0;
51 for(;;) {
52 while((stat $conf{statusfile})[9] == $mtime) { sleep 1; }
53 $mtime = (stat _)[9];
54 if($pid) { kill 9, $pid; wait; }
55 print STDERR "\n"x100;
56 open F, $conf{statusfile} or next;
57 chop($id = <F>);
58 close F;
60 ($lyrics, $ar, $ti, $al, $tr) = $dbh->selectrow_array(
61 "SELECT lyrics.lyrics, artist.name, song.title, album.name, song.track " .
62 "FROM song " .
63 "LEFT JOIN album ON album.id=song.album_id " .
64 "LEFT JOIN artist ON artist.id=song.artist_id " .
65 "LEFT JOIN lyrics ON lyrics.id=song.id " .
66 "WHERE song.id=$id");
67 $lyrics or next;
69 pipe STDIN, STDOUT;
70 if(($pid = fork) == 0) {
71 open STDOUT, ">/dev/tty";
72 exec "less", "-c";
73 die "less -c: $!\n";
75 close STDIN;
76 $t = "$ar - $ti ($al [$tr])";
77 print "$t\n";
78 print "-" x length($t);
79 print "\n\n$lyrics\n";
80 close STDOUT;