Removed hardcoded osu! folder path

This commit is contained in:
2020-12-26 13:42:17 +01:00
parent 012165cdfc
commit 660d3741fb
4 changed files with 65 additions and 11 deletions
+17
View File
@@ -1,3 +1,20 @@
<?php <?php
// imagine Bob. Bob has a slow computer
// but he likes osu! very much. his HDD
// is nearly failing, but the script will
// optimize his experience eventually.
// trust me, 83 hours is still not enough
// for the likes of Bob.
set_time_limit(298800);
// around 13 000 maps, the new parser
// exhausted the default 512MB limit,
// this might need to be adjusted in
// the future
ini_set('memory_limit', '1024M');
// git does not like empty folders
if (!file_exists("session")) mkdir("session"); if (!file_exists("session")) mkdir("session");
// the entry point
require "main.php"; require "main.php";
+36 -5
View File
@@ -16,8 +16,14 @@ class osu_library
$this->load_db($db_file); $this->load_db($db_file);
} }
public function get_scan_time() : float
{
return floatval($this->db["scanning_time"] ?? 0);
}
public function scan_library(string $root) : void public function scan_library(string $root) : void
{ {
$time_start = microtime(true); // measure scanning time
$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)
@@ -31,6 +37,10 @@ class osu_library
{ {
$this->scan_add_folder($folder); $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 public function rescan_library(string $root) : void
@@ -60,15 +70,31 @@ class osu_library
foreach ($glob as $file) foreach ($glob as $file)
{ {
$difficulty_key = basename($file);
$difficulty = $parser->parse_osu_file_format($file); $difficulty = $parser->parse_osu_file_format($file);
$difficulty["key"] = basename($file); $difficulty["key"] = $difficulty_key;
$difficulty["path"] = $file; $difficulty["path"] = $file;
$difficulties[basename($file)] = $difficulty; $difficulties[$difficulty_key] = $difficulty;
} }
$temp = explode(" ", basename($folder))[0]; // look for a beatmapset id
$set_id = is_numeric($temp) ? $temp : ""; $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( $entry = array(
"key" => $key, "key" => $key,
@@ -148,7 +174,12 @@ class osu_library
public function get_full_library() : array 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 public function get_folders() : array
+10 -4
View File
@@ -1,9 +1,9 @@
<?php <?php
// todo: whitelist / blacklist // todo: whitelist / blacklist
// todo: repack osz file // todo: repack osz file
set_time_limit(300000);
ini_set('memory_limit', '1024M');
// imports
require_once "libraries/osu_library.php"; require_once "libraries/osu_library.php";
require_once "libraries/optimizer.php"; require_once "libraries/optimizer.php";
require_once "libraries/utils.php"; require_once "libraries/utils.php";
@@ -11,7 +11,12 @@ require_once "temp/dump.php";
$lib = new osu_library(); $lib = new osu_library();
$root = "S:/test"; $display = "start";
if ($lib->is_loaded())
{
$display = "main";
}
function redirect($path) function redirect($path)
{ {
@@ -21,7 +26,7 @@ function redirect($path)
if (isset($_GET["rescan"])) 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(); $lib->save_db();
redirect("./"); redirect("./");
} }
@@ -72,6 +77,7 @@ foreach ($lib->get_library() as $set)
} }
} }
echo "<h3>Parse time: " . $proc_time . " seconds</h3>"; echo "<h3>Parse time: " . $proc_time . " seconds</h3>";
echo "<h3>Scan time: " . $lib->get_scan_time() . " seconds</h3>";
// foreach ($lib->get_library() as $mapset) // foreach ($lib->get_library() as $mapset)
// { // {
// echo '<div class="beatmapset">'; // echo '<div class="beatmapset">';
+2 -2
View File
@@ -42,7 +42,7 @@ foreach ($library as $key => $set)
$tiempo = 0; $tiempo = 0;
foreach ($set["difficulties"] as $map) foreach ($set["difficulties"] as $map)
{ {
$tiempo += $map["process_time"]; $tiempo += $map["parse_time"];
} }
$proc_times[$key] = $tiempo; $proc_times[$key] = $tiempo;
} }
@@ -53,6 +53,6 @@ foreach ($proc_times as $key => $tiempo)
{ {
$value = $library[$key]; $value = $library[$key];
$firstdiff = $value["difficulties"][array_key_first($value["difficulties"])]; $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 "</pre>"; echo "</pre>";