1. Go to this page and download the library: Download resoul/imdb library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
public function getTitle(): string
public function getReleases(): array // Returns Release[]
public function getRank(): int
public function getLastWeek(): int
public function getRelease(): string
public function getUri(): string
public function getGross(): int
public function getTheaters(): int
public function getTotal(): int
public function getWeeks(): int
public function getFilm(): Film
public function setFilm(Film $film): void
public function getUID(): string
public function getRelease(): string
public function getOriginal(): string
public function getPoster(): string
public function getDescription(): string
public function getReleaseDate(): string
public function getDuration(): string
public function getCertificate(): string
public function getBudget(): ?int
public function getOpening(): ?int
public function getOpeningTheaters(): ?int
public function getWideRelease(): ?int
public function getSeasons(): int
public function getReleaseSummary(): ?string
public function getCast(): ?array // Returns Actor[]
public function getGross(): Gross
public function getType(): FilmTypeEnum
public function getDistributor(): ?DistributorEnum
public function getGenres(): array // Returns GenreEnum[]
public function getDomestic(): ?int
public function getInternational(): ?int
public function getWorldwide(): ?int
public function getOriginal(): string
public function getUri(): string
public function getRole(): RoleEnum
public function getRoleName(): ?string
public function getPoster(): ?string
use resoul\imdb\Parser;
use resoul\imdb\model\enum\FilmTypeEnum;
class BoxOfficeAnalyzer {
private Parser $parser;
public function __construct(string $cacheDir) {
$this->parser = new Parser();
$this->parser->setCacheFolder($cacheDir);
}
public function getTopMoviesOnly(string $weekend): array {
try {
$data = $this->parser->byWeekend($weekend)->run();
$movies = [];
foreach ($data->getReleases() as $release) {
$film = $release->getFilm();
// Filter only movies (exclude TV series)
if ($film->getType() === FilmTypeEnum::MOVIE) {
$movies[] = [
'rank' => $release->getRank(),
'title' => $film->getOriginal(),
'gross' => $release->getGross(),
'theaters' => $release->getTheaters(),
'poster' => $film->getPoster(),
'description' => $film->getDescription(),
];
}
}
return $movies;
} catch (Exception $e) {
error_log("Failed to parse weekend data: " . $e->getMessage());
return [];
}
}
public function calculateMetrics(array $movies): array {
if (empty($movies)) {
return ['error' => 'No data available'];
}
$totalGross = array_sum(array_column($movies, 'gross'));
$totalTheaters = array_sum(array_column($movies, 'theaters'));
$avgPerTheater = $totalTheaters > 0 ? $totalGross / $totalTheaters : 0;
return [
'total_gross' => $totalGross,
'total_theaters' => $totalTheaters,
'average_per_theater' => $avgPerTheater,
'movie_count' => count($movies),
];
}
}
// Usage
$analyzer = new BoxOfficeAnalyzer('./cache/');
$movies = $analyzer->getTopMoviesOnly('2024W48');
$metrics = $analyzer->calculateMetrics($movies);
echo "Weekend Box Office Metrics:\n";
echo "Total Gross: $" . number_format($metrics['total_gross']) . "\n";
echo "Average per Theater: $" . number_format($metrics['average_per_theater']) . "\n";
try {
$data = $parser->byWeekend('2024W48')->run();
// Always check if releases exist
if (empty($data->getReleases())) {
echo "No box office data found for this period.\n";
return;
}
foreach ($data->getReleases() as $release) {
// Check if film data was successfully parsed
try {
$film = $release->getFilm();
// Process film data...
} catch (Exception $e) {
echo "Failed to get film details for: " . $release->getRelease() . "\n";
continue;
}
}
} catch (Exception $e) {
// Log error for debugging
error_log("Parser error: " . $e->getMessage());
// Provide user-friendly message
echo "Unable to retrieve box office data. Please try again later.\n";
}
// Cache files are stored as: {cache_folder}/{parsed_url}.html
// Pro IMDB pages are prefixed: pro.{parsed_url}.html
$data = $parser->byYear('2024')->run();
$releases = $data->getReleases();
// Process in chunks of 10
foreach (array_chunk($releases, 10) as $batch) {
foreach ($batch as $release) {
// Process release...
}
// Optional: Clear memory between batches
if (function_exists('gc_collect_cycles')) {
gc_collect_cycles();
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.