[#8] some fixes on movie processing

This commit is contained in:
2025-01-01 19:24:46 +02:00
parent 54f027a730
commit 70b6a7325a
3 changed files with 77 additions and 19 deletions
@@ -47,7 +47,15 @@ class FetchItemDataCommand extends Command
{
return ItemToFetch::has('jobs')
->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)
->take($batch)
@@ -312,6 +312,10 @@ class MovieProcessingService implements ProcessingInterface
$movie = Movie::where('tmdb_id', $item->tmdb_id)->first();
if (!$movie) {
return;
}
$externalId = ExternalId::where('entity_id', $movie->id)
->where('entity_type', ExternalId::TYPE_MOVIE)
->first();
@@ -321,6 +325,9 @@ class MovieProcessingService implements ProcessingInterface
$externalIds['movie_id'] = $movie->id;
unset($externalIds['id']);
$externalIds['entity_id'] = $movie->id;
$externalIds['entity_type'] = ExternalId::TYPE_MOVIE;
ExternalId::create($externalIds);
}
@@ -337,6 +344,12 @@ class MovieProcessingService implements ProcessingInterface
$movie = Movie::where('tmdb_id', $item->tmdb_id)->first();
if (!$movie) {
$itemToFetch = $this->createJob($item->tmdb_id);
$this->getDetails($itemToFetch);
return;
}
$types = [
'flatrate',
'rent',
@@ -349,6 +362,11 @@ class MovieProcessingService implements ProcessingInterface
continue;
}
$providerInfo = $tmdbWatchProvider[$type];
$providerInfo = reset($providerInfo);
if (!isset($providerInfo['provider_id'])) {
continue;
}
$existingWatchProvider = WatchProvider::where('tmdb_provider_id', $providerInfo['provider_id'])->first();
@@ -362,17 +380,14 @@ class MovieProcessingService implements ProcessingInterface
]);
}
}
if ($movie->whereHas('watchProviders', function ($query) use ($movie) {
$query->where('movie_id', $movie->id);
})->exists()) {
return;
} else {
$movie->watchProviders()->attach($existingWatchProvider, [
'locale' => $locale,
'tmdb_url' => $tmdbWatchProvider['link'],
]);
if (!$movie->whereHas('watchProviders', function ($query) use ($movie) {
$query->where('movie_id', $movie->id);
})->exists()) {
$movie->watchProviders()->attach($existingWatchProvider, [
'locale' => $locale,
'tmdb_url' => $tmdbWatchProvider['link'],
]);
}
}
}
@@ -402,7 +417,7 @@ class MovieProcessingService implements ProcessingInterface
'size' => $tmdbVideo['size'],
'type' => $tmdbVideo['type'],
'official' => $tmdbVideo['official'],
'published_at' => $tmdbVideo['published_at'],
'published_at' => $tmdbVideo['published_at'] ? new \DateTime($tmdbVideo['published_at']) : null,
'tmdb_id' => $tmdbVideo['id'],
]);
}
@@ -687,6 +702,11 @@ class MovieProcessingService implements ProcessingInterface
$itemToFetchJobs = ItemToFetchJobs::where('tmdb_id', $tmdbId)->first();
$remainingJobs = $itemToFetchJobs->remaining_jobs;
if (is_string($remainingJobs)) {
$remainingJobs = json_decode($remainingJobs, true);
}
$remainingJobKey = array_search($job, $remainingJobs);
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->integer('entity_id');
$table->string('entity_type');
$table->integer('tmdb_id');
$table->string('imdb_id');
$table->string('wikidata_id');
$table->string('facebook_id');
$table->string('instagram_id');
$table->string('twitter_id');
$table->integer('tmdb_id')->nullable();
$table->string('imdb_id')->nullable();
$table->string('wikidata_id')->nullable();
$table->string('facebook_id')->nullable();
$table->string('instagram_id')->nullable();
$table->string('twitter_id')->nullable();
$table->timestamps();
});
}