Skip to content

A self-hosted media server and file management system

exiftool for mp4 only and use encoder field since exiftool doesnt work for custom uuid tag

aminnausina91603f6e066
diff --git a/app/Jobs/EmbedUidInMetadata.php b/app/Jobs/EmbedUidInMetadata.php
index fea7fb8b..c08bc92f 100644
--- a/app/Jobs/EmbedUidInMetadata.php
+++ b/app/Jobs/EmbedUidInMetadata.php
@@ -145,17 +145,17 @@ class EmbedUidInMetadata implements ShouldQueue {
$formatMap = ['mp4' => 'mp4', 'mkv' => 'matroska', 'mp3' => 'mp3', 'ogg' => 'opus', 'flac' => 'flac'];
$format = $formatMap[$ext] ?? $ext;
- if ($ext !== 'mp3' && $ext !== 'flac') {
+ if ($ext === 'mp4') {
try {
$this->addMetadataWithExifTool();
-
return ' ExifTool';
} catch (\Exception $e) {
dump('ExifTool failed, falling back to ffmpeg: ' . $e->getMessage());
- $this->addMetadataWithFFMpeg($format, $tempFilePath);
}
}
+ $this->addMetadataWithFFMpeg($format, $tempFilePath);
+
if (file_exists($tempFilePath)) {
dump("Cleaning up temporary file: $tempFilePath");
unlink($tempFilePath); // delete the temp file
@@ -169,12 +169,12 @@ class EmbedUidInMetadata implements ShouldQueue {
$command = [
'exiftool',
- '-uuid=' . $this->uuid,
+ '-encoder=' . $this->uuid, //ExifTool sucks and can't write a custom tag into files like ffmpeg so I have to use encoder
+ '-preserve',
'-overwrite_original',
$this->filePath,
];
- // Execute the exiftool command
$process = new Process($command);
$process->setTimeout(3600);
$process->run();
@@ -183,6 +183,11 @@ class EmbedUidInMetadata implements ShouldQueue {
throw new \Exception('ExifTool failed: ' . $process->getErrorOutput());
}
+ // nothing to do
+ if (strpos($process->getOutput(), 'Nothing to do') !== false) {
+ throw new \Exception('ExifTool: Nothing to do, no changes made to the file.');
+ }
+
dump('ExifTool succeeded in adding uuid');
}
@@ -223,38 +228,4 @@ class EmbedUidInMetadata implements ShouldQueue {
throw new \Exception('Failed to create the temporary file with metadata.');
}
}
-
- private function getUidFromMetadata($filePath) {
- $ext = pathinfo($filePath, PATHINFO_EXTENSION);
-
- $command = [
- 'ffprobe',
- '-v',
- 'quiet',
- '-print_format',
- 'json',
- '-show_format',
- '-show_streams',
- $filePath,
- ];
-
- $process = new Process($command);
- $process->run();
-
- if (! $process->isSuccessful()) {
- throw new ProcessFailedException($process);
- }
-
- $output = $process->getOutput();
- $metadata = json_decode($output, true);
- if ($ext === 'ogg') {
- $metadata['format'] = $metadata['streams'][0] ?? [];
- }
- dump($metadata);
-
- // Tag was previously uid
- $uid = isset($metadata['format']['tags']['uid']) ? $metadata['format']['tags']['uid'] : (isset($metadata['format']['tags']['UID']) ? $metadata['format']['tags']['UID'] : null);
-
- return isset($metadata['format']['tags']['uuid']) ? $metadata['format']['tags']['uuid'] : $uid;
- }
}
diff --git a/app/Jobs/IndexFiles.php b/app/Jobs/IndexFiles.php
index a985d4b3..051bc377 100755
--- a/app/Jobs/IndexFiles.php
+++ b/app/Jobs/IndexFiles.php
@@ -600,4 +600,5 @@ class IndexFiles implements ShouldBeUnique, ShouldQueue {
}
}
}
-class BatchCancelledException extends \Exception {}
+class BatchCancelledException extends \Exception {
+}
diff --git a/app/Jobs/VerifyFiles.php b/app/Jobs/VerifyFiles.php
index af924aa7..5e789fb2 100755
--- a/app/Jobs/VerifyFiles.php
+++ b/app/Jobs/VerifyFiles.php
@@ -321,6 +321,8 @@ class VerifyFiles implements ShouldQueue {
$metadata['format'] = $metadata['streams'][0] ?? [];
}
+ if (!isset($metadata['format']['tags']['uuid']) && isset($metadata['format']['tags']['uid'])) $metadata['format']['tags']['uuid'] = $metadata['format']['tags']['uid']; // old uid tag
+ if (!isset($metadata['format']['tags']['uuid']) && isset($metadata['format']['tags']['encoder']) && uuid_is_valid($metadata['format']['tags']['encoder'])) $metadata['format']['tags']['uuid'] = $metadata['format']['tags']['encoder']; // ExifTool tag
return $metadata['format'];
} catch (\Throwable $th) {
dump($th);