From 92290786b22da16f6bb3f3b6e279fa2b392879a7 Mon Sep 17 00:00:00 2001 From: hbrain Date: Mon, 25 May 2026 18:46:14 +0200 Subject: [PATCH] Cache video metadata by mtime --- .gitignore | 1 + index.php | 30 +++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 4a7573d..7ed67fe 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ in-dir/ out-dir/ thumbs/ *.log +cache/ diff --git a/index.php b/index.php index 423e91d..d8d5c44 100644 --- a/index.php +++ b/index.php @@ -1,6 +1,7 @@ $mtime, 'size' => $size, 'metadata' => video_metadata($path)]; + $changed = true; + } + $newItems[$key] = $cached; + } + + if (array_diff(array_keys($items), array_keys($newItems))) $changed = true; + if ($changed) { + file_put_contents($cacheFile, json_encode(['generated_at' => date('c'), 'items' => $newItems], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT), LOCK_EX); + } + return $newItems; +} $videos = glob($config['videos_dir'].'/*.{mp4,webm,mov,m4v}', GLOB_BRACE) ?: []; usort($videos, fn($a,$b)=>filemtime($b)<=>filemtime($a)); +$videoCache = load_video_cache($videos); $page=max(1,(int)($_GET['page']??1)); $per=$config['items_per_page']; $total=count($videos); $pages=max(1,(int)ceil($total/$per)); $page=min($page,$pages); $slice=array_slice($videos,($page-1)*$per,$per); ?> MVLog

MVLog

No videos yet.

- +

MB