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