[#2] content ratings

This commit is contained in:
2025-01-08 01:50:31 +02:00
parent 929954ebd9
commit 60ee3bb759
5 changed files with 112 additions and 0 deletions
@@ -3,6 +3,7 @@
namespace App\Service\MediaProcessing;
use App\Models\Comment;
use App\Models\ContentRating;
use App\Models\Episode;
use App\Models\ExternalId;
use App\Models\Image;
@@ -491,7 +492,36 @@ class ShowProcessingService implements ProcessingInterface
private function getContentRatings($item)
{
$tmdbContentRatings = $this->showsApi->getContentRatings($item->tmdb_id);
if (empty($tmdbContentRatings) || empty($tmdbContentRatings['results'])) {
return;
}
$show = Show::where('tmdb_id', $item->tmdb_id)->first();
foreach ($tmdbContentRatings['results'] as $contentRating) {
$existingContentRating = ContentRating::where('iso_3166', $contentRating['iso_3166_1'])
->where('rating', $contentRating['rating'])
->first();
if (!$existingContentRating) {
$existingContentRating = ContentRating::create([
'descriptors' => $contentRating['descriptors'],
'iso_3166' => $contentRating['iso_3166_1'],
'rating' => $contentRating['rating'],
]);
}
// attach if not attached
if (!$show->whereHas('contentRatings', function ($query) use ($show) {
$query->where('show_id', $show->id);
})->exists()) {
$show->contentRatings()->attach($existingContentRating);
}
}
$this->removeElementFromRemainingJobs($item->tmdb_id, ItemToFetchJobs::JOB_CONTENT_RATINGS);
}
private function processSeasons(Show $show, array $seasons)