Add next DJ to home page
continuous-integration/drone/pr Build encountered an error Details

Fixes #11. Also adds schedule/nextdj.php, which outputs the same text, for use elsewhere TBD.
This commit is contained in:
Robert Miles 2020-09-27 04:54:31 +00:00
parent 7d40425445
commit 3150e62a31
2 changed files with 55 additions and 1 deletions

View File

@ -15,7 +15,7 @@ TildeRadio is Internet radio streamed by / for users of the tildeverse.
<p>Join the conversation <a href="https://kiwi.tilde.chat/#tilderadio" target="_blank">Here</a></p>
<br>
<br>
<p><?php include 'schedule/nextdj.php'; ?></p>
<hr>
<p>
<iframe src="https://radio.tildeverse.org/public/tilderadio/embed" frameborder="0" allowtransparency="true" style="width: 100%; min-height: 160px; border: 0;"></iframe>

54
schedule/nextdj.php Normal file
View File

@ -0,0 +1,54 @@
<?php
include 'apikey.php';
if (empty($apikey)) {
/* If we don't have the API key, assume we're developing. Pull data from live version of this file */
$context = stream_context_create([
"http" => [
"method" => "GET",
]
]);
$schedule = json_decode(file_get_contents("https://tilderadio.org/schedule/nextdj.php?json=true", false, $context), true);
} else {
$context = stream_context_create([
"http" => [
"method" => "GET",
"header" => "X-API-Key: $apikey\r\n"
]
]);
$schedule = json_decode(
file_get_contents(
"https://radio.tildeverse.org/api/station/1/schedule?rows=2",
false,
$context
),
true
);
}
if (isset($_GET["json"]) && $_GET["json"] === "yes") {
echo json_encode($schedule);
} else {
$data = $schedule[0];
if ((strtotime($data["start"])-strtotime("now"))<0) {
echo $data["name"]." should be streaming now, and ";
$data = $schedule[1];
}
echo $data["name"]." will stream at ".gmdate("D M d H:i",strtotime($data["start"]))." UTC (in ";
$diff = strtotime($data["start"])-strtotime("now");
if ($diff<60) {
echo "".$diff." seconds)";
} else {
$minutes = intdiv($diff,60);
$seconds = $diff % 60;
if ($minutes<60) {
echo "".$minutes." minutes and ".$seconds." seconds)";
} else {
$hours = intdiv($minutes,60);
$minutes = $minutes % 60;
echo "".$hours." hours, ".$minutes." minutes and ".$seconds." seconds)";
}
}
echo ".";
}