-
Notifications
You must be signed in to change notification settings - Fork 4
/
soundbridge-growl
executable file
·61 lines (46 loc) · 1.8 KB
/
soundbridge-growl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env perl
use strict;
use warnings;
use Soundbridge;
use IO::Socket::INET;
use FindBin qw< $Bin >;
use constant ICON => File::Spec->catfile($Bin, 'assets', 'M1001icon.png');
my $sock = IO::Socket::INET->new($Soundbridge::DEFAULT_SERVER)
or die "Unable to bind to soundbridge: $!";
die "Huh?" unless $sock->getline =~ /roku: ready/;
my $current = '';
while (not $sock->error) {
$sock->print("GetCurrentSongInfo\n");
my %data;
while ($_ = $sock->getline) {
#GetCurrentSongInfo: id: Preset 5
#GetCurrentSongInfo: remoteStream: 1
#GetCurrentSongInfo: format: remotePLS
#GetCurrentSongInfo: status: playable
#GetCurrentSongInfo: title: Jim Bianco - Talented
#GetCurrentSongInfo: artist: 89.9 KCRW Eclectic Music - Santa Monica
#GetCurrentSongInfo: songFormat: pls
#GetCurrentSongInfo: playlistURL: http://media.kcrw.com/live/kcrwmusic.pls
#GetCurrentSongInfo: resource[0] url: http://205.188.234.2:80/stream/1045
#GetCurrentSongInfo: resource[0] format: unknown
#GetCurrentSongInfo: OK
s/^GetCurrentSongInfo:\s*//;
s/[\r\n]//g;
last if /^OK/;
my ($key, $val) = split /: /, $_, 2;
$val =~ s/(?:^\s*|\s*$)//;
$data{$key} = $val;
}
$data{album} = '' if not exists $data{album};
if ($data{playlistURL} and $data{playlistURL} =~ /kcrwmusic\.pls/) {
@data{qw(artist title)} = split / - /, $data{title}, 2;
}
my $playing = sprintf "%s by %s from %s", @data{qw(title artist album)};
if ($playing ne $current) {
$current = $playing;
system 'notify-send', '--icon', ICON, $data{title}, join "\n", grep { defined and length } @data{qw(artist album)}
unless $data{artist} =~ /kcrw/i;
}
sleep 10;
}
$sock->close;