[#1] processing videos and livewire

This commit is contained in:
2024-12-30 18:28:50 +02:00
parent c16b36a6da
commit 6abcbe2a84
18 changed files with 280 additions and 39 deletions
@@ -14,6 +14,7 @@ use App\Models\MovieCollection;
use App\Models\Person;
use App\Models\ReleaseDate;
use App\Models\Translation;
use App\Models\Video;
use App\Models\WatchProvider;
use App\Service\TMDBApi\MoviesApi;
use App\Service\TMDBApi\PersonApi;
@@ -143,10 +144,8 @@ class MovieProcessingService implements ProcessingInterface
$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);
}
}
@@ -178,10 +177,8 @@ class MovieProcessingService implements ProcessingInterface
if ($movie->whereHas('keywords', function ($query) use ($existingKeyword) {
$query->where('tmdb_id', $existingKeyword->tmdb_id);
})->exists()) {
echo "Movie has keyword | ";
return;
} else {
echo "Movie does not have keyword | ";
$movie->keywords()->attach($existingKeyword);
}
}
@@ -194,14 +191,11 @@ class MovieProcessingService implements ProcessingInterface
$tmdbReleases = $this->moviesApi->getReleases($item->tmdb_id);
if (empty($tmdbReleases) || !isset($tmdbReleases['countries'])) {
echo "[E] Movie ".$item->tmdb_id ." Releases ".json_encode($tmdbReleases)."\n\n";
return;
}
$movie = Movie::where('tmdb_id', $item->tmdb_id)->first();
echo "Movie ".$movie->id ." Releases ".json_encode($tmdbReleases)."\n\n";
foreach ($tmdbReleases['countries'] as $tmdbRelease) {
$existingReleaseDate = ReleaseDate::where('iso_3166', $tmdbRelease['iso_3166_1'])
->where('release_date', $tmdbRelease['release_date'])
@@ -221,10 +215,8 @@ class MovieProcessingService implements ProcessingInterface
if ($movie->whereHas('releaseDates', function ($query) use ($movie) {
$query->where('movie_id', $movie->id);
})->exists()) {
echo "Movie has release date | ";
return;
} else {
echo "Movie does not have release date | ";
$movie->releaseDates()->attach($existingReleaseDate);
}
}
@@ -365,17 +357,56 @@ class MovieProcessingService implements ProcessingInterface
if ($movie->whereHas('watchProviders', function ($query) use ($movie) {
$query->where('movie_id', $movie->id);
})->exists()) {
echo "Movie has watch provider | ";
return;
} else {
echo "Movie does not have watch provider | ";
$movie->watchProviders()->attach($existingWatchProvider, [
'locale' => $locale,
'tmdb_url' => $tmdbWatchProvider['link'],
]);
}
}
$this->removeElementFromRemainingJobs($item->tmdb_id, ItemToFetchJobs::JOB_WATCH_PROVIDERS);
}
private function getVideos($item)
{
$movie = Movie::where('tmdb_id', $item->tmdb_id)->first();
$tmdbVideos = $this->moviesApi->getVideos($item->tmdb_id);
if (empty($tmdbVideos) || empty($tmdbVideos['results'])) {
return;
}
foreach ($tmdbVideos['results'] as $tmdbVideo) {
$videoExists = Video::where('tmdb_id', $tmdbVideo['id'])->first();
if (!$videoExists) {
$videoExists = Video::create([
'iso_639' => $tmdbVideo['iso_639_1'],
'iso_3166' => $tmdbVideo['iso_3166_1'],
'name' => $tmdbVideo['name'],
'key' => $tmdbVideo['key'],
'site' => $tmdbVideo['site'],
'size' => $tmdbVideo['size'],
'type' => $tmdbVideo['type'],
'official' => $tmdbVideo['official'],
'published_at' => $tmdbVideo['published_at'],
'tmdb_id' => $tmdbVideo['id'],
]);
}
if ($movie->whereHas('videos', function ($query) use ($movie) {
$query->where('movie_id', $movie->id);
})->exists()) {
return;
} else {
$movie->videos()->attach($videoExists);
}
}
$this->removeElementFromRemainingJobs($item->tmdb_id, ItemToFetchJobs::JOB_VIDEOS);
}
private function processMovieCollection(int $movieId, $belongsToCollection)
@@ -397,10 +428,8 @@ class MovieProcessingService implements ProcessingInterface
if ($movie->whereHas('collections', function ($query) use ($movieCollection) {
$query->where('tmdb_id', '=', $movieCollection->tmdb_id);
})->exists()) {
echo "Movie is in the collection";
return;
} else {
echo "Movie is not in the collection";
$movie->collections()->attach($movieCollection);
}
@@ -427,10 +456,8 @@ class MovieProcessingService implements ProcessingInterface
if ($movie->whereHas('genres', function ($query) use ($genre) {
$query->where('tmdb_id', '=', $genre->tmdb_id);
})->exists()) {
echo "Movie is in the genre";
return;
} else {
echo "Movie is not in the genre";
$movie->genres()->attach($genre);
}
}
@@ -494,10 +521,8 @@ class MovieProcessingService implements ProcessingInterface
if ($movie->whereHas('castList', function ($query) use ($person) {
$query->where('tmdb_id', '=', $person->tmdb_id);
})->exists()) {
echo "Person is in cast | ";
return;
} else {
echo "Person is not in cast |";
$movie->castList()->attach($person, [
'known_for_department' => $castPerson['known_for_department'],
'character' => $castPerson['character'],
@@ -549,10 +574,8 @@ class MovieProcessingService implements ProcessingInterface
if ($movie->whereHas('crewList', function ($query) use ($person) {
$query->where('tmdb_id', '=', $person->tmdb_id);
})->exists()) {
echo "Person is in crew | ";
return;
} else {
echo "Person is not in crew |";
$movie->castList()->attach($person, [
'known_for_department' => json_encode($crewPerson['known_for_department']),
'job' => $crewPerson['job'],