[#1] releases processing

This commit is contained in:
2024-12-30 02:55:59 +02:00
parent a44de7348e
commit 3d7e0295ae
5 changed files with 131 additions and 1 deletions
+6 -1
View File
@@ -55,6 +55,11 @@ class Movie extends Model
public function keywords()
{
return $this->belongsToMany(Keyword::class, 'movie_keywords', 'movie_id', 'leyword_id');
return $this->belongsToMany(Keyword::class, 'movie_keywords', 'movie_id', 'keyword_id');
}
public function releaseDates()
{
return $this->belongsToMany(ReleaseDate::class, 'movie_release_dates', 'movie_id', 'release_date_id');
}
}
+18
View File
@@ -0,0 +1,18 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class ReleaseDate extends Model
{
protected $fillable = [
'iso_3166',
'certification',
'descriptors',
'iso_639',
'note',
'release_date',
'type',
];
}
@@ -10,6 +10,7 @@ use App\Models\Movie;
use App\Models\MovieAlternativeTitle;
use App\Models\MovieCollection;
use App\Models\Person;
use App\Models\ReleaseDate;
use App\Service\TMDBApi\MoviesApi;
use App\Service\TMDBApi\PersonApi;
use Illuminate\Support\Str;
@@ -184,6 +185,49 @@ class MovieProcessingService implements ProcessingInterface
$this->removeElementFromRemainingJobs($item->tmdb_id, ItemToFetchJobs::JOB_KEYWORDS);
}
private function getReleases($item)
{
$tmdbReleases = $this->moviesApi->getReleases($item->tmdb_id);
if (empty($tmdbReleases) || !isset($tmdbReleases['countries'])) {
echo "[E] Movie ".$item->tmdb_id ." Releases ".json_encode($tmdbReleases)."\n\n";
return;
}
$movie = Movie::where('tmdb_id', $item->tmdb_id)->first();
echo "Movie ".$movie->id ." Releases ".json_encode($tmdbReleases)."\n\n";
foreach ($tmdbReleases['countries'] as $tmdbRelease) {
$existingReleaseDate = ReleaseDate::where('iso_3166', $tmdbRelease['iso_3166_1'])
->where('release_date', $tmdbRelease['release_date'])
->where('certification', $tmdbRelease['certification'])
->first();
if (!$existingReleaseDate) {
$existingReleaseDate = ReleaseDate::create([
'iso_3166' => $tmdbRelease['iso_3166_1'],
'certification' => $tmdbRelease['certification'],
'descriptors' => $tmdbRelease['descriptors'] ? json_encode($tmdbRelease['descriptors']) : null,
'release_date' => $tmdbRelease['release_date'],
]);
}
if ($movie->whereHas('releaseDates', function ($query) use ($movie) {
$query->where('movie_id', $movie->id);
})->exists()) {
echo "Movie has release date | ";
return;
} else {
echo "Movie does not have release date | ";
$movie->releaseDates()->attach($existingReleaseDate);
}
}
$this->removeElementFromRemainingJobs($item->tmdb_id, ItemToFetchJobs::JOB_RELEASES);
}
private function processMovieCollection(int $movieId, $belongsToCollection)
{
$movieCollection = MovieCollection::where('tmdb_id', $belongsToCollection['id'])->first();
@@ -0,0 +1,34 @@
<?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('release_dates', function (Blueprint $table) {
$table->id();
$table->string('iso_3166');
$table->string('certification');
$table->text('descriptors');
$table->string('iso_639');
$table->text('note');
$table->date('release_date');
$table->integer('type');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('release_dates');
}
};
@@ -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_release_dates', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('movie_id');
$table->unsignedBigInteger('release_date_id');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('movie_release_dates');
}
};