[#1] added images processing

This commit is contained in:
2024-12-30 02:42:07 +02:00
parent 51a6ab6c7a
commit a735462fae
5 changed files with 131 additions and 1 deletions
+19
View File
@@ -0,0 +1,19 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Image extends Model
{
protected $fillable = [
'aspect_ratio',
'height',
'iso',
'file_path',
'vote_average',
'vote_count',
'width',
'type',
];
}
+5
View File
@@ -47,4 +47,9 @@ class Movie extends Model
{ {
return $this->belongsToMany(Person::class, 'movie_crew', 'movie_id', 'person_id'); return $this->belongsToMany(Person::class, 'movie_crew', 'movie_id', 'person_id');
} }
public function images()
{
return $this->belongsToMany(Image::class, 'movie_images', 'movie_id', 'image_id');
}
} }
@@ -3,6 +3,7 @@
namespace App\Service\MediaProcessing; namespace App\Service\MediaProcessing;
use App\Models\Genre; use App\Models\Genre;
use App\Models\Image;
use App\Models\ItemToFetchJobs; use App\Models\ItemToFetchJobs;
use App\Models\Movie; use App\Models\Movie;
use App\Models\MovieAlternativeTitle; use App\Models\MovieAlternativeTitle;
@@ -104,7 +105,48 @@ class MovieProcessingService implements ProcessingInterface
$this->processCast($movie, $tmdbCredits['cast'] ?? []); $this->processCast($movie, $tmdbCredits['cast'] ?? []);
$this->processCrew($movie, $tmdbCredits['crew'] ?? []); $this->processCrew($movie, $tmdbCredits['crew'] ?? []);
$this->removeElementFromRemainingJobs($item->tmdb_id, ItemJob::JOB_CREDITS); $this->removeElementFromRemainingJobs($item->tmdb_id, ItemToFetchJobs::JOB_CREDITS);
}
private function getImages($item)
{
$tmdbImages = $this->moviesApi->getImages($item->tmdb_id);
if (empty($tmdbImages)) {
return;
}
$movie = Movie::where('tmdb_id', $item->tmdb_id)->first();
foreach ($tmdbImages as $type => $images) {
if (!is_array($images)) {
continue;
}
foreach ($images as $image) {
$imageExists = Image::where('type', $type)
->where('file_path', $image['file_path'])
->first();
if (!$imageExists) {
$image['iso'] = $image['iso_639_1'];
$image['type'] = $type;
$imageExists = Image::create($image);
}
if ($movie->whereHas('images', function ($query) use ($imageExists) {
$query->where('type', $imageExists->type)
->where('file_path', $imageExists->file_path);
})->exists()) {
echo "Movie has image | ";
return;
} else {
echo "Movie does not have image | ";
$movie->images()->attach($imageExists);
}
}
}
$this->removeElementFromRemainingJobs($item->tmdb_id, ItemToFetchJobs::JOB_IMAGES);
} }
private function processMovieCollection(int $movieId, $belongsToCollection) private function processMovieCollection(int $movieId, $belongsToCollection)
@@ -0,0 +1,35 @@
<?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('images', function (Blueprint $table) {
$table->id();
$table->decimal('aspect_ratio', 10, 2);
$table->integer('height');
$table->string('iso');
$table->text('file_path');
$table->decimal('vote_average', 10, 2);
$table->integer('vote_count');
$table->integer('width');
$table->string('type');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('images');
}
};
@@ -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_images', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('movie_id');
$table->unsignedBigInteger('image_id');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('movie_images');
}
};