lots of progress
This commit is contained in:
@@ -17,6 +17,8 @@ use App\Models\MovieCollection;
|
||||
use App\Models\MovieRecommendation;
|
||||
use App\Models\MovieSimilar;
|
||||
use App\Models\Person;
|
||||
use App\Models\ProductionCompany;
|
||||
use App\Models\ProductionCountry;
|
||||
use App\Models\ReleaseDate;
|
||||
use App\Models\Translation;
|
||||
use App\Models\User;
|
||||
@@ -79,6 +81,14 @@ class MovieProcessingService implements ProcessingInterface
|
||||
$this->processMovieGenres($movieId->id, $tmdbMovie['genres']);
|
||||
}
|
||||
|
||||
if (!empty($tmdbMovie['production_companies'])) {
|
||||
$this->processProductionCompanies($movieId->id, $tmdbMovie['production_companies']);
|
||||
}
|
||||
|
||||
if (!empty($tmdbMovie['production_countries'])) {
|
||||
$this->processProductionCountries($movieId->id, $tmdbMovie['production_countries']);
|
||||
}
|
||||
|
||||
$this->removeElementFromRemainingJobs($tmdbMovie['id'], 'Details');
|
||||
}
|
||||
|
||||
@@ -112,9 +122,11 @@ class MovieProcessingService implements ProcessingInterface
|
||||
|
||||
private function getCredits($item)
|
||||
{
|
||||
echo "Credits for TMDBID ".$item->tmdb_id." \n";
|
||||
$tmdbCredits = $this->moviesApi->getCredits($item->tmdb_id);
|
||||
|
||||
if (empty($tmdbCredits)) {
|
||||
echo "Empty for ".$item->tmdb_id." \n";
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -701,10 +713,16 @@ class MovieProcessingService implements ProcessingInterface
|
||||
{
|
||||
$itemToFetchJobs = ItemToFetchJobs::where('tmdb_id', $tmdbId)->first();
|
||||
|
||||
$remainingJobs = $itemToFetchJobs->remaining_jobs;
|
||||
if (!$itemToFetchJobs) {
|
||||
return;
|
||||
}
|
||||
|
||||
$remainingJobs = $itemToFetchJobs->jobs;
|
||||
|
||||
if (is_string($remainingJobs)) {
|
||||
$remainingJobs = json_decode($remainingJobs, true);
|
||||
$remainingJobs = explode(',', $remainingJobs);
|
||||
} else {
|
||||
dd($remainingJobs, $tmdbId);
|
||||
}
|
||||
|
||||
$remainingJobKey = array_search($job, $remainingJobs);
|
||||
@@ -715,13 +733,14 @@ class MovieProcessingService implements ProcessingInterface
|
||||
$itemToFetchJobs->delete();
|
||||
}
|
||||
|
||||
$itemToFetchJobs->remaining_jobs = $remainingJobs;
|
||||
// $itemToFetchJobs->remaining_jobs = $remainingJobs;
|
||||
$itemToFetchJobs->jobs = implode(',', $remainingJobs);
|
||||
$itemToFetchJobs->save();
|
||||
}
|
||||
|
||||
private function processCast($movie, array $castList)
|
||||
{
|
||||
if (empty($castList)) {
|
||||
if (empty($castList) || $movie === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -753,15 +772,12 @@ class MovieProcessingService implements ProcessingInterface
|
||||
'place_of_birth' => $tmdbPerson['place_of_birth'],
|
||||
]);
|
||||
}
|
||||
|
||||
$person = Person::create($personData);
|
||||
}
|
||||
|
||||
if ($movie->whereHas('castList', function ($query) use ($person) {
|
||||
$query->where('tmdb_id', '=', $person->tmdb_id);
|
||||
if (!$movie->whereHas('castList', function ($query) use ($person) {
|
||||
$query->where('person_id', '=', $person->id);
|
||||
})->exists()) {
|
||||
return;
|
||||
} else {
|
||||
$movie->castList()->attach($person, [
|
||||
'known_for_department' => $castPerson['known_for_department'],
|
||||
'character' => $castPerson['character'],
|
||||
@@ -825,6 +841,56 @@ class MovieProcessingService implements ProcessingInterface
|
||||
}
|
||||
}
|
||||
|
||||
private function processProductionCompanies(int $movieId, array $productionCompanies)
|
||||
{
|
||||
$movie = Movie::find($movieId);
|
||||
|
||||
foreach ($productionCompanies as $productionCompany) {
|
||||
$existingProductionCompany = ProductionCompany::where('tmdb_id', $productionCompany['id'])->first();
|
||||
|
||||
if (!$existingProductionCompany) {
|
||||
$existingProductionCompany = ProductionCompany::create([
|
||||
'tmdb_id' => $productionCompany['id'],
|
||||
'logo_path' => $productionCompany['logo_path'],
|
||||
'name' => $productionCompany['name'],
|
||||
'origin_country' => $productionCompany['origin_country'],
|
||||
]);
|
||||
}
|
||||
|
||||
if ($movie->whereHas('productionCompanies', function ($query) use ($existingProductionCompany) {
|
||||
$query->where('production_company_id', '=', $existingProductionCompany->id);
|
||||
})->exists()) {
|
||||
return;
|
||||
} else {
|
||||
$movie->productionCompanies()->attach($existingProductionCompany);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function processProductionCountries(int $movieId, array $productionCountries)
|
||||
{
|
||||
$movie = Movie::find($movieId);
|
||||
|
||||
foreach ($productionCountries as $productionCountry) {
|
||||
$existingProductionCountry = ProductionCountry::where('iso_3166', $productionCountry['iso_3166_1'])->first();
|
||||
|
||||
if (!$existingProductionCountry) {
|
||||
$existingProductionCountry = ProductionCountry::create([
|
||||
'iso_3166' => $productionCountry['iso_3166_1'],
|
||||
'name' => $productionCountry['name'],
|
||||
]);
|
||||
}
|
||||
|
||||
if ($movie->whereHas('productionCountries', function ($query) use ($existingProductionCountry) {
|
||||
$query->where('production_country_id', '=', $existingProductionCountry->id);
|
||||
})->exists()) {
|
||||
return;
|
||||
} else {
|
||||
$movie->productionCountries()->attach($existingProductionCountry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function createJob($tmdbId)
|
||||
{
|
||||
$itemToFetch = ItemToFetch::where('tmdb_id', $tmdbId)->where('type', ItemToFetch::TYPE_MOVIE)->first();
|
||||
|
||||
Reference in New Issue
Block a user