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