X-Git-Url: http://git.ieval.ro/?p=app-xmms2-notifier.git;a=blobdiff_plain;f=lib%2FApp%2FXMMS2%2FNotifier.pm;h=e68566ee205c522f13430ad0e1ec0c3e04e42e1c;hp=d04b638abc192b126291b5df501a1bffae6a7395;hb=9399d920cdc7d5a23eea029d88d6a857978e68b0;hpb=f3286fcdcb8b72114af37942582795b08dbc0a74 diff --git a/lib/App/XMMS2/Notifier.pm b/lib/App/XMMS2/Notifier.pm index d04b638..e68566e 100644 --- a/lib/App/XMMS2/Notifier.pm +++ b/lib/App/XMMS2/Notifier.pm @@ -1,24 +1,17 @@ package App::XMMS2::Notifier; -use v5.14; +use 5.014000; use strict; use warnings; -our $VERSION = 0.001001; +our $VERSION = 0.001002; 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,12 +25,15 @@ 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 %metadata = map { $_ => exists $minfo->{$_} ? (values %{$minfo->{$_}})[0] : undef } CONVERSION_SPECIFIERS; my $str=$format; - $str =~ s/\$$_/$metadata{$_}/g for keys %metadata; + $str =~ s/\$$_/$metadata{$_}/gs for keys %metadata; notify_libnotify $str } @@ -53,6 +49,7 @@ sub on_playback_status { } sub run { + $format = $_[0]; while (1) { last if ($xmms->connect); sleep 1 @@ -63,8 +60,7 @@ sub run { $xmms->loop } -1 - +1; __END__ =head1 NAME @@ -149,7 +145,7 @@ Marius Gavrilescu, Emarius@ieval.roE =head1 COPYRIGHT AND LICENSE -Copyright (C) 2013 by Marius Gavrilescu +Copyright (C) 2013-2016 by Marius Gavrilescu This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.14.2 or,