[#1] lists
This commit is contained in:
@@ -7,6 +7,7 @@ use App\Models\User;
|
||||
use Illuminate\Foundation\Auth\RegistersUsers;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class RegisterController extends Controller
|
||||
{
|
||||
@@ -65,6 +66,7 @@ class RegisterController extends Controller
|
||||
{
|
||||
return User::create([
|
||||
'name' => $data['name'],
|
||||
'slug' => Str::slug($data['name']),
|
||||
'email' => $data['email'],
|
||||
'password' => Hash::make($data['password']),
|
||||
]);
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class MediaList extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'description',
|
||||
'favorites_count',
|
||||
'tmdb_id',
|
||||
'item_count',
|
||||
'iso_639_1',
|
||||
'iso_3166_1',
|
||||
'list_type',
|
||||
'name',
|
||||
'poster_path',
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class MediaListItem extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'media_list_id',
|
||||
'item_id',
|
||||
'item_type',
|
||||
'tmdb_id',
|
||||
];
|
||||
}
|
||||
@@ -19,8 +19,10 @@ class User extends Authenticatable
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'slug',
|
||||
'email',
|
||||
'password',
|
||||
'is_dummy_account',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -45,4 +47,9 @@ class User extends Authenticatable
|
||||
'password' => 'hashed',
|
||||
];
|
||||
}
|
||||
|
||||
public function mediaLists()
|
||||
{
|
||||
return $this->belongsToMany(MediaList::class, 'user_media_lists', 'user_id', 'media_list_id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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