Merge branch 'topic/sweetums' (early part)
[soepkiptng.git] / soepkiptng_show_lyrics
blobdd52c06cd45a383e663f7ed6076ddb4b7956d689
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 = DBI->connect("DBI:$conf{db_type}:$conf{db_name}:$conf{db_host}",
43 $conf{db_user}, $conf{db_pass}) or die "can't connect to database";
45 $pid = 0;
46 open STDOUT, ">/dev/null";
47 $SIG{CHLD} = sub {
48 while(waitpid(-1,WNOHANG) > 0) {
49 exit 0 if $@ == 0;
52 for(;;) {
53 while((stat $conf{statusfile})[9] == $mtime) { sleep 1; }
54 $mtime = (stat _)[9];
55 if($pid) { kill 9, $pid; wait; }
56 print STDERR "\n"x100;
57 open F, $conf{statusfile} or next;
58 chop($id = <F>);
59 close F;
61 ($lyrics, $ar, $ti, $al, $tr) = $dbh->selectrow_array(
62 "SELECT lyrics.lyrics, artist.name, song.title, album.name, song.track " .
63 "FROM song " .
64 "LEFT JOIN album ON album.id=song.album_id " .
65 "LEFT JOIN artist ON artist.id=song.artist_id " .
66 "LEFT JOIN lyrics ON lyrics.id=song.id " .
67 "WHERE song.id=$id");
68 $lyrics or next;
70 pipe STDIN, STDOUT;
71 if(($pid = fork) == 0) {
72 open STDOUT, ">/dev/tty";
73 exec "less", "-c";
74 die "less -c: $!\n";
76 close STDIN;
77 $t = "$ar - $ti ($al [$tr])";
78 print "$t\n";
79 print "-" x length($t);
80 print "\n\n$lyrics\n";
81 close STDOUT;