&$stream) { $stream["url"] = "$GLOBALS[frairable_host]$GLOBALS[frairable_uri_meta]$id/$GLOBALS[frairable_part_play]$index"; } return $data; } function get_radio_play($id, $index) { $data = get_radio_data($id); // Clone loves to complain about the stream not being an object... // Deep clone using json is ugly, but eh. $stream = json_decode(json_encode($data["streams"][$index]), true); // The redirect ID can be anything, as long as it is unique. // It doesn't need to match with the URI. $stream["id"] = ["frontiersmart", "redirect", "$GLOBALS[frairable_part_custom]$id/$GLOBALS[frairable_part_play]$index"]; $stream["content"] = $data; unset($stream["reliability"]); return $stream; } // Routing if ($_SERVER["REQUEST_URI"] === "/frontiersmart/radios") { // Stock starting point - add our own entry here. respond_with_proxy(function(&$data) { array_push($data["content"]["entries"], [ "id" => [ "frontiersmart", "directory", "custom" ], "title" => "Frairable (Custom)", "url" => "$GLOBALS[frairable_host]$GLOBALS[frairable_uri_listing]" ]); }); } elseif ($_SERVER["REQUEST_URI"] === $GLOBALS["frairable_uri_listing"]) { // Our custom menu with our own entries. $entries = []; foreach (new DirectoryIterator($GLOBALS["frairable_dir_radios"]) as $sub) { if ($sub->isDot() || $sub->isDir()) { continue; } $id = basename($sub->getFilename(), ".json"); $entries[] = get_radio_entry($id); } $data = [ "id" => [ "frontiersmart", "directory", "custom" ], "title" => "Frairable (Custom)", "url" => "$GLOBALS[frairable_host]$GLOBALS[frairable_uri_listing]", "content" => [ "entries" => $entries ] ]; respond_with_json($data); } elseif (str_starts_with($_SERVER["REQUEST_URI"], $GLOBALS["frairable_uri_meta"])) { // The radio fetches different radio info multiple times: // - Metadata when selecting the entry, containing a list of streams. // - Playing info after the radio picked a stream to play. // See the dumped meta.json and play.json for more info.. and to witness the complex redundancy. $id = substr($_SERVER["REQUEST_URI"], strlen($GLOBALS["frairable_uri_meta"])); $split = strpos($id, "/$GLOBALS[frairable_part_play]"); if ($split) { $index = intval(substr($id, $split + strlen("/$GLOBALS[frairable_part_play]"))); $id = substr($id, 0, $split); respond_with_json(get_radio_play($id, $index)); } else { respond_with_json(get_radio_meta($id)); } } else { respond_with_proxy(); } ?>