[#1] added keywords to processing

This commit is contained in:
2024-12-30 02:48:39 +02:00
parent a735462fae
commit a44de7348e
5 changed files with 108 additions and 0 deletions
@@ -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();