[#8] some fixes on movie processing
This commit is contained in:
@@ -47,7 +47,15 @@ class FetchItemDataCommand extends Command
|
|||||||
{
|
{
|
||||||
return ItemToFetch::has('jobs')
|
return ItemToFetch::has('jobs')
|
||||||
->with([
|
->with([
|
||||||
'jobs' => fn ($jobs) => array_search($job, $jobs->first()->remaining_jobs, true),
|
// 'jobs' => fn ($jobs) => dd($jobs->first()->remaining_jobs) /*array_search($job, $jobs->first()->remaining_jobs, true)*/,
|
||||||
|
'jobs' => function ($jobs) use ($job) {
|
||||||
|
$remainingJobs = $jobs->first()->remaining_jobs;
|
||||||
|
if (is_string($remainingJobs)) {
|
||||||
|
$remainingJobs = json_decode($jobs->first()->remaining_jobs, true);
|
||||||
|
}
|
||||||
|
return array_search($job, $remainingJobs, true);
|
||||||
|
},
|
||||||
|
|
||||||
])
|
])
|
||||||
->where('type', $type)
|
->where('type', $type)
|
||||||
->take($batch)
|
->take($batch)
|
||||||
|
|||||||
@@ -312,6 +312,10 @@ class MovieProcessingService implements ProcessingInterface
|
|||||||
|
|
||||||
$movie = Movie::where('tmdb_id', $item->tmdb_id)->first();
|
$movie = Movie::where('tmdb_id', $item->tmdb_id)->first();
|
||||||
|
|
||||||
|
if (!$movie) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$externalId = ExternalId::where('entity_id', $movie->id)
|
$externalId = ExternalId::where('entity_id', $movie->id)
|
||||||
->where('entity_type', ExternalId::TYPE_MOVIE)
|
->where('entity_type', ExternalId::TYPE_MOVIE)
|
||||||
->first();
|
->first();
|
||||||
@@ -321,6 +325,9 @@ class MovieProcessingService implements ProcessingInterface
|
|||||||
$externalIds['movie_id'] = $movie->id;
|
$externalIds['movie_id'] = $movie->id;
|
||||||
unset($externalIds['id']);
|
unset($externalIds['id']);
|
||||||
|
|
||||||
|
$externalIds['entity_id'] = $movie->id;
|
||||||
|
$externalIds['entity_type'] = ExternalId::TYPE_MOVIE;
|
||||||
|
|
||||||
ExternalId::create($externalIds);
|
ExternalId::create($externalIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -337,6 +344,12 @@ class MovieProcessingService implements ProcessingInterface
|
|||||||
|
|
||||||
$movie = Movie::where('tmdb_id', $item->tmdb_id)->first();
|
$movie = Movie::where('tmdb_id', $item->tmdb_id)->first();
|
||||||
|
|
||||||
|
if (!$movie) {
|
||||||
|
$itemToFetch = $this->createJob($item->tmdb_id);
|
||||||
|
$this->getDetails($itemToFetch);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$types = [
|
$types = [
|
||||||
'flatrate',
|
'flatrate',
|
||||||
'rent',
|
'rent',
|
||||||
@@ -349,6 +362,11 @@ class MovieProcessingService implements ProcessingInterface
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$providerInfo = $tmdbWatchProvider[$type];
|
$providerInfo = $tmdbWatchProvider[$type];
|
||||||
|
$providerInfo = reset($providerInfo);
|
||||||
|
|
||||||
|
if (!isset($providerInfo['provider_id'])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$existingWatchProvider = WatchProvider::where('tmdb_provider_id', $providerInfo['provider_id'])->first();
|
$existingWatchProvider = WatchProvider::where('tmdb_provider_id', $providerInfo['provider_id'])->first();
|
||||||
|
|
||||||
@@ -362,19 +380,16 @@ class MovieProcessingService implements ProcessingInterface
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
if (!$movie->whereHas('watchProviders', function ($query) use ($movie) {
|
||||||
|
|
||||||
if ($movie->whereHas('watchProviders', function ($query) use ($movie) {
|
|
||||||
$query->where('movie_id', $movie->id);
|
$query->where('movie_id', $movie->id);
|
||||||
})->exists()) {
|
})->exists()) {
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
$movie->watchProviders()->attach($existingWatchProvider, [
|
$movie->watchProviders()->attach($existingWatchProvider, [
|
||||||
'locale' => $locale,
|
'locale' => $locale,
|
||||||
'tmdb_url' => $tmdbWatchProvider['link'],
|
'tmdb_url' => $tmdbWatchProvider['link'],
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$this->removeElementFromRemainingJobs($item->tmdb_id, ItemToFetchJobs::JOB_WATCH_PROVIDERS);
|
$this->removeElementFromRemainingJobs($item->tmdb_id, ItemToFetchJobs::JOB_WATCH_PROVIDERS);
|
||||||
}
|
}
|
||||||
@@ -402,7 +417,7 @@ class MovieProcessingService implements ProcessingInterface
|
|||||||
'size' => $tmdbVideo['size'],
|
'size' => $tmdbVideo['size'],
|
||||||
'type' => $tmdbVideo['type'],
|
'type' => $tmdbVideo['type'],
|
||||||
'official' => $tmdbVideo['official'],
|
'official' => $tmdbVideo['official'],
|
||||||
'published_at' => $tmdbVideo['published_at'],
|
'published_at' => $tmdbVideo['published_at'] ? new \DateTime($tmdbVideo['published_at']) : null,
|
||||||
'tmdb_id' => $tmdbVideo['id'],
|
'tmdb_id' => $tmdbVideo['id'],
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@@ -687,6 +702,11 @@ class MovieProcessingService implements ProcessingInterface
|
|||||||
$itemToFetchJobs = ItemToFetchJobs::where('tmdb_id', $tmdbId)->first();
|
$itemToFetchJobs = ItemToFetchJobs::where('tmdb_id', $tmdbId)->first();
|
||||||
|
|
||||||
$remainingJobs = $itemToFetchJobs->remaining_jobs;
|
$remainingJobs = $itemToFetchJobs->remaining_jobs;
|
||||||
|
|
||||||
|
if (is_string($remainingJobs)) {
|
||||||
|
$remainingJobs = json_decode($remainingJobs, true);
|
||||||
|
}
|
||||||
|
|
||||||
$remainingJobKey = array_search($job, $remainingJobs);
|
$remainingJobKey = array_search($job, $remainingJobs);
|
||||||
|
|
||||||
unset($remainingJobs[$remainingJobKey]);
|
unset($remainingJobs[$remainingJobKey]);
|
||||||
@@ -804,4 +824,34 @@ class MovieProcessingService implements ProcessingInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function createJob($tmdbId)
|
||||||
|
{
|
||||||
|
$itemToFetch = ItemToFetch::where('tmdb_id', $tmdbId)->where('type', ItemToFetch::TYPE_MOVIE)->first();
|
||||||
|
|
||||||
|
if ($itemToFetch) {
|
||||||
|
return $itemToFetch;
|
||||||
|
}
|
||||||
|
|
||||||
|
$movie = Movie::where('tmdb_id', $tmdbId)->first();
|
||||||
|
if ($movie) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$itemToFetch = ItemToFetch::create([
|
||||||
|
'tmdb_id' => $tmdbId,
|
||||||
|
'type' => ItemToFetch::TYPE_MOVIE,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$jobs = ItemToFetchJobs::JOBS;
|
||||||
|
$jobs[] = "Details";
|
||||||
|
|
||||||
|
ItemToFetchJobs::create([
|
||||||
|
'tmdb_id' => $tmdbId,
|
||||||
|
'type' => ItemToFetch::TYPE_MOVIE,
|
||||||
|
'remaining_jobs' => json_encode($jobs),
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $itemToFetch;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,12 +15,12 @@ return new class extends Migration
|
|||||||
$table->id();
|
$table->id();
|
||||||
$table->integer('entity_id');
|
$table->integer('entity_id');
|
||||||
$table->string('entity_type');
|
$table->string('entity_type');
|
||||||
$table->integer('tmdb_id');
|
$table->integer('tmdb_id')->nullable();
|
||||||
$table->string('imdb_id');
|
$table->string('imdb_id')->nullable();
|
||||||
$table->string('wikidata_id');
|
$table->string('wikidata_id')->nullable();
|
||||||
$table->string('facebook_id');
|
$table->string('facebook_id')->nullable();
|
||||||
$table->string('instagram_id');
|
$table->string('instagram_id')->nullable();
|
||||||
$table->string('twitter_id');
|
$table->string('twitter_id')->nullable();
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user