diff --git a/schedule/ics.php b/schedule/ics.php index 863972d..f715547 100644 --- a/schedule/ics.php +++ b/schedule/ics.php @@ -1,35 +1,7 @@ [ - "method" => "GET", - "header" => "X-API-Key: $apikey\r\n" - ] -]); - $from = gmdate("Y-m-d\T00:00:00\Z", strtotime(date("w") ? "last sunday" : "sunday")); $to = gmdate("Y-m-d\T00:00:00\Z", strtotime(date("w") ? "sunday" : "next sunday")); - -$schedule = json_decode( - file_get_contents( - "https://radio.tildeverse.org/api/station/1/streamers/schedule?start=$from&end=$to", - false, - $context - ), - true -); - -usort($schedule, function ($a, $b) { - return $a["start"] <=> $b["start"]; -}); - -function formatdate($date) { - return gmdate("Ymd\THis\Z", strtotime($date)); -} +include 'schedule.php'; // ICS generation. Here be dragons. // I created the file using a Python script and reverse-engineered it to figure this out. diff --git a/schedule/index.php b/schedule/index.php index 6840910..acaf7ed 100644 --- a/schedule/index.php +++ b/schedule/index.php @@ -1,36 +1,6 @@ [ - "method" => "GET", - "header" => "X-API-Key: $apikey\r\n" - ] -]); - -$from = gmdate("Y-m-d\TH:i:s\Z", strtotime("now + 1 day")); -$to = gmdate("Y-m-d\TH:i:s\Z", strtotime("now + 8 days")); - -$schedule = json_decode( - file_get_contents( - "https://radio.tildeverse.org/api/station/1/streamers/schedule?start=$from&end=$to", - false, - $context - ), - true -); - -usort($schedule, function ($a, $b) { - return $a["start"] <=> $b["start"]; -}); - -function formatdate($date) { - return gmdate("D M d H:i", strtotime($date)); -} +include 'schedule.php'; ?>

tilderadio.org

diff --git a/schedule/schedule.php b/schedule/schedule.php new file mode 100644 index 0000000..8912041 --- /dev/null +++ b/schedule/schedule.php @@ -0,0 +1,37 @@ + [ + "method" => "GET", + "header" => "X-API-Key: $apikey\r\n" + ] +]); + +// allow ics.php to overwrite $from and $to +if (!isset($from,$to)) { + $from = gmdate("Y-m-d\TH:i:s\Z", strtotime("now + 1 day")); + $to = gmdate("Y-m-d\TH:i:s\Z", strtotime("now + 8 days")); +} + +$schedule = json_decode( + file_get_contents( + "https://radio.tildeverse.org/api/station/1/streamers/schedule?start=$from&end=$to", + false, + $context + ), + true +); + +usort($schedule, function ($a, $b) { + return $a["start"] <=> $b["start"]; +}); + +function formatdate($date) { + return gmdate("D M d H:i", strtotime($date)); +} +