get_library(); $library_size = count($library); $maxpage = ceil($library_size/$pagesize); if ($page > $maxpage) $page = $maxpage; $startindex = ($page - 1) * $pagesize; $partial_library = array_slice($library, $startindex, $pagesize); if ($format == "html") { $previous = $page - 1; if ($previous < 1) $previous = 1; $next = $page + 1; if ($next > $maxpage) $next = $maxpage; $start = file_get_contents("resources/start.html"); $start = str_replace("{{ STYLE }}", file_get_contents("resources/style.css"), $start); echo $start; echo '

Page ' . $page . '/' . $maxpage . ' of osu! songs

'; echo '[Back]     '; echo '[Previous] '; echo '[Next] '; echo "
";
	// print_r($partial_library);
	foreach ($partial_library as $key => $value)
	{
		$firstdiff = $value["difficulties"][array_key_first($value["difficulties"])];
		$diffcount = 0;
		foreach ($value["difficulties"] as $diff)
		{
			if ($diff["format"] != "storyboard")
			{
				$diffcount++;
			}
		}
		if ($diffcount == 1) $difftext = "difficulty";
		else $difftext = "difficulties";
		echo $value["id"] . ": " . $firstdiff["Metadata"]["Artist"] . " - " . $firstdiff["Metadata"]["Title"] . " (" . $diffcount . " {$difftext})\n";
	}
}
else // default to json in every other case
{
	$response = array(
		"page" => $page,
		"maxpage" => $maxpage,
		"pagesize" => $pagesize,
		"mapsets" => $partial_library ?? array(),
	);
	
	header('Content-Type: application/json');
	echo json_encode($response);
}