From 6eab26d677fe47b5d56c4e753194cf0c7a8dbd5b Mon Sep 17 00:00:00 2001 From: Constantin Plaiasu Date: Fri, 30 Aug 2024 19:49:30 +0300 Subject: [PATCH] season --- app/Http/Controllers/ShowController.php | 57 ++++++++----------------- app/Supports/SchemaBuilder.php | 2 +- app/Supports/Traits/CleanItems.php | 14 +++--- resources/views/show.blade.php | 27 +++++++++--- routes/web.php | 9 +++- 5 files changed, 50 insertions(+), 59 deletions(-) diff --git a/app/Http/Controllers/ShowController.php b/app/Http/Controllers/ShowController.php index b9de67c..905facd 100644 --- a/app/Http/Controllers/ShowController.php +++ b/app/Http/Controllers/ShowController.php @@ -14,7 +14,7 @@ use Illuminate\Support\Facades\Route; use Inertia\Inertia; use Illuminate\Support\Str; -use App\Supports\Traits\Helpers; +use App\Supports\Helpers; use App\Http\Requests\MoreMoviesRequest; use App\Http\Resources\MoreTitles; @@ -64,7 +64,6 @@ public function season(TmdbClient $tmdb, ApiClient $api, int $id, string $slug = $id = self::decodeId($id); $show = $tmdb->getShow($id); - $data = $this->formatTmdbShow($show); if (isset($season)) { $season_number = (int)$season; @@ -72,10 +71,8 @@ public function season(TmdbClient $tmdb, ApiClient $api, int $id, string $slug = $season = $tmdb->getSeason($show['id'], $season_number); $season = $this->formatTmdbSeason($season, $show); } - $airing = $this->formatTmdbResponse($tmdb->getAiringShows(1), false, [], 12)['data']; - // dd($data); - // $data['meta']['title'] = 'Watch ' . $movie['title']; - return $data; + // $airing = $this->formatTmdbResponse($tmdb->getAiringShows(1), false, [], 12)['data']; + return $show; }; $results = $call(); // Cache::remember(implode('__', ['show', $id, $slug, $season]),3600, $call); // dd($results); @@ -101,54 +98,34 @@ public function season(TmdbClient $tmdb, ApiClient $api, int $id, string $slug = } - public function episode(TmdbClient $tmdb, ApiClient $api, AdsController $adsController, int $id, int $season, int $episode, string $slug) + public function episode(TmdbClient $tmdb, ApiClient $api, AdsController $adsController, int $id, string $slug, int $season, int $episode) { $similar = []; $season_number = $season; $episode_number = $episode; $call = function() use($tmdb, $id, &$season, &$episode, &$similar, $season_number, $episode_number){ $id = self::decodeId($id); - $show = $tmdb->getShow($id); - $data = $this->formatTmdbShow($show); - $season = $tmdb->getSeason($show['id'], $season_number); - $season = $this->formatTmdbSeason($season); - $episode = $tmdb->getEpisode($show['id'], $season_number, $episode_number); + $data = $tmdb->getShow($id); + $season = $tmdb->getSeason($data['id'], $season_number); + $season = $this->formatTmdbSeason($season, $data); + $episode = $tmdb->getEpisode($data['id'], $season_number, $episode_number); $episode = $this->formatTmdbEpisode($episode); - - // $episode - // dd($data); - // $data['meta']['title'] = 'Watch ' . $movie['title']; return $data; }; - $results = $call(); // Cache::remember(implode('__', ['show', $id, $slug, $season]),3600, $call); + $show = $call(); // Cache::remember(implode('__', ['show', $id, $slug, $season]),3600, $call); // dd($results); - $meta['schema'] = SchemaBuilder::getShowEpisodeSchema($results, $season, $episode); - $data = $results; - $top = $this->getTopContent($tmdb, $api); - // dd($data); - // dd($upcoming); - $meta['title'] = Str::replace(['{TITLE}', '{SEASON}', '{EPISODE}', '{EPISODE_TITLE}'], [$data['title'], $season_number, $episode_number, $episode['name']], config('site.shows.detail_episode.title')); + $meta['schema'] = SchemaBuilder::getShowEpisodeSchema($show, $season, $episode); + + // load episode background path if available + $show['backdrop_path'] = $episode['still_path'] ?? $show['backdrop_path']; + + $meta['title'] = Str::replace(['{TITLE}', '{SEASON}', '{EPISODE}', '{EPISODE_TITLE}'], [$show['title'], $season_number, $episode_number, $episode['name']], config('site.shows.detail_episode.title')); $meta['description'] = Str::limit(Str::replace(['{OVERVIEW}', '{SEASON}', '{EPISODE}'], [$episode['overview'], $season_number, $episode_number], config('site.shows.detail_episode.description')), 150); $meta['image'] = $episode['backdrop']; $meta['keywords'] = config('site.shows.detail_episode.keywords'); - - // dd($season); - if (defined('SHOULD_PRERENDER')) { - return view('prerender.show', compact('data', 'season', 'episode', 'meta', 'top')); - } - - $modal = $adsController->shouldGetModal(request()->headers->get('cf-ipcountry', 'AU')); - - $meta = self::encodeForInertia($meta ?? []) ; - $top = self::encodeForInertia($top); - $data = self::encodeForInertia($data ?? []); - $season = self::encodeForInertia($season ?? []); - $episode = self::encodeForInertia($episode ?? []); - - - return Inertia::render('Show', compact('data', 'season', 'episode', 'meta', 'top', 'modal')); - + $is_show_page = false; + return view('show', compact('show', 'season', 'episode', 'meta', 'is_show_page')); } diff --git a/app/Supports/SchemaBuilder.php b/app/Supports/SchemaBuilder.php index b9ad632..abdfbfc 100644 --- a/app/Supports/SchemaBuilder.php +++ b/app/Supports/SchemaBuilder.php @@ -194,7 +194,7 @@ public static function getShowSeasonSchema($show, $season): array return Schema::person()->name($actor['name'])->image($actor['image']); })->values()->all(); $movieSchema->actor($actors); - $directors = collect($season['crew'])->filter(fn ($director) => Str::of($director['as'])->contains('producer', true))->map(function ($director) { + $directors = collect($season['crew']['producers'])->map(function ($director) { return Schema::person()->name($director['name'])->image($director['image']); })->values()->all(); $movieSchema->producer($directors); diff --git a/app/Supports/Traits/CleanItems.php b/app/Supports/Traits/CleanItems.php index 9d59d8c..84f6857 100644 --- a/app/Supports/Traits/CleanItems.php +++ b/app/Supports/Traits/CleanItems.php @@ -19,14 +19,11 @@ protected function getPageLabel(?string $label) switch ($label) { case 'pagination.previous': return 'Previous'; - break; case 'pagination.next': return 'Next'; - break; default: return $label; - break; } } @@ -130,10 +127,10 @@ public function formatTmdbSeason($data, $showData):array $show['overview'] = $data['overview'] !== '' ? $data['overview'] : $showData['overview']; $show['cast'] = $this->getCast($show['credits']['cast'] ?? $showData['credits']['cast'] ?? [], 8); $show['crew']['producers'] = $this->getCrew($show['credits']['crew'] ?? $showData['credits']['crew'] ?? [], 8); - $show['air_date'] = Helpers::formatReleaseDate($data['air_date']); + $show['air_date'] = self::formatReleaseDate($data['air_date']); $show['poster'] = $this->getImageUrl($data['poster_path'], 'w500', 230, 345); $show['episodes'] = collect($show['episodes'])->map(function($episode){ - $episode['air_date'] = Helpers::formatReleaseDate($episode['air_date']); + $episode['air_date'] = self::formatReleaseDate($episode['air_date']); $episode['label'] = /* 'S'.str_pad($episode['season_number'], 2, '0', STR_PAD_LEFT). 'E'.*/str_pad($episode['episode_number'], 2, '0', STR_PAD_LEFT); $episode['backdrop'] = $this->getImageUrl($episode['still_path'], 'w1280', 1280, 720); unset($episode['still_path']); @@ -154,11 +151,10 @@ public function formatTmdbEpisode($data):array $episode['cast'] = $this->getCast($episode['credits']['cast'] ?? [], 8); $episode['crew'] = $this->getCrew($episode['credits']['crew'] ?? [], 8); - $episode['air_date'] = Helpers::formatReleaseDate($episode['air_date']); - $episode['vote_average'] = round($episode['vote_average']/2, 1); + $episode['air_date'] = self::formatReleaseDate($episode['air_date']); + $episode['vote_average'] = round($episode['vote_average'], 1); $episode['label'] = 'S'.str_pad($episode['season_number'], 2, '0', STR_PAD_LEFT).'E'.str_pad($episode['episode_number'], 2, '0', STR_PAD_LEFT); - - unset($episode['still_path']); + // unset($episode['still_path']); unset($episode['credits']); diff --git a/resources/views/show.blade.php b/resources/views/show.blade.php index 297ab8f..d222f08 100644 --- a/resources/views/show.blade.php +++ b/resources/views/show.blade.php @@ -18,12 +18,12 @@ @section('app')
- {{ str($show['title'])->apa() }} ({{ $show['year'] }}) + {{ str($show['title'])->apa() }} ({{ $show['year'] }})
-

{{ str($show['title'])->apa() }}

+

{{ $show['title'] }}

@if($show['tagline'])

"{{ $show['tagline'] }}"

@endif @@ -44,10 +44,23 @@
-

Watch {{ str($show['title'])->apa() }}

+

Watch {{ str($show['title']) }} @unless($is_show_page) + - {{ str($episode['name'] ?? $season['name']) }} + @endunless()

- Type : TV Show - Seasons: {{ count($show['seasons']) }} + Type : + @if($episode) + Episode + Season: {{ $episode['season_number'] }} + Episode: {{ $episode['episode_number'] }} + @elseif ($season) + Season + Season: {{ $season['season_number'] }} + @else + TV Show + Seasons: {{ count($show['seasons']) }} + @endif +
@@ -337,9 +350,9 @@
- @foreach ($airing as $item) + {{-- @foreach ($airing as $item) @include('components.show_card') - @endforeach + @endforeach --}}
diff --git a/routes/web.php b/routes/web.php index 5f49c84..78adb04 100644 --- a/routes/web.php +++ b/routes/web.php @@ -34,8 +34,13 @@ Route::get('/movie/{id}/{slug}', [MovieController::class, 'index'])->name('movie'); -Route::get('/series/{id}/{slug}', [ShowController::class, 'index'])->name('show'); -Route::get('/series/{id}/{slug}/season/{season}', [ShowController::class, 'season'])->name('show.season'); + +Route::group(['prefix' => '/series'], function(){ + Route::get('/{id}/{slug}', [ShowController::class, 'index'])->name('show'); + Route::get('/{id}/{slug}/season/{season}', [ShowController::class, 'season'])->name('show.season'); + Route::get('/{id}/{slug}/season/{season}/episode/{episode}', [ShowController::class, 'episode'])->name('show.episode'); +}); + Route::get('/person/{person_id}/{slug}', [PeopleController::class, 'index'])->name('person'); Route::get('/search', [HomeController::class, 'search'])->name('search');