From 044649c74547e6b9333d7e3b97710ed50343971a Mon Sep 17 00:00:00 2001 From: Diogo Peralta Cordeiro Date: Fri, 3 Dec 2021 03:13:28 +0000 Subject: [PATCH] [PLUGIN][VideoEncoder] Some videos don't have images (video stream), only audio, handle that --- .../audioEncoder/audioEncoderView.html.twig | 4 +++ plugins/StoreRemoteMedia/StoreRemoteMedia.php | 19 ++++------ plugins/VideoEncoder/VideoEncoder.php | 13 ++++--- .../videoEncoder/videoEncoderView.html.twig | 36 ++++++++++++------- 4 files changed, 42 insertions(+), 30 deletions(-) diff --git a/plugins/AudioEncoder/templates/audioEncoder/audioEncoderView.html.twig b/plugins/AudioEncoder/templates/audioEncoder/audioEncoderView.html.twig index 01596cfeb8..23c9e188aa 100644 --- a/plugins/AudioEncoder/templates/audioEncoder/audioEncoderView.html.twig +++ b/plugins/AudioEncoder/templates/audioEncoder/audioEncoderView.html.twig @@ -1,3 +1,4 @@ +{% if attachment.getFilename() is not null %}
+{% else %} + {# Not stored locally. #} +{% endif %} diff --git a/plugins/StoreRemoteMedia/StoreRemoteMedia.php b/plugins/StoreRemoteMedia/StoreRemoteMedia.php index e0aa7c926c..6e83204446 100644 --- a/plugins/StoreRemoteMedia/StoreRemoteMedia.php +++ b/plugins/StoreRemoteMedia/StoreRemoteMedia.php @@ -69,36 +69,31 @@ class StoreRemoteMedia extends Plugin '.*', // Default to allowing any host ]; public array $domain_blacklist = []; - // Whether to maintain a copy of the original media or only a thumbnail of it - public bool $store_original = false; - public ?int $thumbnail_width; - public ?int $thumbnail_height; - public ?int $max_size; - public ?bool $smart_crop; + // Whether to maintain a copy of the original media or only a thumbnail of it private function getStoreOriginal(): bool { - return $this->store_original ?? Common::config('plugin_store_remote_media', 'store_original'); + return Common::config('plugin_store_remote_media', 'store_original'); } private function getThumbnailWidth(): int { - return $this->thumbnail_width ?? Common::config('thumbnail', 'width'); + return Common::config('thumbnail', 'width'); } private function getThumbnailHeight(): int { - return $this->thumbnail_height ?? Common::config('thumbnail', 'height'); + return Common::config('thumbnail', 'height'); } - private function getMaxSize(): int + private function getMaxFileSize(): int { - return $this->max_size ?? Common::config('plugin_store_remote_media', 'max_file_size'); + return Common::config('plugin_store_remote_media', 'max_file_size'); } private function getSmartCrop(): bool { - return $this->smart_crop ?? Common::config('plugin_store_remote_media', 'smart_crop'); + return Common::config('plugin_store_remote_media', 'smart_crop'); } /** diff --git a/plugins/VideoEncoder/VideoEncoder.php b/plugins/VideoEncoder/VideoEncoder.php index 9cfa0ee0e0..cf0b3d0432 100644 --- a/plugins/VideoEncoder/VideoEncoder.php +++ b/plugins/VideoEncoder/VideoEncoder.php @@ -54,7 +54,8 @@ class VideoEncoder extends Plugin return '1.0.0'; } - public static function shouldHandle (string $mimetype): bool { + public static function shouldHandle(string $mimetype): bool + { return GSFile::mimetypeMajor($mimetype) === 'video' || $mimetype === 'image/gif'; } @@ -107,10 +108,12 @@ class VideoEncoder extends Plugin ]); $metadata = $ffprobe->streams($file->getRealPath()) // extracts streams informations - ->videos() // filters video streams - ->first(); // returns the first video stream - $width = $metadata->get('width'); - $height = $metadata->get('height'); + ->videos() // filters video streams + ->first(); // returns the first video stream + if (!\is_null($metadata)) { + $width = $metadata->get('width'); + $height = $metadata->get('height'); + } return true; } diff --git a/plugins/VideoEncoder/templates/videoEncoder/videoEncoderView.html.twig b/plugins/VideoEncoder/templates/videoEncoder/videoEncoderView.html.twig index 76f04c15ab..49f632cdb4 100644 --- a/plugins/VideoEncoder/templates/videoEncoder/videoEncoderView.html.twig +++ b/plugins/VideoEncoder/templates/videoEncoder/videoEncoderView.html.twig @@ -1,13 +1,23 @@ -
-
- -
- {% if attachment.getFilename() is not null %} - {{ attachment.getBestTitle(note) }} - {% else %} - {{ attachment.getBestTitle(note) }} - {% endif %} -
-
-
+{% if attachment.getFilename() is not null %} +
+
+ +
+ {{ attachment.getBestTitle(note) }} +
+
+
+{% else %} +{# Not stored locally. #} +{% endif %}