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