[#1] watch providers
This commit is contained in:
@@ -14,6 +14,7 @@ use App\Models\MovieCollection;
|
||||
use App\Models\Person;
|
||||
use App\Models\ReleaseDate;
|
||||
use App\Models\Translation;
|
||||
use App\Models\WatchProvider;
|
||||
use App\Service\TMDBApi\MoviesApi;
|
||||
use App\Service\TMDBApi\PersonApi;
|
||||
use Illuminate\Support\Str;
|
||||
@@ -324,6 +325,59 @@ class MovieProcessingService implements ProcessingInterface
|
||||
$this->removeElementFromRemainingJobs($item->tmdb_id, ItemToFetchJobs::JOB_EXTERNAL_IDS);
|
||||
}
|
||||
|
||||
private function getWatchProviders($item)
|
||||
{
|
||||
$tmdbWatchProviders = $this->moviesApi->getWatchProviders($item->tmdb_id);
|
||||
|
||||
if (empty($tmdbWatchProviders) || empty($tmdbWatchProviders['results'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$movie = Movie::where('tmdb_id', $item->tmdb_id)->first();
|
||||
|
||||
$types = [
|
||||
'flatrate',
|
||||
'rent',
|
||||
'buy',
|
||||
];
|
||||
|
||||
foreach ($tmdbWatchProviders['results'] as $locale => $tmdbWatchProvider) {
|
||||
foreach ($types as $type) {
|
||||
if (!isset($tmdbWatchProvider[$type])) {
|
||||
continue;
|
||||
}
|
||||
$providerInfo = $tmdbWatchProvider[$type];
|
||||
|
||||
$existingWatchProvider = WatchProvider::where('tmdb_provider_id', $providerInfo['provider_id'])->first();
|
||||
|
||||
if(!$existingWatchProvider) {
|
||||
$existingWatchProvider = WatchProvider::create([
|
||||
'type' => $type,
|
||||
'logo_path' => $providerInfo['logo_path'],
|
||||
'tmdb_provider_id' => $providerInfo['provider_id'],
|
||||
'provider_name' => $providerInfo['provider_name'],
|
||||
'display_priority' => $providerInfo['display_priority'],
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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'],
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private function processMovieCollection(int $movieId, $belongsToCollection)
|
||||
{
|
||||
$movieCollection = MovieCollection::where('tmdb_id', $belongsToCollection['id'])->first();
|
||||
|
||||
Reference in New Issue
Block a user