some improvements
This commit is contained in:
@@ -48,22 +48,11 @@ class MovieProcessingService implements ProcessingInterface
|
||||
|
||||
public static function getBatch(int $batch, string $job)
|
||||
{
|
||||
if ($job === ItemToFetchJobs::JOB_DETAILS) {
|
||||
return ItemToFetchJobs::leftJoin('movies', function ($join) {
|
||||
$join->on('movies.tmdb_id', '=', 'item_to_fetch_jobs.tmdb_id');
|
||||
})
|
||||
->whereRaw("FIND_IN_SET('".ItemToFetchJobs::JOB_DETAILS."', item_to_fetch_jobs.jobs)")
|
||||
->whereIn('item_to_fetch_jobs.type', ['movies', 'movie'])
|
||||
->whereNull('movies.id')
|
||||
->take($batch)
|
||||
->get();
|
||||
}
|
||||
|
||||
return ItemToFetchJobs::leftJoin('movies', function ($join) {
|
||||
$join->on('movies.tmdb_id', '=', 'item_to_fetch_jobs.tmdb_id');
|
||||
})
|
||||
->whereRaw("FIND_IN_SET('".$job."', item_to_fetch_jobs.jobs)")
|
||||
->where('item_to_fetch_jobs.type', 'tv_series')
|
||||
->where('item_to_fetch_jobs.type', 'movie')
|
||||
->whereNotNull('movies.id')
|
||||
->take($batch)
|
||||
->get();
|
||||
@@ -77,50 +66,57 @@ class MovieProcessingService implements ProcessingInterface
|
||||
// @todo maybe raise an exception here
|
||||
return;
|
||||
}
|
||||
echo "Processing {$methodName} ".$item->tmdb_id."\n";
|
||||
echo "Processing {$methodName} ".$item->tmdb_id." (".$item->id.") \n";
|
||||
$this->$methodName($item);
|
||||
|
||||
// maybe we should sleep for a while so we do not spam the tmdb api
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
private function getDetails($item)
|
||||
{
|
||||
$tmdbMovie = $this->moviesApi->getMovie($item->tmdb_id);
|
||||
|
||||
if (isset($tmdbMovie['status_code']) && $tmdbMovie['status_code'] == 34) {
|
||||
echo "[N]";
|
||||
echo "[ApiError-Could not be found]\n]";
|
||||
return;
|
||||
}
|
||||
|
||||
$tmdbMovie['tmdb_id'] = $tmdbMovie['id'];
|
||||
|
||||
Log::channel('fetch_export_items_details')->info("Processing TmdbId ".$tmdbMovie['tmdb_id']);
|
||||
|
||||
$movie = Movie::where('tmdb_id', $tmdbMovie['tmdb_id'])->first();
|
||||
|
||||
if($movie) {
|
||||
return;
|
||||
}
|
||||
|
||||
$tmdbMovie['slug'] = Str::slug($tmdbMovie['title'].'-'.$tmdbMovie['tmdb_id']);
|
||||
$tmdbMovie['release_date'] = $tmdbMovie['release_date'] ? new \DateTime($tmdbMovie['release_date']) : null;
|
||||
|
||||
$movieId = Movie::create($tmdbMovie);
|
||||
$movie = Movie::where('tmdb_id', $tmdbMovie['tmdb_id'])->first();
|
||||
|
||||
if(!$movie) {
|
||||
$movie = Movie::create($tmdbMovie);
|
||||
}
|
||||
|
||||
$movieId = $movie->id;
|
||||
|
||||
// $movieId = Movie::create($tmdbMovie);
|
||||
|
||||
if (!empty($tmdbMovie['belongs_to_collection'])) {
|
||||
Log::channel('fetch_export_items_details')->info("Processing collections for ".$tmdbMovie['tmdb_id']);
|
||||
$this->processMovieCollection($movieId->id, $tmdbMovie['belongs_to_collection']);
|
||||
$this->processMovieCollection($movieId, $tmdbMovie['belongs_to_collection']);
|
||||
}
|
||||
|
||||
if (!empty($tmdbMovie['genres'])) {
|
||||
Log::channel('fetch_export_items_details')->info("Processing genres for ".$tmdbMovie['tmdb_id']);
|
||||
$this->processMovieGenres($movieId->id, $tmdbMovie['genres']);
|
||||
$this->processMovieGenres($movieId, $tmdbMovie['genres']);
|
||||
}
|
||||
|
||||
if (!empty($tmdbMovie['production_companies'])) {
|
||||
Log::channel('fetch_export_items_details')->info("Processing production companies ".$tmdbMovie['tmdb_id']);
|
||||
$this->processProductionCompanies($movieId->id, $tmdbMovie['production_companies']);
|
||||
$this->processProductionCompanies($movieId, $tmdbMovie['production_companies']);
|
||||
}
|
||||
|
||||
if (!empty($tmdbMovie['production_countries'])) {
|
||||
Log::channel('fetch_export_items_details')->info("Processing production countries ".$tmdbMovie['tmdb_id']);
|
||||
$this->processProductionCountries($movieId->id, $tmdbMovie['production_countries']);
|
||||
$this->processProductionCountries($movieId, $tmdbMovie['production_countries']);
|
||||
}
|
||||
|
||||
$this->removeElementFromRemainingJobs($tmdbMovie['id'], 'Details');
|
||||
@@ -331,6 +327,7 @@ class MovieProcessingService implements ProcessingInterface
|
||||
$tmdbMovieReviews = $this->moviesApi->getReviews($item->tmdb_id);
|
||||
|
||||
if (empty($tmdbMovieReviews) || !isset($tmdbMovieReviews['results'])){
|
||||
echo "Nope";
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -346,6 +343,7 @@ class MovieProcessingService implements ProcessingInterface
|
||||
$user = User::where('name', $tmdbReview['author'])->first();
|
||||
|
||||
if (!$user) {
|
||||
echo "Create user ".$tmdbReview['author'];
|
||||
$user = User::create([
|
||||
'name' => $tmdbReview['author'],
|
||||
'slug' => Str::slug($tmdbReview['author']),
|
||||
@@ -357,6 +355,7 @@ class MovieProcessingService implements ProcessingInterface
|
||||
|
||||
|
||||
if (!$existingReview) {
|
||||
echo "Create comment by user ".$tmdbReview['author']." on movie ".$movie->title;
|
||||
Comment::create([
|
||||
'entity_id' => $movie->id,
|
||||
'entity_type' => Comment::TYPE_MOVIE,
|
||||
@@ -678,7 +677,7 @@ class MovieProcessingService implements ProcessingInterface
|
||||
->first();
|
||||
|
||||
if (!$similarLink) {
|
||||
MovieRecommendation::create([
|
||||
MovieSimilar::create([
|
||||
'movie_id' => $initialMovie->id,
|
||||
'similar_movie_id' => $similarMovie->id,
|
||||
]);
|
||||
@@ -719,6 +718,8 @@ class MovieProcessingService implements ProcessingInterface
|
||||
|
||||
private function processMovieCollection(int $movieId, $belongsToCollection)
|
||||
{
|
||||
dd($belongsToCollection);
|
||||
|
||||
$movieCollection = MovieCollection::where('tmdb_id', $belongsToCollection['id'])->first();
|
||||
|
||||
if (!$movieCollection) {
|
||||
@@ -784,6 +785,7 @@ class MovieProcessingService implements ProcessingInterface
|
||||
if (is_string($remainingJobs)) {
|
||||
$remainingJobs = explode(',', $remainingJobs);
|
||||
} else {
|
||||
dd($remainingJobs);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user