[#1] movie recommendation

This commit is contained in:
2024-12-30 23:44:50 +02:00
parent e60058c1c0
commit 3807d19cb7
3 changed files with 92 additions and 0 deletions
+13
View File
@@ -0,0 +1,13 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class MovieRecommendation extends Model
{
protected $fillable = [
'movie_id',
'recommended_movie_id',
];
}
@@ -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();
@@ -0,0 +1,29 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('movie_recommendations', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('movie_id');
$table->unsignedBigInteger('recommended_movie_id');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('movie_recommendations');
}
};