-
Notifications
You must be signed in to change notification settings - Fork 2
/
squeeze-volume.pl
60 lines (52 loc) · 1.44 KB
/
squeeze-volume.pl
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/perl
use strict;
use URI::Escape qw(uri_escape uri_unescape);
use Socket qw(SOCK_STREAM inet_ntoa);
use IO::Socket::INET;
use IO::Select;
my $host = '10.42.66.2';
my $player = 'be:e0:e6:04:46:38';
{
my $socket;
sub squeeze {
my @args = @_;
$_ = uri_escape($_) for @args;
$socket && $socket->connected or $socket = IO::Socket::INET->new(
PeerHost => "$host:9090",
Type => SOCK_STREAM,
) or return;
$socket->print("@args\n");
my @reply = split " ", readline $socket;
$_ = uri_unescape($_) for @reply;
return @reply;
}
}
sub group {
my $firstkey = shift;
my $returncommon = $firstkey =~ s/^-//;
my $common;
my @items;
while (defined (my $input = shift)) {
if ($input =~ /:/) {
my ($key, $value) = split /:/, $input, 2;
$key =~ s/ /_/g;
if ($key eq $firstkey) {
push @items, { $key => $value };
} elsif (@items) {
$items[-1]{ $key } = $value;
} else {
$common->{ $key } = $value;
}
} else {
push @{ $common->{_} }, $_;
}
}
return $common, @items if $returncommon;
return @items;
}
sub squeeze_volume {
my ($status, @plist) = group
-playlist_index => squeeze $player, qw'status - 1';
return $status->{mixer_volume} //= 0;
}
print squeeze_volume, "\n";