-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathslimp3.pl
144 lines (117 loc) · 3.79 KB
/
slimp3.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/perl -w
# Logitech Media Server Copyright 2003-2011 Logitech.
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License,
# version 2.
#
# Command line interface for the controlling the Logitech Media Server
#
use strict;
use Getopt::Long;
use LWP::Simple;
sub main {
my $httpaddr = undef;
my $httpport = undef;
my $player = undef;
my $command = undef;
my $p1 = undef;
my $p2 = undef;
my $p3 = undef;
my $p4 = undef;
GetOptions(
'httpaddr=s' => \$httpaddr,
'httpport=s' => \$httpport,
'player=s' => \$player,
'command=s' => \$command,
'p1=s' => \$p1,
'p2=s' => \$p2,
'p3=s' => \$p3,
'p4=s' => \$p4,
);
if ( (!defined($command)) ||
(!defined($httpaddr)) ||
(!defined($httpport)) ) {
showUsage();
}
else {
executeCommand($httpaddr, $httpport, $player, $command, $p1, $p2, $p3, $p4);
}
} # end sub main
# Commands are extracted from the parameters p0, p1, p2, p3, & p4.
# For example:
# http://host/status.html?p0=stop
# Both examples above execute a stop command, and sends an html status response
#
# Command parameters are query parameters named p0, p1, p2, p3 and p4
# For example:
# http://host/status.m3u?p0=playlist&p1=jump&p2=2
# This example jumps to the second song in the playlist and sends a playlist as the response
#
# If there are multiple players, then they are specified by the player id
# For example:
# http://host/status.html?p0=mixer&p1=volume&p2=11&player=10.0.1.203:69
#
sub executeCommand {
my ($httpaddr, $httpport, $player, $command, $p1, $p2, $p3, $p4) = @_;
my $urlstring = undef;
my $content = undef;
$urlstring = "http://$httpaddr:$httpport/status.html?p0=$command";
if ( defined($p1) ) {
$p1 =~s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/eg;
$urlstring .= "&p1=" . $p1;
}
if ( defined($p2) ) {
$p2 =~s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/eg;
$urlstring .= "&p2=" . $p2;
}
if ( defined($p3) ) {
$p3 =~s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/eg;
$urlstring .= "&p3=" . $p3;
}
if ( defined($p4) ) {
$p4 =~s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/eg;
$urlstring .= "&p4=" . $p4;
}
if ( defined($player) ) {
$player =~s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/eg;
$urlstring .= "&player=" . $player;
}
$urlstring .= "\n";
unless (defined ($content = get($urlstring))) {
die "could not get $urlstring\n";
}
print $urlstring, "\n";
} # end sub executeCommand
sub showUsage {
print <<EOF;
Usage: $0 --httpaddr <host|ip> --httpport <port> --command <command>
[--p1 <arg>] [--p2 <arg>] [--p3 <arg>] [--p4 <arg>] [--player <playerid>]
--httpaddr => The hostname or ip address of the Slim web server
--httpport => The port on which the Slim web server is listening
--command => Pick from the 1st column of the list below
--p1 => Pick from the 2st column of the list below
--p2 => Pick from the 3rd column of the list below
--p3 => Pick from the 4th column of the list below
--p4 => Pick from the 5th column of the list below
--player => Currently the "ip:port" of your player
COMMAND P1 P2 P3 P4
play
pause (0|1|)
stop
sleep (0..n)
playlist play <song>
playlist load <playlist>
playlist append <playlist>
playlist clear
playlist move <fromoffset> <tooffset>
playlist delete <songoffset>
playlist jump <index>
mixer volume (0 .. 100)|(-100 .. +100)
mixer balance (-100 .. 100)|(-200 .. +200)
mixer base (0 .. 100)|(-100 .. +100)
mixer treble (0 .. 100)|(-100 .. +100)
status
display <line1> <line2> (duration)
EOF
} # end sub showUsage
main();