[#1] added keywords to processing
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Keyword extends Model
|
||||
{
|
||||
//
|
||||
}
|
||||
@@ -52,4 +52,9 @@ class Movie extends Model
|
||||
{
|
||||
return $this->belongsToMany(Image::class, 'movie_images', 'movie_id', 'image_id');
|
||||
}
|
||||
|
||||
public function keywords()
|
||||
{
|
||||
return $this->belongsToMany(Keyword::class, 'movie_keywords', 'movie_id', 'leyword_id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace App\Service\MediaProcessing;
|
||||
use App\Models\Genre;
|
||||
use App\Models\Image;
|
||||
use App\Models\ItemToFetchJobs;
|
||||
use App\Models\Keyword;
|
||||
use App\Models\Movie;
|
||||
use App\Models\MovieAlternativeTitle;
|
||||
use App\Models\MovieCollection;
|
||||
@@ -149,6 +150,40 @@ class MovieProcessingService implements ProcessingInterface
|
||||
$this->removeElementFromRemainingJobs($item->tmdb_id, ItemToFetchJobs::JOB_IMAGES);
|
||||
}
|
||||
|
||||
private function getKeywords($item)
|
||||
{
|
||||
$tmdbKeywords = $this->moviesApi->getKeywords($item->tmdb_id);
|
||||
|
||||
if (empty($tmdbKeywords) || !isset($tmdbKeywords['keywords'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$movie = Movie::where('tmdb_id', $item->tmdb_id)->first();
|
||||
|
||||
foreach ($tmdbKeywords['keywords'] as $tmdbKeyword) {
|
||||
$existingKeyword = Keyword::where('tmdb_id', $tmdbKeyword['id'])->first();
|
||||
|
||||
if (!$existingKeyword) {
|
||||
$existingKeyword = Keyword::create([
|
||||
'name' => $tmdbKeyword['name'],
|
||||
'tmdb_id' => $tmdbKeyword['id'],
|
||||
]);
|
||||
}
|
||||
|
||||
if ($movie->whereHas('keywords', function ($query) use ($existingKeyword) {
|
||||
$query->where('tmdb_id', $existingKeyword->tmdb_id);
|
||||
})->exists()) {
|
||||
echo "Movie has keyword | ";
|
||||
return;
|
||||
} else {
|
||||
echo "Movie does not have keyword | ";
|
||||
$movie->keywords()->attach($existingKeyword);
|
||||
}
|
||||
}
|
||||
|
||||
$this->removeElementFromRemainingJobs($item->tmdb_id, ItemToFetchJobs::JOB_KEYWORDS);
|
||||
}
|
||||
|
||||
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_keywords', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('movie_id');
|
||||
$table->unsignedBigInteger('keyword_id');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('movie_keywords');
|
||||
}
|
||||
};
|
||||
@@ -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('keywords', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('tmdb_id');
|
||||
$table->string('name');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('keywords');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user