use SNDCTL_DSP_GETODELAY for more accurate time display
[soepkiptng.git] / soepkiptng_status
blob88835e2bf1424ea8f092b33f65c2944c89d6024e
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 Cwd 'abs_path';
21 use DBI;
22 use Getopt::Std;
24 # find program directory
25 $_ = $0;
26 while(-l) {
27 my $l = readlink or die "readlink $_: $!\n";
28 if($l =~ m|^/|) { $_ = $l; } else { s|[^/]*$|/$l|; }
30 m|(.*)/|;
31 my $progdir = abs_path($1);
33 require "$progdir/soepkiptng.lib";
35 getopts('c:');
37 read_configfile(\%conf, $opt_c);
39 $| = 1;
41 $dbh = DBI->connect("DBI:$conf{db_type}:$conf{db_name}:$conf{db_host}",
42 $conf{db_user}, $conf{db_pass}) or die "can't connect to database";
44 $SIG{'HUP'} = sub {
45 exec $0;
46 die;
49 for(;; sleep 1) {
50 $newmtime = (stat $conf{statusfile})[9];
51 next if $newmtime == $mtime;
52 $mtime = $newmtime;
53 if(open F, $conf{statusfile}) {
54 chop($nowplaying = <F>);
55 close F;
57 my $query = "SELECT song.title as title,artist.name as artist,album.name as album,song.id,song.track" .
58 " FROM song,artist,album" .
59 " WHERE song.id=?" .
60 " AND song.artist_id=artist.id AND song.album_id=album.id";
61 my $sth = $dbh->prepare($query);
62 my $rv = $sth->execute($nowplaying);
63 if($now_playing = $sth->fetchrow_hashref) {
64 printf "\n%s\n%s\n [%02d] %s\r",
65 $now_playing->{artist},
66 $now_playing->{title},
67 $now_playing->{track},
68 $now_playing->{album} or exit;
69 } else {
70 print "\n\n\n\n" or exit;