[#2] content ratings
This commit is contained in:
@@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class ContentRating extends Model
|
||||||
|
{
|
||||||
|
protected $fillable = [
|
||||||
|
'descriptors',
|
||||||
|
'iso_3166',
|
||||||
|
'rating',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $casts = [
|
||||||
|
'descriptors' => 'array',
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -65,4 +65,9 @@ class Show extends Model
|
|||||||
{
|
{
|
||||||
return $this->belongsToMany(WatchProvider::class, 'show_watch_providers', 'show_id', 'watch_provider_id');
|
return $this->belongsToMany(WatchProvider::class, 'show_watch_providers', 'show_id', 'watch_provider_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function contentRatings()
|
||||||
|
{
|
||||||
|
return $this->belongsToMany(ContentRating::class, 'show_content_ratings', 'show_id', 'content_rating_id');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace App\Service\MediaProcessing;
|
namespace App\Service\MediaProcessing;
|
||||||
|
|
||||||
use App\Models\Comment;
|
use App\Models\Comment;
|
||||||
|
use App\Models\ContentRating;
|
||||||
use App\Models\Episode;
|
use App\Models\Episode;
|
||||||
use App\Models\ExternalId;
|
use App\Models\ExternalId;
|
||||||
use App\Models\Image;
|
use App\Models\Image;
|
||||||
@@ -491,7 +492,36 @@ class ShowProcessingService implements ProcessingInterface
|
|||||||
|
|
||||||
private function getContentRatings($item)
|
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)
|
private function processSeasons(Show $show, array $seasons)
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<?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('content_ratings', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->json('descriptors')->default(null);
|
||||||
|
$table->string('iso_3166', 10)->default(null);
|
||||||
|
$table->string('rating', 50)->default(null);
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('content_ratings');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -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('show_content_ratings', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->unsignedBigInteger('show_id');
|
||||||
|
$table->unsignedBigInteger('content_rating_id');
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('show_content_ratings');
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user