Splitter json support

This commit is contained in:
2020-12-26 16:42:51 +01:00
parent d32105e5c5
commit bf60071b83
3 changed files with 93 additions and 48 deletions
+27 -5
View File
@@ -27,11 +27,24 @@ class osu_library
$root = str_ireplace("\\", "/", $root); // fuck windows backslash $root = str_ireplace("\\", "/", $root); // fuck windows backslash
$root = rtrim($root, "/"); // remove trailing slash(es) $root = rtrim($root, "/"); // remove trailing slash(es)
$this->set_root($root); // update db entry // giving a different library should always cause a full rescan
if ($this->get_root() !== $root)
$glob = glob($this->get_library_folder() . "/*", GLOB_ONLYDIR); {
$this->rescan_library($root);
}
$library = $this->get_library(); $library = $this->get_library();
$library_folder = $this->get_library_folder();
foreach ($library as $key => $entry)
{
if (!file_exists($library_folder . "/" . $key))
{
$this->unset_library_key($key);
};
}
$glob = glob($library_folder . "/*", GLOB_ONLYDIR);
natsort($glob); // i like wasting your processing power natsort($glob); // i like wasting your processing power
foreach($glob as $folder) foreach($glob as $folder)
{ {
@@ -54,6 +67,7 @@ class osu_library
public function rescan_library(string $root) : void public function rescan_library(string $root) : void
{ {
$this->clear_library(); $this->clear_library();
$this->set_root($root); // update db entry
$this->scan_library($root); $this->scan_library($root);
} }
@@ -88,7 +102,7 @@ class osu_library
if ($changed) if ($changed)
{ {
unset($this->db["library"][$key]); $this->unset_library_key($key);
$this->scan_add_folder($folder); $this->scan_add_folder($folder);
} }
} }
@@ -142,14 +156,22 @@ class osu_library
"difficulties" => $difficulties, "difficulties" => $difficulties,
); );
// if (!isset($this->db["library"])) $this->db["library"] = array(); $this->add_to_library($key, $entry);
}
public function add_to_library(string $key, array $entry) : void
{
// init empty // init empty
if (!isset($this->db["library"])) $this->db["library"] = array(); if (!isset($this->db["library"])) $this->db["library"] = array();
$this->db["library"][$key] = $entry; $this->db["library"][$key] = $entry;
} }
public function unset_library_key(string $key) : void
{
if (isset($this->db["library"][$key])) unset($this->db["library"][$key]);
}
public function get_root() : string public function get_root() : string
{ {
+4 -2
View File
@@ -86,8 +86,10 @@ foreach ($lib->get_library() as $set)
$proc_time += $map["parsing_time"] ?? 0; $proc_time += $map["parsing_time"] ?? 0;
} }
} }
echo "<h3>Parse time: " . $proc_time . " seconds</h3>"; $proc_time = round($proc_time, 3);
echo "<h3>Scan time: " . $lib->get_scan_time() . " seconds</h3>"; $scan_time = round($lib->get_scan_time(), 3);
echo "<h3>Total parse time: " . $proc_time . " seconds</h3>";
echo "<h3>Scan time: " . $scan_time . " seconds</h3>";
// foreach ($lib->get_library() as $mapset) // foreach ($lib->get_library() as $mapset)
// { // {
// echo '<div class="beatmapset">'; // echo '<div class="beatmapset">';
+60 -39
View File
@@ -1,10 +1,13 @@
<?php <?php
require "libraries/osu_library.php"; require "libraries/osu_library.php";
$format = "html";
if (!empty($_GET["format"])) $format = $_GET["format"];
$page = $_GET["page"]; $page = $_GET["page"];
$page = intval($page); $page = intval($page);
if ($page < 1) $page = 1; if ($page < 1) $page = 1;
$pagesize = 100; $pagesize = 10;
$lib = new osu_library(); $lib = new osu_library();
$library = $lib->get_library(); $library = $lib->get_library();
@@ -15,52 +18,70 @@ if ($page > $maxpage) $page = $maxpage;
$startindex = ($page - 1) * $pagesize; $startindex = ($page - 1) * $pagesize;
$start = file_get_contents("resources/start.html");
$start = str_replace("{{ STYLE }}", file_get_contents("resources/style.css"), $start);
echo $start;
$partial_library = array_slice($library, $startindex, $pagesize); $partial_library = array_slice($library, $startindex, $pagesize);
$previous = $page - 1;
if ($previous < 1) $previous = 1;
$next = $page + 1;
if ($next > $maxpage) $next = $maxpage;
echo '<h2>Page ' . $page . '/' . $maxpage . ' of osu! songs</h2>'; if ($format == "html")
echo '<a href="./splitter.php?page=' . $previous . '">[Previous]</a> ';
echo '<a href="./splitter.php?page=' . $next . '">[Next]</a> ';
echo "<pre>";
// print_r($partial_library);
// foreach ($partial_library as $key => $value)
// {
// $firstdiff = $value["difficulties"][array_key_first($value["difficulties"])];
// echo $firstdiff["artist"] . " - " . $firstdiff["title"] . " (" . count($value["difficulties"]) . " difficulties)\n";
// }
$proc_times = array();
foreach ($library as $key => $set)
{ {
$tiempo = 0; $previous = $page - 1;
foreach ($set["difficulties"] as $map) if ($previous < 1) $previous = 1;
{ $next = $page + 1;
$tiempo += $map["parsing_time"]; if ($next > $maxpage) $next = $maxpage;
}
$proc_times[$key] = $tiempo;
}
arsort($proc_times); $start = file_get_contents("resources/start.html");
$start = str_replace("{{ STYLE }}", file_get_contents("resources/style.css"), $start);
echo $start;
foreach ($proc_times as $key => $tiempo) echo '<h2>Page ' . $page . '/' . $maxpage . ' of osu! songs</h2>';
{ echo '<a href="./splitter.php?page=' . $previous . '">[Previous]</a> ';
$value = $library[$key]; echo '<a href="./splitter.php?page=' . $next . '">[Next]</a> ';
$firstdiff = $value["difficulties"][array_key_first($value["difficulties"])]; echo "<pre>";
$diffcount = 0; // print_r($partial_library);
foreach ($value["difficulties"] as $diff) foreach ($partial_library as $key => $value)
{ {
if ($diff["format"] != "storyboard") $firstdiff = $value["difficulties"][array_key_first($value["difficulties"])];
$diffcount = 0;
foreach ($value["difficulties"] as $diff)
{ {
$diffcount++; 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";
} }
echo str_pad(round($tiempo, 5), 7, "0") . "s " . $value["id"] . ": " . $firstdiff["Metadata"]["Artist"] . " - " . $firstdiff["Metadata"]["Title"] . " (" . $diffcount . " difficulties)\n"; // $proc_times = array();
// foreach ($library as $key => $set)
// {
// $tiempo = 0;
// foreach ($set["difficulties"] as $map)
// {
// $tiempo += $map["parsing_time"];
// }
// $proc_times[$key] = $tiempo;
// }
// arsort($proc_times);
// foreach ($proc_times as $key => $tiempo)
// {
// $value = $library[$key];
// $firstdiff = $value["difficulties"][array_key_first($value["difficulties"])];
// $diffcount = 0;
// foreach ($value["difficulties"] as $diff)
// {
// if ($diff["format"] != "storyboard")
// {
// $diffcount++;
// }
// }
// echo str_pad(round($tiempo, 5), 7, "0") . "s " . $value["id"] . ": " . $firstdiff["Metadata"]["Artist"] . " - " . $firstdiff["Metadata"]["Title"] . " (" . $diffcount . " difficulties)\n";
// }
}
else // default to json in every other case
{
header('Content-Type: application/json');
echo json_encode($partial_library);
} }
echo "</pre>";