Update sorting logic to use full timestamp from filename
This commit is contained in:
parent
951e9c5f58
commit
0fd6d43adb
1 changed files with 5 additions and 15 deletions
20
new.php
20
new.php
|
|
@ -81,24 +81,14 @@ function media_sort_files($dir, $files){
|
|||
}
|
||||
function media_file_date($path){
|
||||
$ext = strtolower(pathinfo((string)$path, PATHINFO_EXTENSION));
|
||||
if (in_array($ext, ['jpg','jpeg','tif','tiff'], true) && function_exists('exif_read_data')) {
|
||||
if (in_array($ext, ["jpg","jpeg","tif","tiff"], true) && function_exists("exif_read_data")) {
|
||||
$exif = @exif_read_data($path);
|
||||
foreach (['DateTimeOriginal','DateTimeDigitized','DateTime'] as $k) {
|
||||
if (!empty($exif[$k]) && preg_match('/^(\d{4}):(\d{2}):(\d{2})/', (string)$exif[$k], $m)) return "$m[1]$m[2]$m[3]";
|
||||
foreach (["DateTimeOriginal","DateTimeDigitized","DateTime"] as $k) {
|
||||
if (!empty($exif[$k]) && preg_match("/^(\d{4}):(\d{2}):(\d{2})\s*(\d{2}):(\d{2}):(\d{2})/", (string)$exif[$k], $m)) return $m[1].$m[2].$m[3].$m[4].$m[5].$m[6];
|
||||
}
|
||||
}
|
||||
if (in_array($ext, ['mp4','mov','m4v','avi','mkv','webm'], true)) {
|
||||
$ffprobe = trim((string)shell_exec('command -v ffprobe 2>/dev/null'));
|
||||
if ($ffprobe !== '') {
|
||||
$json = shell_exec(escapeshellarg($ffprobe).' -v quiet -print_format json -show_entries format_tags=creation_time:stream_tags=creation_time '.escapeshellarg($path).' 2>/dev/null');
|
||||
$data = json_decode((string)$json, true);
|
||||
$candidates = [];
|
||||
if (is_array($data['format']['tags'] ?? null)) $candidates[] = $data['format']['tags']['creation_time'] ?? '';
|
||||
foreach (($data['streams'] ?? []) as $stream) if (is_array($stream['tags'] ?? null)) $candidates[] = $stream['tags']['creation_time'] ?? '';
|
||||
foreach ($candidates as $value) {
|
||||
if (preg_match('/^(\d{4})-(\d{2})-(\d{2})/', (string)$value, $m)) return "$m[1]$m[2]$m[3]";
|
||||
}
|
||||
}
|
||||
if (preg_match("/(\d{8})[_-]?(\d{6})?/", basename($path), $m)) {
|
||||
return $m[1] . ($m[2] ?? "000000");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue