my $format = '$artist - $title';
GetOptions (
- "libnotify!" => \$use_libnotify,
- "libpurple!" => \$use_libpurple,
- "format=s" => \$format,
+ "libnotify!" => \$use_libnotify,
+ "libpurple!" => \$use_libpurple,
+ "format=s" => \$format,
);
my $xmms = Audio::XMMSClient->new('xmms2-notifyd');
##################################################
sub notify_libnotify{
- $notify->update($_[0]);
- $notify->show;
+ $notify->update($_[0]);
+ $notify->show;
}
sub notify{
- my $id=$xmms->playback_current_id->wait->value or return;
- my $minfo=$xmms->medialib_get_info($id)->wait->value;
+ my $id=$xmms->playback_current_id->wait->value or return;
+ my $minfo=$xmms->medialib_get_info($id)->wait->value;
- my %metadata = map { $_ => exists $minfo->{$_} ? (values $minfo->{$_})[0] : undef } CONVERSION_SPECIFIERS;
- my $str=$format;
- $str =~ s/\$$_/$metadata{$_}/g for keys %metadata;
+ my %metadata = map { $_ => exists $minfo->{$_} ? (values $minfo->{$_})[0] : undef } CONVERSION_SPECIFIERS;
+ my $str=$format;
+ $str =~ s/\$$_/$metadata{$_}/g for keys %metadata;
- notify_libnotify $str if $use_libnotify;
-# notify_libpurple $str if $use_libpurple;
+ notify_libnotify $str if $use_libnotify;
+ # notify_libpurple $str if $use_libpurple;
}
sub on_playback_current_id {
- notify;
- $xmms->broadcast_playback_current_id->notifier_set(\&on_playback_current_id);
+ notify;
+ $xmms->broadcast_playback_current_id->notifier_set(\&on_playback_current_id);
}
sub on_playback_status {
- notify if $xmms->playback_status->wait->value == 1; # 1 means playing, 2 means paused
- $xmms->broadcast_playback_status->notifier_set(\&on_playback_status);
+ notify if $xmms->playback_status->wait->value == 1; # 1 means playing, 2 means paused
+ $xmms->broadcast_playback_status->notifier_set(\&on_playback_status);
}
sub run {
- while(1){
- last if ($xmms->connect);
- sleep 1
- }
-
- $xmms->broadcast_playback_current_id->notifier_set(\&on_playback_current_id);
- $xmms->broadcast_playback_status->notifier_set(\&on_playback_status);
- $xmms->loop
+ while (1) {
+ last if ($xmms->connect);
+ sleep 1
+ }
+
+ $xmms->broadcast_playback_current_id->notifier_set(\&on_playback_current_id);
+ $xmms->broadcast_playback_status->notifier_set(\&on_playback_status);
+ $xmms->loop
}
1