[#1] movie recommendation
This commit is contained in:
@@ -14,6 +14,7 @@ use App\Models\MediaListItem;
|
||||
use App\Models\Movie;
|
||||
use App\Models\MovieAlternativeTitle;
|
||||
use App\Models\MovieCollection;
|
||||
use App\Models\MovieRecommendation;
|
||||
use App\Models\Person;
|
||||
use App\Models\ReleaseDate;
|
||||
use App\Models\Translation;
|
||||
@@ -498,6 +499,55 @@ class MovieProcessingService implements ProcessingInterface
|
||||
$this->removeElementFromRemainingJobs($item->tmdb_id, ItemToFetchJobs::JOB_LISTS);
|
||||
}
|
||||
|
||||
private function getRecommendations($item)
|
||||
{
|
||||
$tmdbRecommendations = $this->moviesApi->getRecommendations($item->tmdb_id);
|
||||
|
||||
if (empty($tmdbRecommendations) || empty($tmdbRecommendations['results'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($tmdbRecommendations['results'] as $tmdbRecommendation) {
|
||||
$itemToFetch = ItemToFetch::where('tmdb_id', $tmdbRecommendation['id'])->where('type', ItemToFetch::TYPE_MOVIE)->first();
|
||||
|
||||
if ($itemToFetch) {
|
||||
$this->getDetails($itemToFetch);
|
||||
continue;
|
||||
}
|
||||
|
||||
$movie = Movie::where('tmdb_id', $tmdbRecommendation['id'])->first();
|
||||
|
||||
if ($movie) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
$itemToFetch = ItemToFetch::create([
|
||||
'tmdb_id' => $tmdbRecommendation['id'],
|
||||
'type' => ItemToFetch::TYPE_MOVIE,
|
||||
]);
|
||||
|
||||
$jobs = ItemToFetchJobs::JOBS;
|
||||
$jobs[] = "Details";
|
||||
|
||||
ItemToFetchJobs::create([
|
||||
'tmdb_id' => $tmdbRecommendation['id'],
|
||||
'type' => ItemToFetch::TYPE_MOVIE,
|
||||
'remaining_jobs' => json_encode($jobs),
|
||||
]);
|
||||
|
||||
$this->getDetails($itemToFetch);
|
||||
|
||||
$movie = Movie::where('tmdb_id', $item->tmdb_id)->first();
|
||||
$recommendedMovie = Movie::where('tmdb_id', $tmdbRecommendation['id'])->first();
|
||||
|
||||
MovieRecommendation::create([
|
||||
'movie_id' => $movie->id,
|
||||
'recommended_movie_id' => $recommendedMovie->id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
private function processMovieCollection(int $movieId, $belongsToCollection)
|
||||
{
|
||||
$movieCollection = MovieCollection::where('tmdb_id', $belongsToCollection['id'])->first();
|
||||
|
||||
Reference in New Issue
Block a user