[#1] watch providers
This commit is contained in:
@@ -62,4 +62,9 @@ class Movie extends Model
|
|||||||
{
|
{
|
||||||
return $this->belongsToMany(ReleaseDate::class, 'movie_release_dates', 'movie_id', 'release_date_id');
|
return $this->belongsToMany(ReleaseDate::class, 'movie_release_dates', 'movie_id', 'release_date_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function watchProviders()
|
||||||
|
{
|
||||||
|
return $this->belongsToMany(WatchProvider::class, 'movie_watch_providers', 'movie_id', 'watch_provider_id');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class WatchProvider extends Model
|
||||||
|
{
|
||||||
|
protected $fillable = [
|
||||||
|
'type',
|
||||||
|
'logo_path',
|
||||||
|
'tmdb_provider_id',
|
||||||
|
'provider_name',
|
||||||
|
'display_priority',
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -14,6 +14,7 @@ use App\Models\MovieCollection;
|
|||||||
use App\Models\Person;
|
use App\Models\Person;
|
||||||
use App\Models\ReleaseDate;
|
use App\Models\ReleaseDate;
|
||||||
use App\Models\Translation;
|
use App\Models\Translation;
|
||||||
|
use App\Models\WatchProvider;
|
||||||
use App\Service\TMDBApi\MoviesApi;
|
use App\Service\TMDBApi\MoviesApi;
|
||||||
use App\Service\TMDBApi\PersonApi;
|
use App\Service\TMDBApi\PersonApi;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
@@ -324,6 +325,59 @@ class MovieProcessingService implements ProcessingInterface
|
|||||||
$this->removeElementFromRemainingJobs($item->tmdb_id, ItemToFetchJobs::JOB_EXTERNAL_IDS);
|
$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)
|
private function processMovieCollection(int $movieId, $belongsToCollection)
|
||||||
{
|
{
|
||||||
$movieCollection = MovieCollection::where('tmdb_id', $belongsToCollection['id'])->first();
|
$movieCollection = MovieCollection::where('tmdb_id', $belongsToCollection['id'])->first();
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('watch_providers', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->string('type');
|
||||||
|
$table->string('logo_path');
|
||||||
|
$table->integer('tmdb_provider_id');
|
||||||
|
$table->string('provider_name');
|
||||||
|
$table->integer('display_priority');
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('watch_providers');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('movie_watch_providers', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->unsignedBigInteger('movie_id');
|
||||||
|
$table->integer('watch_provider_id');
|
||||||
|
$table->string('locale');
|
||||||
|
$table->string('tmdb_url');
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('movie_watch_providers');
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user