]> git.vpit.fr Git - perl/scripts/xchat.git/blob - mpd.pl
No trailing whitespace
[perl/scripts/xchat.git] / mpd.pl
1 package Xchat::VPIT::MPD;
2
3 use strict;
4 use warnings;
5
6 use Audio::MPD;
7
8 use Xchat qw<:all>;
9
10 use lib get_info 'xchatdir';
11 use Xchat::XPI;
12
13 our $VERSION = 0.04;
14
15 my $ph;
16
17 hook_command $_, sub {
18  my $mpd = Audio::MPD->new;
19  unless ($mpd) {
20   print $ph "Couldn't connect to the MPD server\n";
21   return EAT_ALL;
22  }
23
24  my $status = $mpd->status;
25  unless ($status) {
26   print $ph "MPD doesn't seem to be running\n";
27   return EAT_ALL;
28  }
29  if ($status->state eq 'stop') {
30   print $ph "MPD is stopped\n";
31   return EAT_ALL;
32  }
33
34  my $song = $mpd->current;
35  my $title;
36  if ($title = $song->title) {
37   $title = $_ . ' - ' . $title for grep defined, $song->album, $song->artist;
38  } else {
39   $title = $song->file;
40   $title =~ s!\.\w+$!!;
41   $title = $1 if $title =~ m!/([^/]*)$!;
42  }
43
44  my $time = $status->time;
45  my $duration = sprintf '[%d:%02d/%d:%02d]',
46                         $time->sofar_mins, $time->sofar_secs,
47                         $time->total_mins, $time->total_secs;
48  command 'ACTION np: ' . $title . ' ' . $duration;
49
50  return EAT_ALL;
51 }, {
52  help_text => "$_, output which song is currently played by mpd"
53 } for qw<MPD NP>;
54
55 $ph = Xchat::XPI->new(
56  name   => 'MPD Client',
57  tag    => 'MPD',
58  desc   => 'Music Player Daemon client',
59  author => 'Vincent Pit (VPIT)',
60  email  => 'perl@profvince.com',
61  url    => 'http://www.profvince.com',
62 );
63
64 1;