This repository was archived by the owner on Dec 23, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathindex.php
More file actions
134 lines (86 loc) · 4.54 KB
/
index.php
File metadata and controls
134 lines (86 loc) · 4.54 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
<?php
/*
/* @package IceCast2 PHP API
/* http://github.com/okwinza/icecast2-php-api
/* @author Okwinza
/* This work is licensed under the Creative Commons Attribution 3.0 Unported License.
/* To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/
/* or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.
*/
define('IN_APP', true);
require 'vendor/autoload.php';
require 'icecast_api.php';
require 'config.php';
//initiate Slim
$app = new \Slim\Slim();
//initiate IcecastApi model
$icecastApi = new icecastApi($config);
//No active mounts -- nothing to do here, shutting down...
$active_mounts = $icecastApi->listMounts(true);
if(empty($active_mounts)){
// build response
$response = array(
'type' => '503',
'message' => 'Unavailable'
);
// output response and exit.
$app->halt(503, json_encode($response));
}
//Number of listeners of specified mountpoint.
//(string) :mount => one of the existing mounts
//(string) :responseType => response type(json|xml)
$app->get('/:mount/listeners/:responseType(/)', function ($mount,$responseType) use ($icecastApi, $app) {
$app->response()->header("Content-Type", "application/".$responseType); //setting appropriate headers
echo $icecastApi->Request('GetListeners',array('mount' => $mount))->Response($responseType); //returning response to the client
})->conditions(array("mount" => "(". implode('|',$icecastApi->listMounts()) .")", "responseType" => "(json|xml)")); // Only existing mounts are allowed
//Current track of specified mountpoint.
//(string) :mount => one of the existing mounts
//(string) :responseType => response type(json|xml)
$app->get('/:mount/track/:responseType(/)', function ($mount,$responseType) use ($icecastApi, $app) {
$app->response()->header("Content-Type", "application/".$responseType); //setting appropriate headers
echo $icecastApi->Request('GetTrack',array('mount' => $mount))->Response($responseType); //returning response to the client
})->conditions(array("mount" => "(". implode('|',$icecastApi->listMounts()) .")", "responseType" => "(json|xml)"));
//Last tracks of specified mountpoint.
//(string) :mount => one of the existing mounts
//(int) :amount => amount of tracks to retrieve
//(string) :responseType => response type(json|xml)
$app->get('/:mount/history/:amount/:responseType(/)', function ($mount,$amount,$responseType) use ($icecastApi, $app) {
$app->response()->header("Content-Type", "application/".$responseType); //setting appropriate headers
echo $icecastApi->Request('GetHistory',array('mount' => $mount , 'amount' => $amount))->Response($responseType); //returning response to the client
})->conditions(array("mount" => "(". implode('|',$icecastApi->listMounts()) .")", "amount" => "\d+" , "responseType" => "(json|xml)"));
//Total listeners
//(string) :responseType => response type(json|xml)
$app->get('/totalListeners/:responseType(/)', function ($responseType) use ($icecastApi, $app) {
$app->response()->header("Content-Type", "application/".$responseType); //setting appropriate headers
echo $icecastApi->Request('GetTotalListeners',array())->Response($responseType); //returning response to the client
})->conditions(array("responseType" => "(json|xml)"));
$app->get('/cover/:artist/:song(/)', function ($artist, $song) use ($icecastApi, $app) {
$img = $icecastApi->Request('GetAlbumArt',array('artist' => $artist, 'song' => $song), true)->Response();
$app->response()->header("Content-Type", "image/jpeg"); //setting appropriate headers
$app->response()->header("Content-Length", filesize($img));
readfile($img);
});
$app->get('/cover/:artist(/)', function ($artist) use ($icecastApi, $app) {
$img = $icecastApi->Request('GetArtistArt',array('artist' => $artist), true)->Response();
$app->response()->header("Content-Type", "image/jpeg"); //setting appropriate headers
$app->response()->header("Content-Length", filesize($img));
readfile($img);
});
//Custom method template
/*
$app->get('/customMethod/:responseType(/)', function ($responseType) use ($icecastApi, $app) {
$app->response()->header("Content-Type", "application/".$responseType);
echo $icecastApi->Request('YourCustomMethod',array())->Response($responseType);
})->conditions(array("responseType" => "(json|xml)"));
*/
$app->notFound(function () use ($app) {
// build response
$response = array(
'type' => '400',
'message' => 'Bad request'
);
// output response and exit
$app->halt(400, json_encode($response));
});
$app->run();
?>