[PLUGIN][VideoEncoder] Some videos don't have images (video stream), only audio, handle that

This commit is contained in:
Diogo Peralta Cordeiro 2021-12-03 03:13:28 +00:00
parent 4501b7e85e
commit 044649c745
No known key found for this signature in database
GPG Key ID: 18D2D35001FBFAB0
4 changed files with 42 additions and 30 deletions

View File

@ -1,3 +1,4 @@
{% if attachment.getFilename() is not null %}
<div>
<figure>
<audio class="u-audio" src="{{ attachment.getUrl() }}" controls>
@ -11,3 +12,6 @@
</figcaption>
</figure>
</div>
{% else %}
{# Not stored locally. #}
{% endif %}

View File

@ -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');
}
/**

View File

@ -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';
}
@ -109,8 +110,10 @@ class VideoEncoder extends Plugin
$metadata = $ffprobe->streams($file->getRealPath()) // extracts streams informations
->videos() // filters video streams
->first(); // returns the first video stream
if (!\is_null($metadata)) {
$width = $metadata->get('width');
$height = $metadata->get('height');
}
return true;
}

View File

@ -1,13 +1,23 @@
{% if attachment.getFilename() is not null %}
<div>
<figure>
<video class="u-video" src="{{ attachment.getUrl() }}" controls poster="{{ attachment.getThumbnailUrl('medium')}}">
<video
{% if attachment.getWidth() is not null %}
class="u-video"
{% else %}
class="u-audio"
{% endif %}
src="{{ attachment.getUrl() }}" controls
{% if attachment.getWidth() is not null %}
poster="{{ attachment.getThumbnailUrl('medium')}}"
{% endif %}
>
</video>
<figcaption>
{% if attachment.getFilename() is not null %}
<a href="{{ path('attachment_show', {'id': attachment.getId()}) }}">{{ attachment.getBestTitle(note) }}</a>
{% else %}
{{ attachment.getBestTitle(note) }}
{% endif %}
</figcaption>
</figure>
</div>
{% else %}
{# Not stored locally. #}
{% endif %}