function action_updateTagCache() { global $config; doPrint("starting tag cache update..."); print formatDateTime() . "\n"; $data = getData(); $data["lastTagUpdate"] = time(); storeData($data); $oldTags = array(); foreach (file($config["tagCache"]) as $tag) { $tag = trim($tag); $tagArray = explode(";-;", $tag); if (!isset($tagArray[0]) or count($tagArray) != 8) { doPrint("removed invalid entry in tagcache: " . count($tagArray)); doPrint($tagArray); } else { $oldTags[$tagArray[0]] = $tagArray; } } doPrint("got old tag cache"); $tagCache = array(); $files = getFilesForDirectory($config["searchPath"]); $new = 0; $old = 0; $updates = 0; $fp = fopen($config["tagCache"], "w+") or die("cannot open tagCache File for writing"); foreach ($files as $file) { #if(substr($file, -5) == '.flac') { # continue; #} $scan = 0; $newTime = filemtime($config["searchPath"] . "/" . $file); if (!isset($oldTags[$file])) { #doPrint("file is new: ".$file); $scan = 1; $new++; } elseif ($newTime != $oldTags[$file][7]) { #doPrint("file changed and needs update: ".$file); $scan = 1; $updates++; } else { #doPrint("file unchanged: ".$file); $old++; } if (!$scan and isset($oldTags[$file])) { $fileinfo = $oldTags[$file]; } else { $fileinfo = getTag($config["searchPath"] . "/" . $file); array_push($fileinfo, $newTime); array_unshift($fileinfo, $file); } fwrite($fp, join(";-;", $fileinfo) . "\n"); } $data = getData(); $data["lastTagUpdate"] = time(); storeData($data); fclose($fp); print "wrote tag cache\n"; print formatDateTime() . "\n"; doPrint("finished tag cache update..."); doPrint("new: " . $new); doPrint("update: " . $updates); doPrint("old: " . $old); }
function getFilesForDirectory($dir) { global $config; $files = array(); if ($handle = opendir($dir)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { if (is_link($dir . "/" . $file) and is_dir(readlink($dir . "/" . $file))) { # resolve links $files = array_merge($files, getFilesForDirectory($dir . "/" . $file)); } elseif (is_dir($dir . "/" . $file)) { $files = array_merge($files, getFilesForDirectory($dir . "/" . $file)); } else { $tmp = explode(".", $file); $ext = "." . array_pop($tmp); if (in_array($ext, array_keys($config["ext"]))) { $files[] = str_replace($config["searchPath"], "", $dir . "/" . $file); } } } } closedir($handle); } return $files; }