Skip to content

Commit

Permalink
Merge pull request rrze-mmz#37 from rrze-mmz/36-enhance-clip-page-by-…
Browse files Browse the repository at this point in the history
…enabling-users-to-load-a-wider-variety-of-video-formats

Add options to load different videos in plyr
  • Loading branch information
stefanosgeo authored Jan 18, 2024
2 parents 6e51d5b + 015f80d commit 67222a9
Show file tree
Hide file tree
Showing 23 changed files with 657 additions and 490 deletions.
4 changes: 2 additions & 2 deletions app/Http/Controllers/Backend/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ public function __invoke(OpencastService $opencastService): Application|Factory|
'userSeries' => auth()->user()->getAllSeries()
->CurrentSemester()
->withLastPublicClip()
->orderByDesc('updated_at')
->simplePaginate(12),
->orderBy('title')
->simplePaginate(100),
'userClips' => auth()->user()->clips()
->whereNull('series_id')
->orderByDesc('updated_at')
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Frontend/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __invoke(): View
->public()
->whereHas('assets')
->single()
->orderByDesc('updated_at')
->orderByDesc('recording_date')
->limit(12)
->get(),
]);
Expand Down
24 changes: 24 additions & 0 deletions app/Http/Controllers/Frontend/ShowClipsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Http\Controllers\Controller;
use App\Models\Clip;
use App\Services\WowzaService;
use Debugbar;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\View\View;

Expand Down Expand Up @@ -45,9 +46,32 @@ public function show(Clip $clip, WowzaService $wowzaService): View
return $value !== 'PDF/CC';
});

$wowzaStatus = $wowzaService->getHealth();
$urls = collect([]);
$defaultPlayerUrl = '';
if ($wowzaStatus) {
$urls = $wowzaService->vodSecureUrls($clip);

if (empty($urls)) {
$defaultPlayerUrl = [];
} elseif ($urls->has('composite')) {
$defaultPlayerUrl = $urls['composite'];
} elseif ($urls->has('presenter')) {
$defaultPlayerUrl = $urls['presenter'];
} elseif ($urls->has('presentation')) {
$defaultPlayerUrl = $urls['presentation'];
} else {
$defaultPlayerUrl = [];
}
}

Debugbar::info($defaultPlayerUrl);

return view('frontend.clips.show', [
'clip' => $clip,
'wowzaStatus' => $wowzaService->getHealth(),
'defaultVideoUrl' => $defaultPlayerUrl,
'alternativeVideoUrls' => $urls,
'previousNextClipCollection' => $clip->previousNextClipCollection(),
'assetsResolutions' => $assetsResolutions,
]);
Expand Down
1 change: 1 addition & 0 deletions app/Policies/ClipPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function view(?User $user, Clip $clip): bool
} elseif ($clip->is_public &&
(is_null($clip->series->is_public) || $clip->series->is_public)
&& $clip->assets()->count() > 0) {

return true;
} else {
return false;
Expand Down
2 changes: 1 addition & 1 deletion app/Services/OpenSearchService.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public function searchIndexes(
}

$isPhrase = Str::contains($searchTerm, ' ');
Debugbar::info($isPhrase);

$query = ($isPhrase) ?
[
// 'multi_match' => [
Expand Down
54 changes: 35 additions & 19 deletions app/Services/WowzaService.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,27 +193,43 @@ public function findWowzaAssetBitrate($videoPixelHeight): int
/**
* Generates a wowza streaming link with secure token settings
*/
public function vodSecureUrl(Clip $clip): bool|string
public function vodSecureUrls(Clip $clip): Collection
{
$filePaths = collect();
if ($clip->assets->count() > 0) {
$contentUrl = getClipSmilFile($clip, config('wowza.check_fautv_links'));

$contentPath = (config('wowza.check_fautv_links'))
? $this->streamingSettings->data['content_path'].getClipStoragePath($clip).'camera.smil'
: $this->streamingSettings->data['content_path'].getClipStoragePath($clip).'presenter.smil';
$secureToken = $this->streamingSettings->data['secure_token'];
$tokenPrefix = $this->streamingSettings->data['token_prefix'];
$tokenStartTime = $tokenPrefix.'starttime='.time();
$tokenEndTime = $tokenPrefix.'endTime='.(time() + 21600);

$userIP = (App::environment(['testing', 'local'])) ? env('FAUTV_USER_IP') : $_SERVER['REMOTE_ADDR'];
$hashStr = "{$contentPath}?{$userIP}&{$secureToken}&{$tokenEndTime}&{$tokenStartTime}";
$hash = hash('sha256', $hashStr, 1);
$usableHash = strtr(base64_encode($hash), '+/', '-_');

return "{$contentUrl}?{$tokenStartTime}&{$tokenEndTime}&{$tokenPrefix}hash={$usableHash}";
} else {
return false;
$clip->getAssetsByType(Content::SMIL)->each(function ($asset) use ($filePaths) {
$fileType = Str::before($asset->original_file_name, '.smil');
if (config('wowza.check_fautv_links')) {
if (Str::contains($asset->original_file_name, 'composite')) {
$asset->original_file_name = 'combined.smil';
} elseif (Str::contains($asset->original_file_name, 'presenter')) {
$asset->original_file_name = 'camera.smil';
} else {
$asset->original_file_name = 'slides.smil';
}
}

$url =
config('wowza.stream_url').config('wowza.content_path').
$asset->path.$asset->original_file_name.'/playlist.m3u8';
$wowzaContentPath =
$this->streamingSettings->data['content_path'].
$asset->path.
$asset->original_file_name;
$secureToken = $this->streamingSettings->data['secure_token'];
$tokenPrefix = $this->streamingSettings->data['token_prefix'];
$tokenStartTime = $tokenPrefix.'starttime='.time();
$tokenEndTime = $tokenPrefix.'endTime='.(time() + 21600);

$userIP = (App::environment(['testing', 'local'])) ? env('FAUTV_USER_IP') : $_SERVER['REMOTE_ADDR'];
$hashStr = "{$wowzaContentPath}?{$userIP}&{$secureToken}&{$tokenEndTime}&{$tokenStartTime}";
$hash = hash('sha256', $hashStr, 1);
$usableHash = strtr(base64_encode($hash), '+/', '-_');
$urlWithToken = "{$url}?{$tokenStartTime}&{$tokenEndTime}&{$tokenPrefix}hash={$usableHash}";
$filePaths->put($fileType, $urlWithToken);
});
}

return $filePaths;
}
}
25 changes: 23 additions & 2 deletions app/View/Components/Player.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Models\Clip;
use App\Services\WowzaService;
use Debugbar;
use Illuminate\Support\Collection;
use Illuminate\View\Component;
use Illuminate\View\View;
Expand All @@ -15,8 +16,12 @@ class Player extends Component
*
* @return void
*/
public function __construct(public Clip $clip, public Collection $wowzaStatus, public WowzaService $wowzaService)
{
public function __construct(
public Clip $clip,
public Collection $wowzaStatus,
// public WowzaService $wowzaService,
public $defaultVideoUrl
) {
//
}

Expand All @@ -25,6 +30,22 @@ public function __construct(public Clip $clip, public Collection $wowzaStatus, p
*/
public function render(): View
{
// $urls = $this->wowzaService->vodSecureUrls($this->clip);
//
// if (empty($urls)) {
// $defaultPlayerUrl = [];
// } elseif ($urls->has('composite')) {
// $defaultPlayerUrl = $urls['composite'];
// } elseif ($urls->has('presenter')) {
// $defaultPlayerUrl = $urls['presenter'];
// } elseif ($urls->has('presentation')) {
// $defaultPlayerUrl = $urls['presentation'];
// } else {
// $defaultPlayerUrl = [];
// }
//
// Debugbar::info($urls);

return view('components.player');
}
}
19 changes: 0 additions & 19 deletions app/helpers.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php

use App\Enums\Acl;
use App\Enums\Content;
use App\Models\Asset;
use App\Models\Clip;
use App\Models\User;
Expand Down Expand Up @@ -35,24 +34,6 @@ function getClipStoragePath(Clip $clip): string
"/{$clip->folder_id}/";
}

function getClipSmilFile(Clip $clip, bool $checkFAUTVLinks = true): string
{
if ($checkFAUTVLinks) {
return
config('wowza.stream_url').
config('wowza.content_path').
getClipStoragePath($clip).
'camera.smil/playlist.m3u8';
} else {
return
config('wowza.stream_url').
config('wowza.content_path').
getClipStoragePath($clip).
$clip->getAssetsByType(Content::SMIL)->first()?->original_file_name.
'/playlist.m3u8';
}
}

/*
* Fetch all files in the dropzone with sha1 hash
* @param bool $ffmpegCheck
Expand Down
Loading

0 comments on commit 67222a9

Please sign in to comment.