Use state file only for orphan videos
This commit is contained in:
parent
b0020c75b3
commit
770b8aa964
1 changed files with 1 additions and 18 deletions
19
new.php
19
new.php
|
|
@ -45,32 +45,15 @@ function write_data($dir, $post){
|
||||||
file_put_contents($dir . '/data.txt', implode("\n", $lines) . "\n");
|
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 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 video_title($path){
|
|
||||||
$ffprobe = trim((string)shell_exec('command -v ffprobe 2>/dev/null'));
|
|
||||||
if ($ffprobe === '') return '';
|
|
||||||
$json = shell_exec(escapeshellarg($ffprobe).' -v quiet -print_format json -show_entries format_tags=title '.escapeshellarg($path).' 2>/dev/null');
|
|
||||||
$data = json_decode((string)$json, true);
|
|
||||||
$tags = $data['format']['tags'] ?? [];
|
|
||||||
foreach ($tags as $k => $v) if (strtolower($k) === 'title') return trim((string)$v);
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
function orphan_videos($config){
|
function orphan_videos($config){
|
||||||
$referenced = [];
|
$referenced = [];
|
||||||
$sourceTitles = [];
|
|
||||||
foreach (input_dirs($config['uploads_dir']) as $dir) {
|
foreach (input_dirs($config['uploads_dir']) as $dir) {
|
||||||
$stateFile = $dir . '/.movmaker-state.json';
|
$stateFile = $dir . '/.movmaker-state.json';
|
||||||
$state = is_file($stateFile) ? json_decode((string)file_get_contents($stateFile), true) : [];
|
$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;
|
if (is_array($state) && !empty($state['output'])) $referenced[basename((string)$state['output'])] = true;
|
||||||
$data = read_data($dir);
|
|
||||||
if (!empty($data['title'])) $sourceTitles[strtolower($data['title'])] = true;
|
|
||||||
}
|
}
|
||||||
$videos = glob($config['videos_dir'].'/*.{mp4,webm,mov,m4v}', GLOB_BRACE) ?: [];
|
$videos = glob($config['videos_dir'].'/*.{mp4,webm,mov,m4v}', GLOB_BRACE) ?: [];
|
||||||
return array_values(array_filter($videos, function($v) use ($referenced, $sourceTitles) {
|
return array_values(array_filter($videos, fn($v)=>empty($referenced[basename($v)])));
|
||||||
if (!empty($referenced[basename($v)])) return false;
|
|
||||||
$title = video_title($v);
|
|
||||||
if ($title !== '' && !empty($sourceTitles[strtolower($title)])) return false;
|
|
||||||
return true;
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
function save_uploads($field, $dest, $allowed){
|
function save_uploads($field, $dest, $allowed){
|
||||||
if (empty($_FILES[$field])) return [];
|
if (empty($_FILES[$field])) return [];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue