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