diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 467a533..11ca604 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -74,12 +74,12 @@ public function homesearch() } - public function search(SearchRequest $request, TmdbClient $tmdb) + public function search(SearchRequest $request, ApiClient $api) { $query = $request->validated()['search']; $page = $request->query('page', 1); - $results = $tmdb->getSearch($query, $page); - ['data' => $data, 'pagination' => $pagination] = $this->formatTmdbSearchResponse($results); + $results = $api->getSearch($query); + ['data' => $data, 'pagination' => $pagination] = $this->formatApiSearchResponse($results); $page_text = ($page > 1) ? sprintf(' - Page %s', $page) : ''; @@ -100,11 +100,11 @@ public function search(SearchRequest $request, TmdbClient $tmdb) return view('search', compact('data', 'pagination', 'meta', 'query')); } - public function search_more(SearchRequest $request, TmdbClient $tmdb) + public function search_more(SearchRequest $request, ApiClient $api) { $query = $request->validated()['search']; $page = $request->validated()['page']; - $results = $this->formatTmdbSearchResponse($tmdb->getSearch($query, $page)); + $results = $this->formatApiSearchResponse($api->getSearch($query), $page); // dd($results); $items = MoreTitles::collection($results['data']); $has_more_pages = $results['pagination']->hasMorePages(); diff --git a/app/Services/ApiClient.php b/app/Services/ApiClient.php index 9ae4690..50b5d3b 100644 --- a/app/Services/ApiClient.php +++ b/app/Services/ApiClient.php @@ -190,6 +190,24 @@ public function getGenreShows($id, $page = 1, $per_page = null) return $results; } + public function getSearch(string $query) + { + $path = 'search'; + $options = [ + 'query' => $query + ]; + $key = Str::slug(implode(' ', [$path, str($query)->slug()]), '_'); + if ($this->use_cache === true) { + $results = Cache::remember($key, $this->cache_time, function () use ($path, $options) { + return $this->_call($path, $options); + }); + } else { + $results = $this->_call($path, $options); + } + + return $results; + } + private function _call(string $path, array $options = []) { diff --git a/app/Supports/Traits/CleanItems.php b/app/Supports/Traits/CleanItems.php index 84f6857..114cb33 100644 --- a/app/Supports/Traits/CleanItems.php +++ b/app/Supports/Traits/CleanItems.php @@ -267,6 +267,35 @@ public function formatApiResponse(Object $data, $with_pagination = true, $route // dd($response); return $response; } + + public function formatApiSearchResponse(array $data, int $page = 1): array + { + $response = []; + $results = collect([]); + if (!empty($data)) { + + $items = collect($data)->filter(fn($item) => in_array($item->type, ['movie', 'show']))->map(fn($item) =>(Object)$item); + $results = $items->map(function($item) { + + return [ + 'id' => self::encodeId($item->id), + 'title' => $item->title ?? $item->name, + 'image' => self::getImageUrl($item->poster_path, 'w500', 230, 345), + 'link' => self::getItemUrl($item), + 'slug' => Str::slug($item->title ?? $item->name) === '' ? sprintf('f%sl', $item->id) : Str::slug($item->title ?? $item->name), + 'year' => isset($item->release_date) ? Carbon::parse($item->release_date ?? '')->format('Y') : Carbon::parse($item->first_air_date ?? '')->format('Y'), + 'type' => match($item->type) {'movie' => 'movie', 'show' => 'show'}, + ]; + }); + } + + $response['pagination'] = new LengthAwarePaginator($results->forPage($page, 20), count($results), 20, $page, [ + 'path' => request()->url() + ]); + $response['data'] = $response['pagination']->items(); + + return $response; + } public function formatTmdbSearchResponse(array $data): array { // dd($data->data); diff --git a/config/services.php b/config/services.php index cf7bc2b..f6cabfe 100644 --- a/config/services.php +++ b/config/services.php @@ -36,7 +36,7 @@ 'cache_ttl' => env('TMDB_CACHE_TTL', 3600*24), ], 'api' => [ - 'api_url' => env('API_URL', 'https://qa.softcad.pw/'), + 'api_url' => env('API_URL', 'https://api.gostream.mobi/'), 'per_page' => env('API_PER_PAGE', 48), 'use_cache' => env('API_USE_CACHE', true), 'cache_ttl' => env('API_CACHE_TTL', 3600*2), diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php index 0b0bfce..04a980a 100644 --- a/resources/views/home.blade.php +++ b/resources/views/home.blade.php @@ -69,7 +69,26 @@ @include('sections.single', ['item' => $trending_movies[5]]) +
+

123movies

+

123movies uses a collection of various sources available online to watch legal movies and TV shows online. The sources you'll find on 123movies are for free with ads, subscription, rentals, and purchase. They are all provided by the Streamboat API, which also provides other info, videos, and images to 123movies. + +Some of the top sources used on 123movies as of 2024 are: +

+ +
@endsection