diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 7cbc2c3..01ee665 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -6,21 +6,10 @@ use Illuminate\Http\Request; class HomeController extends Controller { - /** - * Create a new controller instance. - * - * @return void - */ public function __construct() { - $this->middleware('auth'); } - /** - * Show the application dashboard. - * - * @return \Illuminate\Contracts\Support\Renderable - */ public function index() { return view('home'); diff --git a/app/Livewire/Homepage/Movies/LatestTrailersComponent.php b/app/Livewire/Homepage/Movies/LatestTrailersComponent.php new file mode 100644 index 0000000..3d08a36 --- /dev/null +++ b/app/Livewire/Homepage/Movies/LatestTrailersComponent.php @@ -0,0 +1,13 @@ +belongsToMany(WatchProvider::class, 'movie_watch_providers', 'movie_id', 'watch_provider_id'); } + + public function videos() + { + return $this->belongsToMany(Video::class, 'movie_videos', 'movie_id', 'video_id'); + } } diff --git a/app/Models/Video.php b/app/Models/Video.php new file mode 100644 index 0000000..14d651b --- /dev/null +++ b/app/Models/Video.php @@ -0,0 +1,21 @@ +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'], diff --git a/composer.json b/composer.json index 8c319a9..6213af0 100644 --- a/composer.json +++ b/composer.json @@ -10,10 +10,11 @@ "license": "MIT", "require": { "php": "^8.2", + "ext-zlib": "*", "laravel/framework": "^11.31", "laravel/tinker": "^2.9", "laravel/ui": "^4.6", - "ext-zlib": "*" + "livewire/livewire": "^3.5" }, "require-dev": { "fakerphp/faker": "^1.23", diff --git a/composer.lock b/composer.lock index ddb3d8d..aae3df0 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f70b6bfc17538a9703666cf04bbb5ccf", + "content-hash": "4e7e2781a95eda3eb8e36b6b04f4625f", "packages": [ { "name": "brick/math", @@ -2069,6 +2069,82 @@ ], "time": "2024-12-08T08:18:47+00:00" }, + { + "name": "livewire/livewire", + "version": "v3.5.18", + "source": { + "type": "git", + "url": "https://github.com/livewire/livewire.git", + "reference": "62f0fa6b340a467c25baa590a567d9a134b357da" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/livewire/livewire/zipball/62f0fa6b340a467c25baa590a567d9a134b357da", + "reference": "62f0fa6b340a467c25baa590a567d9a134b357da", + "shasum": "" + }, + "require": { + "illuminate/database": "^10.0|^11.0", + "illuminate/routing": "^10.0|^11.0", + "illuminate/support": "^10.0|^11.0", + "illuminate/validation": "^10.0|^11.0", + "laravel/prompts": "^0.1.24|^0.2|^0.3", + "league/mime-type-detection": "^1.9", + "php": "^8.1", + "symfony/console": "^6.0|^7.0", + "symfony/http-kernel": "^6.2|^7.0" + }, + "require-dev": { + "calebporzio/sushi": "^2.1", + "laravel/framework": "^10.15.0|^11.0", + "mockery/mockery": "^1.3.1", + "orchestra/testbench": "^8.21.0|^9.0", + "orchestra/testbench-dusk": "^8.24|^9.1", + "phpunit/phpunit": "^10.4", + "psy/psysh": "^0.11.22|^0.12" + }, + "type": "library", + "extra": { + "laravel": { + "aliases": { + "Livewire": "Livewire\\Livewire" + }, + "providers": [ + "Livewire\\LivewireServiceProvider" + ] + } + }, + "autoload": { + "files": [ + "src/helpers.php" + ], + "psr-4": { + "Livewire\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Caleb Porzio", + "email": "calebporzio@gmail.com" + } + ], + "description": "A front-end framework for Laravel.", + "support": { + "issues": "https://github.com/livewire/livewire/issues", + "source": "https://github.com/livewire/livewire/tree/v3.5.18" + }, + "funding": [ + { + "url": "https://github.com/livewire", + "type": "github" + } + ], + "time": "2024-12-23T15:05:02+00:00" + }, { "name": "monolog/monolog", "version": "3.8.1", @@ -8141,7 +8217,8 @@ "prefer-stable": true, "prefer-lowest": false, "platform": { - "php": "^8.2" + "php": "^8.2", + "ext-zlib": "*" }, "platform-dev": {}, "plugin-api-version": "2.6.0" diff --git a/database/migrations/2024_12_30_150223_create_videos_table.php b/database/migrations/2024_12_30_150223_create_videos_table.php new file mode 100644 index 0000000..22114e1 --- /dev/null +++ b/database/migrations/2024_12_30_150223_create_videos_table.php @@ -0,0 +1,37 @@ +id(); + $table->string('iso_639', 5)->nullable(); + $table->string('iso_3166', 5)->nullable(); + $table->string('name', 500)->nullable(); + $table->string('key')->nullable(); + $table->string('site', 50)->nullable(); + $table->integer('size')->nullable(); + $table->string('type')->nullable(); + $table->boolean('official'); + $table->dateTime('published_at'); + $table->string('tmdb_id'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('videos'); + } +}; diff --git a/database/migrations/2024_12_30_162133_create_movie_videos_table.php b/database/migrations/2024_12_30_162133_create_movie_videos_table.php new file mode 100644 index 0000000..f367156 --- /dev/null +++ b/database/migrations/2024_12_30_162133_create_movie_videos_table.php @@ -0,0 +1,29 @@ +id(); + $table->unsignedBigInteger('movie_id'); + $table->unsignedBigInteger('video_id'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('movie_videos'); + } +}; diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php index 1f34466..fdf80fd 100644 --- a/resources/views/home.blade.php +++ b/resources/views/home.blade.php @@ -4,6 +4,9 @@