1 package App
::XMMS2
::Notifier
;
5 our $VERSION = 0.001001;
7 use Audio
::XMMSClient
0.03;
8 use Gtk2
::Notify
0.05 -init
,'xmms2-notifyd';
12 use constant CONVERSION_SPECIFIERS
=> qw
/bitrate date sample_format url id channels samplerate tracknr genre artist album title/;
14 ##################################################
16 my $use_libnotify = 1;
18 my $format = '$artist - $title';
21 "libnotify!" => \
$use_libnotify,
22 "libpurple!" => \
$use_libpurple,
23 "format=s" => \
$format,
26 my $xmms = Audio
::XMMSClient
->new('xmms2-notifyd');
27 my $notify = Gtk2
::Notify
->new('');
29 $notify->set_timeout(3000);
31 ##################################################
34 $notify->update($_[0]);
39 my $id=$xmms->playback_current_id->wait->value or return;
40 my $minfo=$xmms->medialib_get_info($id)->wait->value;
42 my %metadata = map { $_ => exists $minfo->{$_} ?
(values $minfo->{$_})[0] : undef } CONVERSION_SPECIFIERS
;
44 $str =~ s/\$$_/$metadata{$_}/g for keys %metadata;
46 notify_libnotify
$str if $use_libnotify;
47 # notify_libpurple $str if $use_libpurple;
50 sub on_playback_current_id
{
52 $xmms->broadcast_playback_current_id->notifier_set(\
&on_playback_current_id
);
55 sub on_playback_status
{
56 notify
if $xmms->playback_status->wait->value == 1; # 1 means playing, 2 means paused
57 $xmms->broadcast_playback_status->notifier_set(\
&on_playback_status
);
62 last if ($xmms->connect);
66 $xmms->broadcast_playback_current_id->notifier_set(\
&on_playback_current_id
);
67 $xmms->broadcast_playback_status->notifier_set(\
&on_playback_status
);
77 App::XMMS2::Notifier - script which notifies you what xmms2 is playing
81 # Shows libnotify notifications e.g. "Silence - Cellule"
84 # Shows libnotify notifications e.g. "Cellule by Silence (L'autre endroit), year 2005, genre Electro"
85 xmms2-notifier --format="$title by $artist ($album), year $date, genre $genre"
89 xmms2-notifier is a script which shows libnotify notifications when
90 the song is changed and when the playback is started/resumed.
92 You can control the notification format with the B<--format> argument.
93 The following strings are replaced:
99 The song bitrate, in bits/s. Example: 785104
103 Usually the year the song was published. Example: 2005
107 The format of each sample. Example: S16
111 An URL that points to the song. Example: file:///ext/Music/Silence+-+Cellule.flac
115 The XMMS2 id of the song. Example: 498
119 The number of channels the song has. Example: 2
123 The sample rate of the song, in Hz. Example: 44100
127 The track number in the album. Example: 1
131 The genre of the song. Example: Electro
135 The artist/band. Example: Silence
139 The album the song is from. Example: L'autre endroit
143 The song title. Example: Cellule
153 Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
155 =head1 COPYRIGHT AND LICENSE
157 Copyright (C) 2013 by Marius Gavrilescu
159 This library is free software; you can redistribute it and/or modify
160 it under the same terms as Perl itself, either Perl version 5.14.2 or,
161 at your option, any later version of Perl 5 you may have available.