[#1] lists
This commit is contained in:
@@ -6,16 +6,21 @@ use App\Models\Comment;
|
||||
use App\Models\ExternalId;
|
||||
use App\Models\Genre;
|
||||
use App\Models\Image;
|
||||
use App\Models\ItemToFetch;
|
||||
use App\Models\ItemToFetchJobs;
|
||||
use App\Models\Keyword;
|
||||
use App\Models\MediaList;
|
||||
use App\Models\MediaListItem;
|
||||
use App\Models\Movie;
|
||||
use App\Models\MovieAlternativeTitle;
|
||||
use App\Models\MovieCollection;
|
||||
use App\Models\Person;
|
||||
use App\Models\ReleaseDate;
|
||||
use App\Models\Translation;
|
||||
use App\Models\User;
|
||||
use App\Models\Video;
|
||||
use App\Models\WatchProvider;
|
||||
use App\Service\TMDBApi\ListApi;
|
||||
use App\Service\TMDBApi\MoviesApi;
|
||||
use App\Service\TMDBApi\PersonApi;
|
||||
use Illuminate\Support\Str;
|
||||
@@ -24,13 +29,16 @@ class MovieProcessingService implements ProcessingInterface
|
||||
{
|
||||
private MoviesApi $moviesApi;
|
||||
private PersonApi $personApi;
|
||||
private ListApi $listApi;
|
||||
|
||||
public function __construct(
|
||||
MoviesApi $moviesApi,
|
||||
PersonApi $personApi
|
||||
PersonApi $personApi,
|
||||
ListApi $listApi
|
||||
) {
|
||||
$this->moviesApi = $moviesApi;
|
||||
$this->personApi = $personApi;
|
||||
$this->listApi = $listApi;
|
||||
}
|
||||
|
||||
public function process($item, $job)
|
||||
@@ -409,6 +417,87 @@ class MovieProcessingService implements ProcessingInterface
|
||||
$this->removeElementFromRemainingJobs($item->tmdb_id, ItemToFetchJobs::JOB_VIDEOS);
|
||||
}
|
||||
|
||||
public function getLists($item)
|
||||
{
|
||||
$tmdbLists = $this->moviesApi->getLists($item->tmdb_id);
|
||||
|
||||
if (empty($tmdbLists) || empty($tmdbLists['results'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($tmdbLists['results'] as $tmdbList) {
|
||||
$list = MediaList::where('tmdb_id', $tmdbList['id'])->first();
|
||||
$tmdbList['tmdb_id'] = $tmdbList['id'];
|
||||
unset($tmdbList['id']);
|
||||
|
||||
if (!$list) {
|
||||
$list = MediaList::create($tmdbList);
|
||||
}
|
||||
|
||||
$listDetails = $this->listApi->details($tmdbList['tmdb_id']);
|
||||
|
||||
if (empty($listDetails)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$user = User::where('name', $listDetails['created_by'])->first();
|
||||
|
||||
if (!$user) {
|
||||
$user = User::create([
|
||||
'name' => $listDetails['created_by'],
|
||||
'slug' => Str::slug($listDetails['created_by']),
|
||||
'email' => $listDetails['created_by'].'@nowhere.wtf',
|
||||
'password' => 'no_password_neeeded_here',
|
||||
'is_dummy_account' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
if (!$user->whereHas('mediaLists', function ($query) use ($list) {
|
||||
$query->where('media_list_id', $list->id);
|
||||
})->exists()) {
|
||||
$user->mediaLists()->attach($list);
|
||||
}
|
||||
|
||||
foreach ($tmdbList['items'] as $tmdbListItem) {
|
||||
$mediaListItem = MediaListItem::where('media_list_id', $list->id)
|
||||
->where('tmdb_id', $tmdbListItem['id'])
|
||||
->first();
|
||||
|
||||
if (!$mediaListItem) {
|
||||
$movie = Movie::where('tmdb_id', $item->tmdb_id)->first();
|
||||
|
||||
if (!$movie) {
|
||||
$itemToFetch = ItemToFetch::where('tmdb_id', $item->tmdb_id)->first();
|
||||
|
||||
if (!$itemToFetch) {
|
||||
$itemToFetch = ItemToFetch::create([
|
||||
'tmdb_id' => $item->tmdb_id,
|
||||
'type' => ItemToFetch::TYPE_MOVIE,
|
||||
]);
|
||||
|
||||
$jobs = ItemToFetchJobs::JOBS;
|
||||
$jobs[] = "Details";
|
||||
|
||||
ItemToFetchJobs::create([
|
||||
'tmdb_id' => $item->tmdb_id,
|
||||
'type' => ItemToFetch::TYPE_MOVIE,
|
||||
'remaining_jobs' => json_encode($jobs),
|
||||
]);
|
||||
}
|
||||
|
||||
MediaListItem::create([
|
||||
'media_list_id' => $list->id,
|
||||
'item_type' => ItemToFetch::TYPE_MOVIE,
|
||||
'tmdb_id' => $item->tmdb_id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->removeElementFromRemainingJobs($item->tmdb_id, ItemToFetchJobs::JOB_LISTS);
|
||||
}
|
||||
|
||||
private function processMovieCollection(int $movieId, $belongsToCollection)
|
||||
{
|
||||
$movieCollection = MovieCollection::where('tmdb_id', $belongsToCollection['id'])->first();
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service\TMDBApi;
|
||||
|
||||
class ListApi extends AbstractApiService
|
||||
{
|
||||
public function details($listId)
|
||||
{
|
||||
sleep(1);
|
||||
return $this->get("list/" . $listId);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user