Prevent crashes
[app-xmms2-notifier.git] / lib / App / XMMS2 / Notifier.pm
index d04b638abc192b126291b5df501a1bffae6a7395..3ce6645126aa158621a51fca498506476e8dd579 100644 (file)
@@ -7,18 +7,11 @@ our $VERSION = 0.001001;
 use Audio::XMMSClient 0.03;
 use Gtk2::Notify 0.05 -init,'xmms2-notifyd';
 
-use Getopt::Long;
-
 use constant CONVERSION_SPECIFIERS => qw/bitrate date sample_format url id channels samplerate tracknr genre artist album title/;
 
 ##################################################
 
-my $format = '$artist - $title';
-
-GetOptions (
-       "format=s" => \$format,
-);
-
+my $format;
 my $xmms = Audio::XMMSClient->new('xmms2-notifyd');
 my $notify = Gtk2::Notify->new('');
 
@@ -32,8 +25,11 @@ sub notify_libnotify{
 }
 
 sub notify{
-       my $id=$xmms->playback_current_id->wait->value or return;
-       my $minfo=$xmms->medialib_get_info($id)->wait->value;
+       my ($id, $minfo);
+       eval {
+               $id=$xmms->playback_current_id->wait->value or return;
+               $minfo=$xmms->medialib_get_info($id)->wait->value;
+       } or return;
 
        my %metadata = map { $_ => exists $minfo->{$_} ? (values $minfo->{$_})[0] : undef } CONVERSION_SPECIFIERS;
        my $str=$format;
@@ -53,6 +49,7 @@ sub on_playback_status {
 }
 
 sub run {
+       $format = $_[0];
        while (1) {
                last if ($xmms->connect);
                sleep 1
This page took 0.01027 seconds and 4 git commands to generate.