From 9e56582a02da19ae1e5f375c3ed773e6a42afe8b Mon Sep 17 00:00:00 2001 From: hbrain Date: Mon, 25 May 2026 21:29:49 +0200 Subject: [PATCH] Add orphan video deletion admin section --- new.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/new.php b/new.php index 04da8e8..0126d39 100644 --- a/new.php +++ b/new.php @@ -45,6 +45,16 @@ function write_data($dir, $post){ file_put_contents($dir . '/data.txt', implode("\n", $lines) . "\n"); } function list_files($dir){ $files = array_values(array_filter(scandir($dir), fn($f)=>$f!=='.' && $f!=='..' && is_file($dir.'/'.$f) && $f !== 'data.txt')); natcasesort($files); return $files; } +function orphan_videos($config){ + $referenced = []; + foreach (input_dirs($config['uploads_dir']) as $dir) { + $stateFile = $dir . '/.movmaker-state.json'; + $state = is_file($stateFile) ? json_decode((string)file_get_contents($stateFile), true) : []; + if (is_array($state) && !empty($state['output'])) $referenced[basename((string)$state['output'])] = true; + } + $videos = glob($config['videos_dir'].'/*.{mp4,webm,mov,m4v}', GLOB_BRACE) ?: []; + return array_values(array_filter($videos, fn($v)=>empty($referenced[basename($v)]))); +} function save_uploads($field, $dest, $allowed){ if (empty($_FILES[$field])) return []; $files = $_FILES[$field]; $saved = []; @@ -93,6 +103,14 @@ try { unlink($dir.'/'.$file); $msg = 'Removed file: ' . $file; $_GET['edit'] = basename($dir); + } elseif ($action === 'delete_video') { + $file = basename((string)($_POST['video'] ?? '')); + $path = $config['videos_dir'] . '/' . $file; + if ($file === '' || !is_file($path)) throw new RuntimeException('Invalid video.'); + unlink($path); + $cache = __DIR__ . '/cache/videos.json'; + if (is_file($cache)) unlink($cache); + $msg = 'Deleted video: ' . $file; } elseif ($action === 'delete_dir') { $dir = safe_input_dir($config['uploads_dir'], $_POST['dir'] ?? ''); $name = basename($dir); @@ -112,6 +130,7 @@ try { } } catch (Throwable $e) { $err = $e->getMessage(); } $dirs = input_dirs($config['uploads_dir']); +$orphanVideos = orphan_videos($config); $editName = $_GET['edit'] ?? ''; $editDir = null; $editData = ['title'=>'','date'=>'','place'=>'','description'=>'','captions'=>[]]; $editFiles = []; if ($editName !== '') { try { $editDir = safe_input_dir($config['uploads_dir'], $editName); $editData = read_data($editDir); $editFiles = list_files($editDir); } catch (Throwable $e) { $err = $e->getMessage(); } } @@ -119,6 +138,8 @@ if ($editName !== '') { try { $editDir = safe_input_dir($config['uploads_dir'], Admin - <?=h($config['site_name'])?>

MVLog Admin

+ +

Videos without input dir

No orphan videos.


MB

Existing input dirs

No input directories yet.


ยท files
Edit

Edit input dir

in-dir/

Files and captions

No caption for audio files

Add new movie input