Spiele Filme in allen Playern über die gespeicherte Qualitätsleiter.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
8e77defaca
commit
1fb48783bf
14 files changed
+202
-18
No files matched your search
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Media;
|
||||
|
||||
class FilmPlayback
|
||||
{
|
||||
public function mode(int $versionId): string
|
||||
{
|
||||
return MediaRendition::masterPath($versionId) !== null ? 'hls' : 'file';
|
||||
}
|
||||
}
|
||||
@@ -344,12 +344,12 @@ public function pickerDetail(): ?array
|
||||
return null;
|
||||
}
|
||||
|
||||
$row['file_url'] = null;
|
||||
$row['playback'] = null;
|
||||
|
||||
if (preg_match('/^element:(\d+)$/', (string) $row['target'], $match) === 1) {
|
||||
$version = ContentElementVersion::query()->find($match[1]);
|
||||
$row['file_url'] = $version instanceof ContentElementVersion
|
||||
? app(ContentPreviewController::class)->fileUrl($version)
|
||||
$version = ContentElementVersion::query()->with('element')->find($match[1]);
|
||||
$row['playback'] = $version instanceof ContentElementVersion
|
||||
? app(ContentPreviewController::class)->playback($version)
|
||||
: null;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,11 @@
|
||||
|
||||
use App\Domain\Catalog\ContentElementVersion;
|
||||
use App\Domain\Identity\StaffRole;
|
||||
use App\Domain\Media\FilmPlayback;
|
||||
use App\Domain\Media\HlsPlaylist;
|
||||
use App\Domain\Media\MediaRendition;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\View\View;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
@@ -39,6 +43,55 @@ public function fileUrl(ContentElementVersion $version): ?string
|
||||
return $this->storedPath($version) === null ? null : route('content.file', $version);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{mode: string, url: string}|null
|
||||
*/
|
||||
public function playback(ContentElementVersion $version): ?array
|
||||
{
|
||||
$version->loadMissing('element');
|
||||
|
||||
if ($version->element?->output_class !== 'film') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$mode = app(FilmPlayback::class)->mode($version->id);
|
||||
$master = MediaRendition::masterPath($version->id);
|
||||
|
||||
if ($mode === 'hls' && is_string($master)) {
|
||||
return [
|
||||
'mode' => 'hls',
|
||||
'url' => route('content.rendition', ['version' => $version, 'datei' => $master]),
|
||||
];
|
||||
}
|
||||
|
||||
$file = $this->fileUrl($version);
|
||||
|
||||
return $file === null ? null : ['mode' => 'file', 'url' => $file];
|
||||
}
|
||||
|
||||
public function rendition(ContentElementVersion $version, string $datei): Response|StreamedResponse
|
||||
{
|
||||
$this->authorizeStaff();
|
||||
abort_unless($this->renditionBelongsTo($version->id, $datei), 404);
|
||||
$disk = Storage::disk('media_derived');
|
||||
abort_unless($disk->exists($datei), 404);
|
||||
|
||||
if (str_ends_with($datei, '.m3u8')) {
|
||||
$body = app(HlsPlaylist::class)->rewrite(
|
||||
$disk->get($datei),
|
||||
$datei,
|
||||
fn (string $target): string => route('content.rendition', ['version' => $version, 'datei' => $target]),
|
||||
);
|
||||
|
||||
return response($body, 200, [
|
||||
'Content-Type' => 'application/vnd.apple.mpegurl',
|
||||
'Cache-Control' => 'private, no-store',
|
||||
]);
|
||||
}
|
||||
|
||||
return $disk->response($datei, basename($datei), ['Content-Disposition' => 'inline']);
|
||||
}
|
||||
|
||||
public function isPending(ContentElementVersion $version): bool
|
||||
{
|
||||
if ($this->storedPath($version) !== null) {
|
||||
@@ -62,6 +115,13 @@ private function storedPath(ContentElementVersion $version): ?string
|
||||
return Storage::disk('media_derived')->exists($file) ? $file : null;
|
||||
}
|
||||
|
||||
private function renditionBelongsTo(int $versionId, string $path): bool
|
||||
{
|
||||
$prefix = 'ableitungen/'.$versionId;
|
||||
|
||||
return ($path === $prefix || str_starts_with($path, $prefix.'/')) && ! str_contains($path, '..');
|
||||
}
|
||||
|
||||
private function authorizeStaff(): void
|
||||
{
|
||||
$user = auth('staff')->user();
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
use App\Domain\Entitlement\Grant;
|
||||
use App\Domain\Entitlement\GrantStatus;
|
||||
use App\Domain\Media\DeliveryLog;
|
||||
use App\Domain\Media\FilmPlayback;
|
||||
use App\Domain\Media\HlsPlaylist;
|
||||
use App\Domain\Media\MediaRendition;
|
||||
use App\Http\Controllers\Controller;
|
||||
@@ -146,7 +147,7 @@ public function show(Request $request, LicenseArticle $article): View
|
||||
? (int) $metadata['decision_seconds']
|
||||
: null,
|
||||
'playable' => $decision->allowed && is_string($file) && $file !== '' && ($class === 'film' || $class === 'audio'),
|
||||
'playback' => MediaRendition::masterPath($version->id) !== null ? 'hls' : 'file',
|
||||
'playback' => app(FilmPlayback::class)->mode($version->id),
|
||||
'pillars' => $version->element->pillars->pluck('name')->all(),
|
||||
'url' => $decision->allowed
|
||||
? SignedLink::temporary('member.media', now()->addMinutes(10), [
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
use App\Domain\Entitlement\DecideAccess;
|
||||
use App\Domain\Entitlement\Grant;
|
||||
use App\Domain\Entitlement\GrantStatus;
|
||||
use App\Domain\Media\MediaRendition;
|
||||
use App\Domain\Media\FilmPlayback;
|
||||
use App\Domain\Media\ThumbnailRef;
|
||||
use App\Filament\Support\EditorialCatalog;
|
||||
use App\Models\User;
|
||||
@@ -138,7 +138,7 @@ private function present(User $user, StructureNode $node): array
|
||||
if ($node->contentElementVersionId !== null) {
|
||||
$view = $this->open($user, $node->contentElementVersionId, $this->viewAction($node->outputClass));
|
||||
$download = $this->open($user, $node->contentElementVersionId, 'laden');
|
||||
$playback = MediaRendition::masterPath($node->contentElementVersionId) !== null ? 'hls' : 'file';
|
||||
$playback = app(FilmPlayback::class)->mode($node->contentElementVersionId);
|
||||
if ($view !== null && $node->contentElementId !== null) {
|
||||
$path = ContentElement::query()->whereKey($node->contentElementId)->value('thumbnail_path');
|
||||
$poster = ThumbnailRef::url('member.thumbnail', 'element', $node->contentElementId, $path);
|
||||
|
||||
@@ -14,12 +14,14 @@
|
||||
use Filament\Panel;
|
||||
use Filament\PanelProvider;
|
||||
use Filament\Support\Colors\Color;
|
||||
use Filament\View\PanelsRenderHook;
|
||||
use Filament\Widgets\AccountWidget;
|
||||
use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse;
|
||||
use Illuminate\Cookie\Middleware\EncryptCookies;
|
||||
use Illuminate\Foundation\Http\Middleware\PreventRequestForgery;
|
||||
use Illuminate\Routing\Middleware\SubstituteBindings;
|
||||
use Illuminate\Session\Middleware\StartSession;
|
||||
use Illuminate\Support\Facades\Blade;
|
||||
use Illuminate\View\Middleware\ShareErrorsFromSession;
|
||||
|
||||
class AdminPanelProvider extends PanelProvider
|
||||
@@ -64,6 +66,10 @@ public function panel(Panel $panel): Panel
|
||||
])
|
||||
->authMiddleware([
|
||||
Authenticate::class,
|
||||
]);
|
||||
])
|
||||
->renderHook(
|
||||
PanelsRenderHook::BODY_END,
|
||||
fn (): string => app()->environment('testing') ? '' : Blade::render("@vite('resources/js/app.js')"),
|
||||
);
|
||||
}
|
||||
}
|
||||
+30
-2
@@ -1,12 +1,18 @@
|
||||
import Hls from 'hls.js';
|
||||
|
||||
document.querySelectorAll('video[data-hls]').forEach((video) => {
|
||||
function attachPlayback(video) {
|
||||
if (!(video instanceof HTMLVideoElement) || video.dataset.playbackReady === '1') {
|
||||
return;
|
||||
}
|
||||
|
||||
const source = video.dataset.hls;
|
||||
|
||||
if (!source) {
|
||||
return;
|
||||
}
|
||||
|
||||
video.dataset.playbackReady = '1';
|
||||
|
||||
if (Hls.isSupported()) {
|
||||
const playback = new Hls();
|
||||
playback.loadSource(source);
|
||||
@@ -18,7 +24,29 @@ document.querySelectorAll('video[data-hls]').forEach((video) => {
|
||||
if (video.canPlayType('application/vnd.apple.mpegurl')) {
|
||||
video.src = source;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function scanPlayback(root) {
|
||||
if (root instanceof HTMLVideoElement) {
|
||||
attachPlayback(root);
|
||||
}
|
||||
|
||||
if (root instanceof Element) {
|
||||
root.querySelectorAll('video[data-hls]').forEach(attachPlayback);
|
||||
}
|
||||
}
|
||||
|
||||
scanPlayback(document);
|
||||
|
||||
new MutationObserver((records) => {
|
||||
records.forEach((record) => {
|
||||
record.addedNodes.forEach((node) => {
|
||||
if (node instanceof Element) {
|
||||
scanPlayback(node);
|
||||
}
|
||||
});
|
||||
});
|
||||
}).observe(document.documentElement, { childList: true, subtree: true });
|
||||
|
||||
document.addEventListener('click', (event) => {
|
||||
const fullscreen = event.target.closest('[data-fullscreen]');
|
||||
|
||||
@@ -2,12 +2,16 @@
|
||||
$metadata = is_array($version->metadata) ? $version->metadata : [];
|
||||
$class = $version->element->output_class;
|
||||
$poster = \App\Domain\Media\ThumbnailRef::url('editorial.card', 'element', $version->element->id, $version->element->thumbnail_path);
|
||||
$playback = $class === 'film' ? app(\App\Http\Controllers\ContentPreviewController::class)->playback($version) : null;
|
||||
@endphp
|
||||
|
||||
@if ($fileUrl)
|
||||
@if ($class === 'film')
|
||||
<video controls preload="metadata" playsinline @if ($poster) poster="{{ $poster }}" @endif src="{{ $fileUrl }}" style="width: 100%; max-height: 70vh; background: #111;"></video>
|
||||
@elseif ($class === 'audio')
|
||||
@if ($class === 'film' && $playback)
|
||||
@include('content.video', ['playback' => $playback, 'poster' => $poster, 'style' => 'width: 100%; max-height: 70vh; background: #111;'])
|
||||
@if ($fileUrl)
|
||||
<p><a href="{{ $fileUrl }}">Datei öffnen</a></p>
|
||||
@endif
|
||||
@elseif ($fileUrl)
|
||||
@if ($class === 'audio')
|
||||
<audio controls preload="metadata" src="{{ $fileUrl }}" style="width: 100%;"></audio>
|
||||
@elseif ($class === 'bild')
|
||||
<img src="{{ $fileUrl }}" alt="{{ $version->element->working_title }}" style="max-width: 100%; height: auto;">
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
<video controls playsinline
|
||||
@if (($preload ?? 'metadata') !== '') preload="{{ $preload ?? 'metadata' }}" @endif
|
||||
@if (filled($poster ?? null)) poster="{{ $poster }}" @endif
|
||||
@if (filled($class ?? null)) class="{{ $class }}" @endif
|
||||
@if (filled($style ?? null)) style="{{ $style }}" @endif
|
||||
@if (($playback['mode'] ?? 'file') === 'hls') data-hls="{{ $playback['url'] }}" @else src="{{ $playback['url'] }}" @endif></video>
|
||||
@@ -470,8 +470,8 @@
|
||||
<p>{{ $detail['summary'] }}</p>
|
||||
@endif
|
||||
@if (($detail['tone'] ?? '') === 'film')
|
||||
@if (filled($detail['file_url'] ?? null))
|
||||
<video class="luf-video" controls preload="none" playsinline src="{{ $detail['file_url'] }}"></video>
|
||||
@if (filled($detail['playback']['url'] ?? null))
|
||||
@include('content.video', ['playback' => $detail['playback'], 'class' => 'luf-video', 'preload' => 'none'])
|
||||
@else
|
||||
<p class="luf-note">Für diese Fassung liegt noch keine abspielbare Datei vor. Ansehen öffnet die vorhandene Vorschau.</p>
|
||||
@endif
|
||||
|
||||
@@ -28,7 +28,10 @@
|
||||
@endif
|
||||
@if ($entry['playable'])
|
||||
<div class="player">
|
||||
<video controls preload="metadata" playsinline @if ($poster = \App\Domain\Media\ThumbnailRef::url('member.thumbnail', 'element', $entry['version']->element->id, $entry['version']->element->thumbnail_path)) poster="{{ $poster }}" @endif @if (($entry['playback'] ?? 'file') === 'hls') data-hls="{{ $entry['url'] }}" @else src="{{ $entry['url'] }}" @endif></video>
|
||||
@include('content.video', [
|
||||
'playback' => ['mode' => $entry['playback'] ?? 'file', 'url' => $entry['url']],
|
||||
'poster' => \App\Domain\Media\ThumbnailRef::url('member.thumbnail', 'element', $entry['version']->element->id, $entry['version']->element->thumbnail_path),
|
||||
])
|
||||
<button class="button button-quiet" type="button" data-fullscreen>Vollbild</button>
|
||||
</div>
|
||||
@elseif ($entry['allowed'] && $entry['url'])
|
||||
|
||||
@@ -20,7 +20,10 @@
|
||||
@if ($node['output_class'] === 'audio')
|
||||
<audio controls preload="metadata" src="{{ $node['view_url'] }}"></audio>
|
||||
@else
|
||||
<video controls preload="metadata" playsinline @if ($node['poster_url'] ?? null) poster="{{ $node['poster_url'] }}" @endif @if (($node['playback'] ?? 'file') === 'hls') data-hls="{{ $node['view_url'] }}" @else src="{{ $node['view_url'] }}" @endif></video>
|
||||
@include('content.video', [
|
||||
'playback' => ['mode' => $node['playback'] ?? 'file', 'url' => $node['view_url']],
|
||||
'poster' => $node['poster_url'] ?? null,
|
||||
])
|
||||
<button class="button button-quiet" type="button" data-fullscreen>Vollbild</button>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
@@ -56,6 +56,10 @@
|
||||
Route::get('/redaktion/inhalt/{version}/datei', [ContentPreviewController::class, 'file'])
|
||||
->middleware('auth:staff')
|
||||
->name('content.file');
|
||||
Route::get('/redaktion/inhalt/{version}/ableitung/{datei}', [ContentPreviewController::class, 'rendition'])
|
||||
->middleware('auth:staff')
|
||||
->where('datei', '.*')
|
||||
->name('content.rendition');
|
||||
|
||||
Route::middleware('auth')->group(function () {
|
||||
Route::get('/email/bestaetigen', [EmailVerificationController::class, 'notice'])->name('verification.notice');
|
||||
|
||||
@@ -412,4 +412,62 @@ public function test_an_uploaded_preview_and_an_image_file_stay_on_the_medium():
|
||||
$this->assertSame('datei', $picture->element->thumbnail_source);
|
||||
Storage::disk('media_derived')->assertExists($picture->element->thumbnail_path);
|
||||
}
|
||||
|
||||
public function test_staff_players_use_the_stored_film_ladder(): void
|
||||
{
|
||||
Storage::fake('media_derived');
|
||||
$content = app(ContentService::class);
|
||||
$version = $content->publishElementVersion(
|
||||
$content->createElement('film', 'film', 'Hofszene'),
|
||||
null,
|
||||
['file' => 'inhalte/hof.mp4'],
|
||||
);
|
||||
Storage::disk('media_derived')->put('inhalte/hof.mp4', 'filmbytes');
|
||||
$base = 'ableitungen/'.$version->id;
|
||||
Storage::disk('media_derived')->put($base.'/master.m3u8', "#EXTM3U\n#EXT-X-STREAM-INF:BANDWIDTH=800000\n480/index.m3u8\n");
|
||||
Storage::disk('media_derived')->put($base.'/480/index.m3u8', "#EXTM3U\n#EXTINF:6.0,\nsegment.m4s\n");
|
||||
Storage::disk('media_derived')->put($base.'/480/segment.m4s', 'segment-bytes');
|
||||
MediaRendition::query()->create([
|
||||
'content_element_version_id' => $version->id,
|
||||
'role' => 'master',
|
||||
'label' => 'master',
|
||||
'path' => $base.'/master.m3u8',
|
||||
]);
|
||||
$editor = User::factory()->redakteur()->create();
|
||||
$editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
|
||||
$playlist = route('content.rendition', ['version' => $version, 'datei' => $base.'/master.m3u8']);
|
||||
$variant = route('content.rendition', ['version' => $version, 'datei' => $base.'/480/index.m3u8']);
|
||||
|
||||
$this->get($playlist)->assertRedirect();
|
||||
|
||||
$this->actingAs($editor, 'staff')
|
||||
->get($playlist)
|
||||
->assertOk()
|
||||
->assertHeader('content-type', 'application/vnd.apple.mpegurl')
|
||||
->assertSee($variant, false);
|
||||
|
||||
$this->actingAs($editor, 'staff')
|
||||
->get(route('content.rendition', ['version' => $version, 'datei' => $base.'/480/segment.m4s']))
|
||||
->assertOk();
|
||||
|
||||
$this->actingAs($editor, 'staff')
|
||||
->get(route('content.rendition', ['version' => $version, 'datei' => 'ableitungen/99/master.m3u8']))
|
||||
->assertNotFound();
|
||||
|
||||
Livewire::actingAs($editor, 'staff')
|
||||
->test(ViewContentElement::class, ['record' => $version->element->getKey()])
|
||||
->assertSee('data-hls="'.$playlist.'"', false)
|
||||
->assertSee(route('content.file', $version), false);
|
||||
|
||||
$module = $content->publishComposition(
|
||||
$content->createComposition('Modul mit Hofszene', CompositionKind::Uebung),
|
||||
[['role' => 'Film', 'target' => $version]],
|
||||
);
|
||||
|
||||
Livewire::actingAs($editor, 'staff')
|
||||
->test(EditExercise::class, ['record' => $module->composition_id])
|
||||
->call('openPicker')
|
||||
->set('pickerSelected', 'element:'.$version->id)
|
||||
->assertSee('data-hls="'.$playlist.'"', false);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user