Skip to content

Commit b8d3832

Browse files
committed
fix: get file metadata tag keys are not consistent case and require checking "uuid" and "UUID" between mp4 and mkv
1 parent 23860ed commit b8d3832

1 file changed

Lines changed: 23 additions & 12 deletions

File tree

app/Jobs/VerifyFiles.php

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,9 @@ public static function getFileMetadata($filePath) {
358358
// ? FFMPEG module with 6 test folders takes 35+ seconds but running the commands through shell takes 18 seconds
359359

360360
$ext = pathinfo($filePath, PATHINFO_EXTENSION);
361-
dump('PULLING METADATA ' . $filePath);
361+
if (config('app.env') === 'local') {
362+
dump('PULLING METADATA ' . $filePath);
363+
}
362364
$command = [
363365
'ffprobe',
364366
'-v',
@@ -380,25 +382,34 @@ public static function getFileMetadata($filePath) {
380382

381383
$output = $process->getOutput();
382384
$metadata = json_decode($output, true);
385+
386+
if (! is_array($metadata)) {
387+
throw new \RuntimeException('Invalid ffprobe JSON output');
388+
}
389+
383390
if ($ext === 'ogg') {
384391
$metadata['format'] = $metadata['streams'][0] ?? [];
385392
}
386393

387-
if (! isset($metadata['format']['tags']['uuid']) && isset($metadata['format']['tags']['uid'])) {
388-
$metadata['format']['tags']['uuid'] = $metadata['format']['tags']['uid'];
389-
} // old uid tag
390-
if (! isset($metadata['format']['tags']['uuid']) && isset($metadata['format']['tags']['encoder']) && uuid_is_valid($metadata['format']['tags']['encoder'])) {
391-
$metadata['format']['tags']['uuid'] = $metadata['format']['tags']['encoder'];
392-
} // ExifTool tag
394+
$format = $metadata['format'] ?? [];
395+
$tags = array_change_key_case($format['tags'] ?? [], CASE_LOWER);
396+
$streams = $metadata['streams'] ?? [];
397+
398+
if (! isset($tags['uuid']) && isset($tags['uid'])) {
399+
$tags['uuid'] = $tags['uid']; // Old uid tag, does not apply to any versions from 2025 and up
400+
}
401+
402+
if (! isset($tags['uuid']) && isset($tags['encoder']) && uuid_is_valid($tags['encoder'])) {
403+
$tags['uuid'] = $tags['encoder']; // ExifTool tag
404+
}
393405

394406
return [
395-
'format' => $metadata['format'] ?? [],
396-
'tags' => $metadata['format']['tags'] ?? [],
397-
'streams' => $metadata['streams'] ?? [],
407+
'format' => $format,
408+
'tags' => $tags,
409+
'streams' => $streams,
398410
];
399411
} catch (\Throwable $th) {
400-
dump($th);
401-
Log::error('Unable to get file metadata', ['error' => $th->getMessage()]);
412+
Log::error('Unable to get file metadata', ['path' => $filePath, 'error' => $th->getMessage(), 'trace' => $th->getTraceAsString()]);
402413

403414
return ['format' => [], 'tags' => [], 'streams' => []];
404415
}

0 commit comments

Comments
 (0)