From 660d3741fb9bb3acb7964d88102aed42beb3880a Mon Sep 17 00:00:00 2001 From: Thayol Date: Sat, 26 Dec 2020 13:42:17 +0100 Subject: [PATCH] Removed hardcoded osu! folder path --- index.php | 17 ++++++++++++++++ libraries/osu_library.php | 41 ++++++++++++++++++++++++++++++++++----- main.php | 14 +++++++++---- splitter.php | 4 ++-- 4 files changed, 65 insertions(+), 11 deletions(-) diff --git a/index.php b/index.php index 6e9740d..bfd6e07 100644 --- a/index.php +++ b/index.php @@ -1,3 +1,20 @@ load_db($db_file); } + public function get_scan_time() : float + { + return floatval($this->db["scanning_time"] ?? 0); + } + public function scan_library(string $root) : void { + $time_start = microtime(true); // measure scanning time $root = str_ireplace("\\", "/", $root); // fuck windows backslash $root = rtrim($root, "/"); // remove trailing slash(es) @@ -31,6 +37,10 @@ class osu_library { $this->scan_add_folder($folder); } + + $time_end = microtime(true); + $scanning_time = $time_end - $time_start; + $this->db["scanning_time"] = $scanning_time; } public function rescan_library(string $root) : void @@ -60,15 +70,31 @@ class osu_library foreach ($glob as $file) { + $difficulty_key = basename($file); $difficulty = $parser->parse_osu_file_format($file); - $difficulty["key"] = basename($file); + $difficulty["key"] = $difficulty_key; $difficulty["path"] = $file; - $difficulties[basename($file)] = $difficulty; + $difficulties[$difficulty_key] = $difficulty; } - $temp = explode(" ", basename($folder))[0]; - $set_id = is_numeric($temp) ? $temp : ""; + // look for a beatmapset id + $set_id = false; + foreach ($difficulties as $difficulty) + { + if (!empty($difficulty[0]["Metadata"]["BeatmapSetID"])) + { + $id = intval($difficulty[0]["Metadata"]["BeatmapSetID"]); + } + } + + if ($set_id === false) + { + $temp = explode(" ", basename($folder))[0]; + $set_id = is_numeric($temp) ? $temp : ""; + } + + if ($set_id < 1) $set_id = false; // some are 0, some are -1, allowing positive only $entry = array( "key" => $key, @@ -148,7 +174,12 @@ class osu_library public function get_full_library() : array { - return $this->db["library"]; + return $this->db["library"] ?? array(); + } + + public function is_loaded() : bool + { + return !empty($this->get_full_library()); // not empty == loaded } public function get_folders() : array diff --git a/main.php b/main.php index 20b4ed0..f79559f 100644 --- a/main.php +++ b/main.php @@ -1,9 +1,9 @@ is_loaded()) +{ + $display = "main"; +} function redirect($path) { @@ -21,7 +26,7 @@ function redirect($path) if (isset($_GET["rescan"])) { - $lib->scan_library($root); + $lib->scan_library(json_decode(file_get_contents("session/settings.json"), true)["osu_folder"]); $lib->save_db(); redirect("./"); } @@ -72,6 +77,7 @@ foreach ($lib->get_library() as $set) } } echo "

Parse time: " . $proc_time . " seconds

"; +echo "

Scan time: " . $lib->get_scan_time() . " seconds

"; // foreach ($lib->get_library() as $mapset) // { // echo '
'; diff --git a/splitter.php b/splitter.php index 8203d8e..3d7720c 100644 --- a/splitter.php +++ b/splitter.php @@ -42,7 +42,7 @@ foreach ($library as $key => $set) $tiempo = 0; foreach ($set["difficulties"] as $map) { - $tiempo += $map["process_time"]; + $tiempo += $map["parse_time"]; } $proc_times[$key] = $tiempo; } @@ -53,6 +53,6 @@ foreach ($proc_times as $key => $tiempo) { $value = $library[$key]; $firstdiff = $value["difficulties"][array_key_first($value["difficulties"])]; - echo str_pad(round($tiempo, 5), 7, "0") . "s " . $value["id"] . ": " . $firstdiff["artist"] . " - " . $firstdiff["title"] . " (" . count($value["difficulties"]) . " difficulties)\n"; + echo str_pad(round($tiempo, 5), 7, "0") . "s " . $value["id"] . ": " . $firstdiff["Metadata"]["Artist"] . " - " . $firstdiff["Metadata"]["Title"] . " (" . count($value["difficulties"]) . " difficulties)\n"; } echo ""; \ No newline at end of file