This repository has been archived by the owner on May 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathget_station_url.php
65 lines (57 loc) · 2.03 KB
/
get_station_url.php
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
<?php
if (!isset($_REQUEST['format']) || !isset($_REQUEST['stationid'])) {
echo 'parameters missing!';
exit();
}
require 'db.php';
$db = openDB();
$stationid = $_REQUEST['stationid'];
$format = $_REQUEST['format'];
$stmt = $db->prepare('SELECT Name, Url, UrlCache FROM Station WHERE LastCheckOK=TRUE AND StationID=:stationid');
$stmt->execute(['stationid'=>$stationid]);
if ($stmt->rowCount() !== 1) {
http_response_code(404);
exit();
}
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$url = $row['Url'];
$stationname = $row['Name'];
$audiofile = $row['UrlCache'];
if ($audiofile !== false) {
if ($format == 'xml') {
header('Content-Type: text/xml');
echo '<?xml version="1.0"?>';
echo "<result><station id='".$stationid."' url='".$audiofile."'/></result>";
clickedStationID($db, $stationid);
} elseif ($format == 'json') {
header('Content-Type: application/json');
echo '[{';
echo "\"ok\":\"true\",";
echo "\"message\":\"retrieved station url successfully\",";
echo "\"id\":\"$stationid\",";
//echo "\"name\":\"$stationname\",";
echo "\"name\":".json_encode($stationname).",";
echo '"url":"'.$audiofile.'"';
echo '}]';
clickedStationID($db, $stationid);
} elseif ($format == 'pls') {
//header('content-type: audio/x-scpls');
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=radio.pls');
header('Content-Transfer-Encoding: chunked'); //changed to chunked
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
echo "[playlist]\n";
echo "NumberOfEntries=1\n";
echo "Version=2\n";
echo 'File1='.$audiofile."\n";
echo 'Title1='.$stationname;
clickedStationID($db, $stationid);
} else {
echo 'unknown format';
}
} else {
http_response_code(404);
}