53 lines
1.4 KiB
PHP
53 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
use App\Domain\Catalog\ContentElementVersion;
|
|
use App\Domain\Media\FilmTranscoder;
|
|
use App\Domain\Media\MediaRendition;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Queue\Queueable;
|
|
use Throwable;
|
|
|
|
class DeriveFilmRenditions implements ShouldQueue
|
|
{
|
|
use Queueable;
|
|
|
|
public int $timeout = 3600;
|
|
|
|
public function __construct(public readonly int $versionId) {}
|
|
|
|
public function handle(FilmTranscoder $transcoder): void
|
|
{
|
|
$version = ContentElementVersion::query()->with('element')->find($this->versionId);
|
|
$file = is_array($version?->metadata) ? ($version->metadata['file'] ?? null) : null;
|
|
|
|
if ($version === null || $version->element->output_class !== 'film' || ! is_string($file) || $file === '') {
|
|
return;
|
|
}
|
|
|
|
if (! $transcoder->available()) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
$rows = $transcoder->derive($version->id, $file);
|
|
} catch (Throwable) {
|
|
return;
|
|
}
|
|
|
|
foreach ($rows as $row) {
|
|
MediaRendition::query()->updateOrCreate(
|
|
[
|
|
'content_element_version_id' => $version->id,
|
|
'label' => $row['label'],
|
|
],
|
|
[
|
|
'role' => $row['role'],
|
|
'path' => $row['path'],
|
|
],
|
|
);
|
|
}
|
|
}
|
|
}
|