[#1] added images processing
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Service\MediaProcessing;
|
||||
|
||||
use App\Models\Genre;
|
||||
use App\Models\Image;
|
||||
use App\Models\ItemToFetchJobs;
|
||||
use App\Models\Movie;
|
||||
use App\Models\MovieAlternativeTitle;
|
||||
@@ -104,7 +105,48 @@ class MovieProcessingService implements ProcessingInterface
|
||||
$this->processCast($movie, $tmdbCredits['cast'] ?? []);
|
||||
$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)
|
||||
|
||||
Reference in New Issue
Block a user