Skip to content

A self-hosted media server and file management system

fix: correct getting video duration when indexing

aminnausin20cc682df0bf
diff --git a/app/Jobs/IndexFiles.php b/app/Jobs/IndexFiles.php
index 16696555..03165b4b 100755
--- a/app/Jobs/IndexFiles.php
+++ b/app/Jobs/IndexFiles.php
@@ -501,8 +501,10 @@ class IndexFiles implements ShouldBeUnique, ShouldQueue {
$mtime = filemtime($rawFile);
$ctime = filectime($rawFile);
+ $duration = isset($fileMetaData['format']['duration']) ? floor($fileMetaData['format']['duration']) : (isset($fileMetaData['streams'][0]['duration']) ? floor($fileMetaData['streams'][0]['duration']) : null);
+
$generated = ['id' => $currentID, 'uuid' => $embeddingUuid ? null : $uuid, 'name' => $cleanName, 'path' => $key, 'folder_id' => $folderStructure[$folder]['id'], 'date' => date('Y-m-d h:i A', $mtime < $ctime ? $mtime : $ctime), 'action' => 'INSERT'];
- $metadata = ['video_id' => $currentID, 'composite_id' => "$folder/$name", 'uuid' => $uuid, 'file_size' => filesize($rawFile), 'duration' => isset($fileMetaData['duration']) ? (int) $fileMetaData['duration'] : null, 'mime_type' => $mime_type ?? null, 'date_scanned' => date('Y-m-d h:i:s A'), 'date_uploaded' => date('Y-m-d h:i A', $mtime < $ctime ? $mtime : $ctime)];
+ $metadata = ['video_id' => $currentID, 'composite_id' => "$folder/$name", 'uuid' => $uuid, 'file_size' => filesize($rawFile), 'duration' => $duration, 'mime_type' => $mime_type ?? null, 'date_scanned' => date('Y-m-d h:i:s A'), 'date_uploaded' => date('Y-m-d h:i A', $mtime < $ctime ? $mtime : $ctime)];
$current[$key] = $currentID; // add to current
array_push($changes, $generated); // add to new (insert)
array_push($metadataChanges, $metadata); // create metadata (insert)
@@ -609,4 +611,5 @@ class IndexFiles implements ShouldBeUnique, ShouldQueue {
return 'Generated ' . $count . ' ' . $type . ' Changes';
}
}
-class BatchCancelledException extends \Exception {}
+class BatchCancelledException extends \Exception {
+}