This commit is contained in:
2025-10-09 00:22:54 +03:00
parent 7e0e330ef6
commit b8b39c945d
28 changed files with 2186 additions and 452 deletions
@@ -69,6 +69,7 @@ class FetchItemDataCommand extends Command
$bar = $this->output->createProgressBar(count($items));
foreach ($items as $item) {
echo "Processing ".$item->tmdb_id."\n";
$this->processItem($item, $job, $type);
$bar->advance();
}
@@ -0,0 +1,128 @@
<?php
namespace App\Console\Commands\TmdbFetch;
use App\Models\ItemToFetch;
use App\Models\ItemToFetchJobs;
use App\Service\TMDBApi\MoviesApi;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class DiscoverMoviesCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'tmdb:discover-movies {--page=1} {--limit=5}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Discover movies from TMDB API and add them to the fetch queue';
private MoviesApi $moviesApi;
public function __construct(MoviesApi $moviesApi)
{
$this->moviesApi = $moviesApi;
parent::__construct();
}
/**
* Execute the console command.
*/
public function handle()
{
$page = $this->option('page');
$limit = $this->option('limit');
$this->info("Discovering movies from TMDB API (page: {$page}, limit: {$limit})");
$totalPages = 0;
$processedCount = 0;
try {
for ($currentPage = $page; $currentPage < $page + $limit; $currentPage++) {
$this->info("Processing page {$currentPage}");
$discoverResult = $this->moviesApi->discover([
'page' => $currentPage,
'sort_by' => 'popularity.desc',
'include_adult' => false,
'include_video' => false,
]);
if (empty($discoverResult) || empty($discoverResult['results'])) {
$this->error("No results found on page {$currentPage}");
break;
}
$totalPages = $discoverResult['total_pages'];
if ($currentPage > $totalPages) {
$this->info("Reached the end of results (total pages: {$totalPages})");
break;
}
DB::beginTransaction();
foreach ($discoverResult['results'] as $movie) {
$this->processMovie($movie);
$processedCount++;
}
DB::commit();
// Sleep to avoid rate limiting
sleep(1);
}
$this->info("Successfully processed {$processedCount} movies");
} catch (\Throwable $e) {
DB::rollBack();
$this->error("Error processing movies: " . $e->getMessage());
$this->error($e->getTraceAsString());
}
}
private function processMovie(array $movie)
{
$tmdbId = $movie['id'];
// Check if this movie is already in the queue
$existingJob = ItemToFetchJobs::where('tmdb_id', $tmdbId)
->where('type', 'movie')
->first();
if ($existingJob) {
$this->line("Movie ID {$tmdbId} already in queue, skipping");
return;
}
// Create ItemToFetch record if it doesn't exist
$itemToFetch = ItemToFetch::firstOrCreate(
[
'tmdb_id' => $tmdbId,
'type' => ItemToFetch::TYPE_MOVIE,
]
);
// Prepare jobs list
$jobs = ItemToFetchJobs::MOVIE_JOBS;
$jobs[] = ItemToFetchJobs::JOB_DETAILS;
// Create ItemToFetchJobs record
ItemToFetchJobs::create([
'tmdb_id' => $tmdbId,
'type' => ItemToFetch::TYPE_MOVIE,
'jobs' => implode(',', $jobs),
]);
$this->line("Added movie ID {$tmdbId} to fetch queue");
}
}
@@ -0,0 +1,127 @@
<?php
namespace App\Console\Commands\TmdbFetch;
use App\Models\ItemToFetch;
use App\Models\ItemToFetchJobs;
use App\Service\TMDBApi\ShowsApi;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class DiscoverTvSeriesCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'tmdb:discover-tv-series {--page=1} {--limit=5}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Discover TV series from TMDB API and add them to the fetch queue';
private ShowsApi $showsApi;
public function __construct(ShowsApi $showsApi)
{
$this->showsApi = $showsApi;
parent::__construct();
}
/**
* Execute the console command.
*/
public function handle()
{
$page = $this->option('page');
$limit = $this->option('limit');
$this->info("Discovering TV series from TMDB API (page: {$page}, limit: {$limit})");
$totalPages = 0;
$processedCount = 0;
try {
for ($currentPage = $page; $currentPage < $page + $limit; $currentPage++) {
$this->info("Processing page {$currentPage}");
$discoverResult = $this->showsApi->discover([
'page' => $currentPage,
'sort_by' => 'popularity.desc',
'include_adult' => false,
]);
if (empty($discoverResult) || empty($discoverResult['results'])) {
$this->error("No results found on page {$currentPage}");
break;
}
$totalPages = $discoverResult['total_pages'];
if ($currentPage > $totalPages) {
$this->info("Reached the end of results (total pages: {$totalPages})");
break;
}
DB::beginTransaction();
foreach ($discoverResult['results'] as $show) {
$this->processShow($show);
$processedCount++;
}
DB::commit();
// Sleep to avoid rate limiting
sleep(1);
}
$this->info("Successfully processed {$processedCount} TV series");
} catch (\Throwable $e) {
DB::rollBack();
$this->error("Error processing TV series: " . $e->getMessage());
$this->error($e->getTraceAsString());
}
}
private function processShow(array $show)
{
$tmdbId = $show['id'];
// Check if this show is already in the queue
$existingJob = ItemToFetchJobs::where('tmdb_id', $tmdbId)
->where('type', ItemToFetch::TYPE_TV_SERIES)
->first();
if ($existingJob) {
$this->line("TV series ID {$tmdbId} already in queue, skipping");
return;
}
// Create ItemToFetch record if it doesn't exist
$itemToFetch = ItemToFetch::firstOrCreate(
[
'tmdb_id' => $tmdbId,
'type' => ItemToFetch::TYPE_TV_SERIES,
]
);
// Prepare jobs list
$jobs = ItemToFetchJobs::SHOW_JOBS;
$jobs[] = ItemToFetchJobs::JOB_DETAILS;
// Create ItemToFetchJobs record
ItemToFetchJobs::create([
'tmdb_id' => $tmdbId,
'type' => ItemToFetch::TYPE_TV_SERIES,
'jobs' => implode(',', $jobs),
]);
$this->line("Added TV series ID {$tmdbId} to fetch queue");
}
}
+1 -1
View File
@@ -34,7 +34,7 @@ class MediaListController extends Controller
return view('profile.lists.show', compact('list', 'items', 'user'));
}
public function create()
public function create(string $userSlug)
{
$user = Auth::user();
+10 -1
View File
@@ -4,8 +4,10 @@ namespace App\Http\Controllers;
use App\Http\Requests\Movie\CommentRequest;
use App\Models\Comment;
use App\Models\MediaList;
use App\Models\Movie;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class MovieController extends Controller
{
@@ -26,7 +28,14 @@ class MovieController extends Controller
->where('entity_type', Comment::TYPE_MOVIE)
->paginate(15);
return view('movie.show', compact('movie', 'comments'));
$userLists = [];
if (Auth::check()) {
$userLists = MediaList::whereNotIn('name', MediaList::SPECIAL_LISTS)
->where('user_id', Auth::user()->id)
->get();
}
return view('movie.show', compact('movie', 'comments', 'userLists'));
}
public function storeComment(CommentRequest $request, string $movieSlug)
+54
View File
@@ -0,0 +1,54 @@
<?php
namespace App\Http\Controllers;
use App\Models\Movie;
use App\Models\Person;
use App\Models\Show;
use Illuminate\Http\Request;
class SearchController extends Controller
{
public function index(Request $request)
{
$query = $request->input('query');
$type = $request->input('type', 'all');
$movies = collect([]);
$shows = collect([]);
$people = collect([]);
if ($query) {
// Search for movies if type is 'all' or 'movie'
if ($type === 'all' || $type === 'movie') {
$movies = Movie::where('title', 'like', "%{$query}%")
->orWhere('overview', 'like', "%{$query}%")
->limit(20)
->get();
}
// Search for TV shows if type is 'all' or 'tv'
if ($type === 'all' || $type === 'tv') {
$shows = Show::where('name', 'like', "%{$query}%")
->orWhere('overview', 'like', "%{$query}%")
->limit(20)
->get();
}
// Search for people if type is 'all' or 'person'
if ($type === 'all' || $type === 'person') {
$people = Person::where('name', 'like', "%{$query}%")
->limit(20)
->get();
}
}
return view('search.results', [
'query' => $query,
'type' => $type,
'movies' => $movies,
'shows' => $shows,
'people' => $people,
]);
}
}
+13
View File
@@ -297,4 +297,17 @@ class MoviesApi extends AbstractApiService
sleep(1);
return $this->get('movie/' . $movieId . '/external_ids', $parameters, $headers);
}
/**
* Discover movies based on filters.
*
* @param array $parameters
* @param array $headers
* @return mixed
*/
public function discover(array $parameters = [], array $headers = [])
{
sleep(1);
return $this->get('discover/movie', $parameters, $headers);
}
}
+12
View File
@@ -296,4 +296,16 @@ class ShowsApi extends AbstractApiService
{
return $this->get('tv/' . $seriesTmdbId . '/season/'.$seasonNumber);
}
/**
* Discover TV shows based on filters.
*
* @param array $parameters
* @param array $headers
* @return mixed
*/
public function discover(array $parameters = [], array $headers = [])
{
sleep(1);
return $this->get('discover/tv', $parameters, $headers);
}
}