diff --git a/libraries/osu_library.php b/libraries/osu_library.php index 01b7f72..c5918e7 100644 --- a/libraries/osu_library.php +++ b/libraries/osu_library.php @@ -29,13 +29,21 @@ class osu_library $this->set_root($root); // update db entry - $this->clear_library(); $glob = glob($this->get_library_folder() . "/*", GLOB_ONLYDIR); + $library = $this->get_library(); natsort($glob); // i like wasting your processing power foreach($glob as $folder) { - $this->scan_add_folder($folder); + $key = basename($folder); + if (isset($library[$key])) + { + $this->scan_check_folder($folder); + } + else + { + $this->scan_add_folder($folder); + } } $time_end = microtime(true); @@ -54,6 +62,37 @@ class osu_library unset($this->db["library"]); } + private function scan_check_folder(string $folder) : void + { + $key = basename($folder); + + $osu_glob = glob(utils::globsafe($folder) . "/*.osu"); + $osb_glob = glob(utils::globsafe($folder) . "/*.osb"); + $glob = array_merge($osu_glob, $osb_glob); + + $cacher = new osu_cacher($this->get_library_folder(), self::$cache_root); + + $changed = false; + if (count($osu_glob) < 1) + { + $changed = true; + } + + foreach ($glob as $file) + { + if ($cacher->get_cache($file) === false) + { + $changed = true; + } + } + + if ($changed) + { + unset($this->db["library"][$key]); + $this->scan_add_folder($folder); + } + } + private function scan_add_folder(string $folder) : void { $key = basename($folder); diff --git a/libraries/osu_parser.php b/libraries/osu_parser.php index 2641a3b..16e86b3 100644 --- a/libraries/osu_parser.php +++ b/libraries/osu_parser.php @@ -152,7 +152,7 @@ class osu_parser unset($file); // remove the memory leak // storyboards are overloaded with dupes (renumber to make json export to arrays) - $parsed["storyboard"] = array_values(array_unique($parsed["storyboard"])); + if (!empty($parsed["storyboard"])) $parsed["storyboard"] = array_values(array_unique($parsed["storyboard"])); $time_end = microtime(true); $parsing_time = $time_end - $time_start; diff --git a/main.php b/main.php index 8dd3581..f6ac867 100644 --- a/main.php +++ b/main.php @@ -27,6 +27,13 @@ function redirect($path) } if (isset($_GET["rescan"])) +{ + $lib->rescan_library(json_decode(file_get_contents("session/settings.json"), true)["osu_folder"]); + $lib->save_db(); + redirect("./"); +} + +if (isset($_GET["scan"])) { $lib->scan_library(json_decode(file_get_contents("session/settings.json"), true)["osu_folder"]); $lib->save_db(); @@ -61,7 +68,8 @@ $start = file_get_contents("resources/start.html"); $start = str_replace("{{ STYLE }}", file_get_contents("resources/style.css"), $start); echo $start; dump($lib, "lib"); -echo '[Rescan] '; +echo '[Scan] '; +echo '[Force rescan] '; echo '[Blacken] '; echo '[NoSB] '; echo '[Novid] ';