[#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
-11
View File
@@ -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');
@@ -0,0 +1,13 @@
<?php
namespace App\Livewire\Homepage\Movies;
use Livewire\Component;
class LatestTrailersComponent extends Component
{
public function render()
{
return view('livewire.homepage.movies.latest-trailers-component');
}
}
@@ -0,0 +1,13 @@
<?php
namespace App\Livewire\Homepage\Movies;
use Livewire\Component;
class NewMoviesComponent extends Component
{
public function render()
{
return view('livewire.homepage.movies.new-movies-component');
}
}
@@ -0,0 +1,13 @@
<?php
namespace App\Livewire\Homepage\Movies;
use Livewire\Component;
class UpcomingMoviesComponent extends Component
{
public function render()
{
return view('livewire.homepage.movies.upcoming-movies-component');
}
}
+5
View File
@@ -67,4 +67,9 @@ class Movie extends Model
{
return $this->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');
}
}
+21
View File
@@ -0,0 +1,21 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Video extends Model
{
protected $fillable = [
'iso_639',
'iso_3166',
'name',
'key',
'site',
'size',
'type',
'official',
'published_at',
'tmdb_id',
];
}
@@ -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'],