[#1] similar movies
This commit is contained in:
@@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class MovieSimilar extends Model
|
||||||
|
{
|
||||||
|
protected $fillable = [
|
||||||
|
'movie_id',
|
||||||
|
'similar_movie_id',
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -15,6 +15,7 @@ use App\Models\Movie;
|
|||||||
use App\Models\MovieAlternativeTitle;
|
use App\Models\MovieAlternativeTitle;
|
||||||
use App\Models\MovieCollection;
|
use App\Models\MovieCollection;
|
||||||
use App\Models\MovieRecommendation;
|
use App\Models\MovieRecommendation;
|
||||||
|
use App\Models\MovieSimilar;
|
||||||
use App\Models\Person;
|
use App\Models\Person;
|
||||||
use App\Models\ReleaseDate;
|
use App\Models\ReleaseDate;
|
||||||
use App\Models\Translation;
|
use App\Models\Translation;
|
||||||
@@ -507,6 +508,8 @@ class MovieProcessingService implements ProcessingInterface
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$initialMovie = Movie::where('tmdb_id', $item->tmdb_id)->first();
|
||||||
|
|
||||||
foreach ($tmdbRecommendations['results'] as $tmdbRecommendation) {
|
foreach ($tmdbRecommendations['results'] as $tmdbRecommendation) {
|
||||||
$itemToFetch = ItemToFetch::where('tmdb_id', $tmdbRecommendation['id'])->where('type', ItemToFetch::TYPE_MOVIE)->first();
|
$itemToFetch = ItemToFetch::where('tmdb_id', $tmdbRecommendation['id'])->where('type', ItemToFetch::TYPE_MOVIE)->first();
|
||||||
|
|
||||||
@@ -518,6 +521,17 @@ class MovieProcessingService implements ProcessingInterface
|
|||||||
$movie = Movie::where('tmdb_id', $tmdbRecommendation['id'])->first();
|
$movie = Movie::where('tmdb_id', $tmdbRecommendation['id'])->first();
|
||||||
|
|
||||||
if ($movie) {
|
if ($movie) {
|
||||||
|
$recommendationLink = MovieRecommendation::where('movie_id', $initialMovie->id)
|
||||||
|
->where('recommended_movie_id', $movie->id)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if (!$recommendationLink) {
|
||||||
|
MovieRecommendation::create([
|
||||||
|
'movie_id' => $initialMovie->id,
|
||||||
|
'recommended_movie_id' => $movie->id,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -546,6 +560,70 @@ class MovieProcessingService implements ProcessingInterface
|
|||||||
'recommended_movie_id' => $recommendedMovie->id,
|
'recommended_movie_id' => $recommendedMovie->id,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->removeElementFromRemainingJobs($item->tmdb_id, ItemToFetchJobs::JOB_RECOMMNDATION);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getSimilar($item)
|
||||||
|
{
|
||||||
|
$tmdbSimilarMovies = $this->moviesApi->getSimilar($item->tmdb_id);
|
||||||
|
|
||||||
|
if (empty($tmdbSimilarMovies) || empty($tmdbSimilarMovies['results'])) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$initialMovie = Movie::where('tmdb_id', $item->tmdb_id)->first();
|
||||||
|
|
||||||
|
foreach ($tmdbSimilarMovies['results'] as $tmdbSimilarMovie) {
|
||||||
|
$itemToFetch = ItemToFetch::where('tmdb_id', $tmdbSimilarMovie['id'])->where('type', ItemToFetch::TYPE_MOVIE)->first();
|
||||||
|
|
||||||
|
if ($itemToFetch) {
|
||||||
|
$this->getDetails($itemToFetch);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$similarMovie = Movie::where('tmdb_id', $tmdbSimilarMovie['id'])->first();
|
||||||
|
|
||||||
|
if ($similarMovie) {
|
||||||
|
$similarLink = MovieSimilar::where('movie_id', $initialMovie->id)
|
||||||
|
->where('similar_movie_id', $similarMovie->id)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if (!$similarLink) {
|
||||||
|
MovieRecommendation::create([
|
||||||
|
'movie_id' => $initialMovie->id,
|
||||||
|
'similar_movie_id' => $similarMovie->id,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$itemToFetch = ItemToFetch::create([
|
||||||
|
'tmdb_id' => $tmdbSimilarMovie['id'],
|
||||||
|
'type' => ItemToFetch::TYPE_MOVIE,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$jobs = ItemToFetchJobs::JOBS;
|
||||||
|
$jobs[] = "Details";
|
||||||
|
|
||||||
|
ItemToFetchJobs::create([
|
||||||
|
'tmdb_id' => $tmdbSimilarMovie['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', $tmdbSimilarMovie['id'])->first();
|
||||||
|
|
||||||
|
MovieSimilar::create([
|
||||||
|
'movie_id' => $movie->id,
|
||||||
|
'similar_movie_id' => $recommendedMovie->id,
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function processMovieCollection(int $movieId, $belongsToCollection)
|
private function processMovieCollection(int $movieId, $belongsToCollection)
|
||||||
|
|||||||
@@ -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_similars', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->unsignedBigInteger('movie_id');
|
||||||
|
$table->unsignedBigInteger('similar_movie_id');
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('movie_similars');
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user