add own search

This commit is contained in:
Constantin Plaiasu 2024-09-25 07:40:46 +03:00
parent 1dbd255a80
commit 7b73e8094c
5 changed files with 72 additions and 6 deletions

View file

@ -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();

View file

@ -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 = [])
{

View file

@ -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);

View file

@ -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),

View file

@ -69,7 +69,26 @@
@include('sections.single', ['item' => $trending_movies[5]])
</div>
<div class="sources" style="width:95%;margin:0 auto;margin-bottom:10px">
<h2 style="text-align:center">123movies</h2>
<p>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 <a href="https://streamboat.net">Streamboat</a> API, which also provides other info, videos, and images to 123movies.
</b>
Some of the top sources used on 123movies as of 2024 are:
<ul class="link-list">
<li><a href="https://netflix.com">Netflix</a></li>
<p>Netflix is the most popular streaming platform in the entire world and offers a massive library of some of the most popular movies and TV series online today. If you don't already have Netflix we definitely recommend you sign up for a subscription!</p>
<li><a href="https://primevideo.com">Prime Video</a></li>
<p>Prime Video is not only a top selection for the latest movies & shows online, but also comes with the Amazon Prime benefits like free 2 day shipping on Prime items, and decreased pricing on Prime eligible items. While more streaming may take place on Netflix, far more people have an Amazon Prime account throughout the world, just make sure you make use of Prime Video if you haven't already.</p>
<li><a href="https://freevee.com">Freevee</a></li>
<p>Freevee is the free service from Amazon that is ad based. It's titles cannot be watched without ads no matter what but it has an amazing selection of free content, and you can easily find all of it on 123movies.onl.</p>
<li><a href="https://pluto.tv">Pluto TV</a></li>
<p>Pluto TV is another free, ad-based, movie and TV service that has a large selection. Offering both an extensive movie collection with a great TV library, it's one of the best free sources to watch online.</p>
<li><a href="https://disneyplus.com">Disney+</a></li>
<p>Disney+ is becoming a combination of many of your favorite OTT apps. With Disney's recent purchase of Fox, it now has control of hulu, which makes it easy to combine these services at a discounted price, for a little more you can add on ESPN+, which will give you all the sports, kids content, and adult movies and shows that you'll need.</p>
</ul>
</div>
@endsection