Import App::XMMS2::Notifier 0.001
[app-xmms2-notifier.git] / lib / App / XMMS2 / Notifier.pm
... / ...
CommitLineData
1package App::XMMS2::Notifier 0.001;
2use v5.14;
3use warnings;
4
5use Audio::XMMSClient 0.03;
6use Gtk2::Notify 0.05 -init,'xmms2-notifyd';
7
8use Getopt::Long;
9
10use constant CONVERSION_SPECIFIERS => qw/bitrate date sample_format url id channels samplerate tracknr genre artist album title/;
11
12##################################################
13
14my $use_libnotify = 1;
15my $use_libpurple;
16my $format = '$artist - $title';
17
18GetOptions (
19 "libnotify!" => \$use_libnotify,
20 "libpurple!" => \$use_libpurple,
21 "format=s" => \$format,
22);
23
24my $xmms = Audio::XMMSClient->new('xmms2-notifyd');
25my $notify = Gtk2::Notify->new('');
26
27$notify->set_timeout(3000);
28
29##################################################
30
31sub notify_libnotify{
32 $notify->update($_[0]);
33 $notify->show;
34}
35
36sub notify{
37 my $id=$xmms->playback_current_id->wait->value or return;
38 my $minfo=$xmms->medialib_get_info($id)->wait->value;
39
40 my %metadata = map { $_ => exists $minfo->{$_} ? (values $minfo->{$_})[0] : undef } CONVERSION_SPECIFIERS;
41 my $str=$format;
42 $str =~ s/\$$_/$metadata{$_}/g for keys %metadata;
43
44 notify_libnotify $str if $use_libnotify;
45# notify_libpurple $str if $use_libpurple;
46}
47
48sub on_playback_current_id {
49 notify;
50 $xmms->broadcast_playback_current_id->notifier_set(\&on_playback_current_id);
51}
52
53sub on_playback_status {
54 notify if $xmms->playback_status->wait->value == 1; # 1 means playing, 2 means paused
55 $xmms->broadcast_playback_status->notifier_set(\&on_playback_status);
56}
57
58sub run {
59 while(1){
60 last if ($xmms->connect);
61 sleep 1
62 }
63
64 $xmms->broadcast_playback_current_id->notifier_set(\&on_playback_current_id);
65 $xmms->broadcast_playback_status->notifier_set(\&on_playback_status);
66 $xmms->loop
67}
68
691
70
71__END__
72
73=head1 NAME
74
75App::XMMS2::Notifier - script which notifies you what xmms2 is playing
76
77=head1 SYNOPSIS
78
79 # Shows libnotify notifications e.g. "Silence - Cellule"
80 xmms2-notifier
81
82 # Shows libnotify notifications e.g. "Cellule by Silence (L'autre endroit), year 2005, genre Electro"
83 xmms2-notifier --format="$title by $artist ($album), year $date, genre $genre"
84
85=head1 DESCRIPTION
86
87xmms2-notifier is a script which shows libnotify notifications when
88the song is changed and when the playback is started/resumed.
89
90You can control the notification format with the B<--format> argument.
91The following strings are replaced:
92
93=over
94
95=item $bitrate
96
97The song bitrate, in bits/s. Example: 785104
98
99=item $date
100
101Usually the year the song was published. Example: 2005
102
103=item $sample_format
104
105The format of each sample. Example: S16
106
107=item $url
108
109An URL that points to the song. Example: file:///ext/Music/Silence+-+Cellule.flac
110
111=item $id
112
113The XMMS2 id of the song. Example: 498
114
115=item $channels
116
117The number of channels the song has. Example: 2
118
119=item $samplerate
120
121The sample rate of the song, in Hz. Example: 44100
122
123=item $tracknr
124
125The track number in the album. Example: 1
126
127=item $genre
128
129The genre of the song. Example: Electro
130
131=item $artist
132
133The artist/band. Example: Silence
134
135=item $album
136
137The album the song is from. Example: L'autre endroit
138
139=item $title
140
141The song title. Example: Cellule
142
143=back
144
145=head1 SEE ALSO
146
147L<xmms2(1)>
148
149=head1 AUTHOR
150
151Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
152
153=head1 COPYRIGHT AND LICENSE
154
155Copyright (C) 2013 by Marius Gavrilescu
156
157This library is free software; you can redistribute it and/or modify
158it under the same terms as Perl itself, either Perl version 5.14.2 or,
159at your option, any later version of Perl 5 you may have available.
160
161
162=cut
This page took 0.009013 seconds and 4 git commands to generate.