-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.php
More file actions
executable file
·148 lines (139 loc) · 5.37 KB
/
index.php
File metadata and controls
executable file
·148 lines (139 loc) · 5.37 KB
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
144
145
146
<?php
/*
Example of an API using SimpleMPDWrapper and https://github.com/marcj/php-rest-service
*/
include 'vendor/autoload.php';
include 'helpers/BaseUrl.php';
include 'MPDWrapper/SimpleMPDWrapper.php';
use MPDWrapper\SimpleMPDWrapper;
use RestService\Server;
Server::create('/')
->addGetRoute('', function(){
$baseUrl = new BaseUrl();
$response = array(
'message' => 'Welcome to the Mutant MPD API',
'view this nicely' => 'http://jsonview.com/',
'menu' => array(
'status' => $baseUrl->url()."status",
'add song' => $baseUrl->url()."add",
'control player' => $baseUrl->url()."control",
'current song' => $baseUrl->url()."current",
'volume to integer' => $baseUrl->url()."volume",
'volume up' => $baseUrl->url()."volUp",
'volume down' => $baseUrl->url()."volDown",
'clear playlist' => $baseUrl->url()."clear"
)
);
return $response;
})
->addGetRoute('status',function(){
$mp = new SimpleMPDWrapper("","192.168.1.121",6600,0);
return $mp->status();
})
->addGetRoute('add/(.*)', function($data){
$mp = new SimpleMPDWrapper("","192.168.1.121",6600,0);
$response = array(
'message' => 'track sent to mutant playlist',
'track' => $data,
'response' => $mp->add($data)
);
return $response;
})
->addGetRoute('add', function(){
$baseUrl = new BaseUrl();
$response = array(
'message' => 'Requires a valid spotify URI',
'options' => array(
'default' => array(
"description" => "spotify URI",
"example" => $baseUrl->url()."/spotify:track:48mZ0CGCffjH49h5lAPTIe"
)
)
);
return $response;
})
->addGetRoute('control',function(){
$baseUrl = new BaseUrl();
$response = array(
'message' => 'play, pause etc',
'options' => array(
'e.g.' => array(
"play" => $baseUrl->url()."/play",
"pause" => $baseUrl->url()."/pause"
)
)
);
return $response;
})
->addGetRoute('control/(.*)',function($action){
$mp = new SimpleMPDWrapper("","192.168.1.121",6600,0);
return $mp->send($action, "");
})
->addGetRoute('current',function(){
$mp = new SimpleMPDWrapper("","192.168.1.121",6600,0);
return $mp->currentSong();
})
->addGetRoute('volume',function(){
$baseUrl = new BaseUrl();
$response = array(
'message' => 'set vol to integer',
'options' => array(
'e.g.' => array(
"50%" => $baseUrl->url()."/50",
"100%" => $baseUrl->url()."/100"
)
)
);
return $response;
})
->addGetRoute('volume/(.*)',function($volume){
$mp = new SimpleMPDWrapper("","192.168.1.121",6600,0);
return $mp->send('setvol', $volume);
})
->addGetRoute('getVolume',function(){
$mp = new SimpleMPDWrapper("","192.168.1.121",6600,0);
$data = $mp->send('status');
$volume = explode(":",$data['ret'][0]);
return array('volume' => (int)$volume[1]);
})
->addGetRoute('volUp',function(){
$mp = new SimpleMPDWrapper("","192.168.1.121",6600,0);
$data = $mp->status();
$volume = explode(":",$data['ret'][0]);
$newVolume = $volume[1] + 1;
$mp->send('setvol', (int)$newVolume);
return array(
'volume' => (int)$newVolume
);
})
->addGetRoute('volDown',function(){
$mp = new SimpleMPDWrapper("","192.168.1.121",6600,0);
$data = $mp->send('status');
$volume = explode(":",$data['ret'][0]);
$newVolume = $volume[1] - 1;
$mp->send('setvol', (int)$newVolume);
return array(
'volume' => (int)$newVolume
);
})
->addGetRoute('clear',function(){
$mp = new SimpleMPDWrapper("","192.168.1.121",6600,0);
return $mp->send('clear');
})
->addGetRoute('random/(.*)',function($int){
$mp = new SimpleMPDWrapper("","192.168.1.121",6600,0);
return $mp->send('random', $int);
})
->addGetRoute('repeat/(.*)',function($int){
$mp = new SimpleMPDWrapper("","192.168.1.121",6600,0);
return $mp->send('repeat', $int);
})
->addGetRoute('playlist',function(){
$mp = new SimpleMPDWrapper("","192.168.1.121",6600,0);
return $mp->send('playlistinfo');
})
->addGetRoute('move/(.*)/(.*)',function($from,$to){
$mp = new SimpleMPDWrapper("","192.168.1.121",6600,0);
return $mp->move($from,$to);
})
->run();