daemon that reads keystrokes from /dev/input/event* and acts on the "multimedia keys"
[soepkiptng.git] / soepkiptng_status
blobfcb50023940b1f943ec71b9910a21f2190e99b31
1 #!/usr/bin/perl
2 ############################################################################
3 # soepkiptng (c) copyright 2000 Eric Lammerts <eric@lammerts.org>.
4 # $Id$
5 ############################################################################
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License, version 2, as
8 # published by the Free Software Foundation.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # A copy of the GNU General Public License is available on the World Wide Web
16 # at `http://www.gnu.org/copyleft/gpl.html'. You can also obtain it by
17 # writing to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 # Boston, MA 02111-1307, USA.
19 ############################################################################
21 use Cwd 'abs_path';
22 use DBI;
23 use Getopt::Std;
25 # find program directory
26 $_ = $0;
27 while(-l) {
28 my $l = readlink or die "readlink $_: $!\n";
29 if($l =~ m|^/|) { $_ = $l; } else { s|[^/]*$|/$l|; }
31 m|(.*)/|;
32 my $progdir = abs_path($1);
34 require "$progdir/soepkiptng.lib";
36 getopts('c:');
38 read_configfile(\%conf, $opt_c);
40 $| = 1;
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 $SIG{'HUP'} = sub {
46 exec $0;
47 die;
50 for(;; sleep 1) {
51 $newmtime = (stat $conf{statusfile})[9];
52 next if $newmtime == $mtime;
53 $mtime = $newmtime;
54 if(open F, $conf{statusfile}) {
55 chop($nowplaying = <F>);
56 close F;
58 my $query = "SELECT song.title as title,artist.name as artist,album.name as album,song.id,song.track" .
59 " FROM song,artist,album" .
60 " WHERE song.id=?" .
61 " AND song.artist_id=artist.id AND song.album_id=album.id";
62 my $sth = $dbh->prepare($query);
63 my $rv = $sth->execute($nowplaying);
64 if($now_playing = $sth->fetchrow_hashref) {
65 printf "\n%s\n%s\n [%02d] %s\r",
66 $now_playing->{artist},
67 $now_playing->{title},
68 $now_playing->{track},
69 $now_playing->{album} or exit;
70 } else {
71 print "\n\n\n\n" or exit;