line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::XMMS2::Notifier; |
2
|
1
|
|
|
1
|
|
23782
|
use v5.14; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
42
|
|
3
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
50
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
74
|
|
5
|
|
|
|
|
|
|
our $VERSION = 0.001001; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
507
|
use Audio::XMMSClient 0.03; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
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__ |