Download the PHP package mfonte/imdb-scraper without Composer
On this page you can find all versions of the php package mfonte/imdb-scraper. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package imdb-scraper
Mfonte IMDb Scraper
A PHP library for scraping movie and TV show data from IMDb with ease. This package provides methods to retrieve detailed information about movies and TV shows using best matches or strict year-based queries, with support for localized searches.
[!CAUTION] This package is intended for educational and personal use only. Users are responsible for ensuring their use complies with IMDb's Terms of Service and applicable laws. The author does not condone or encourage unauthorized scraping or other activities that violate legal agreements. Please, refer to the IMDb Conditions of Use for more information. It is your responsibility to use this package in compliance with IMDb's Terms of Service.
List of supported locales
- English (
en-US
) viaen
- Italian (
it-IT
) viait
- Spanish (
es-ES
) viaes
- French (
fr-FR
) viafr
- German (
de-DE
) viade
- Portuguese (
pt-BR
) viapt
-
Indian (
hi-IN
) viahi
-
- -
Overview
Mfonte IMDb Scraper is a lightweight, object-oriented library to interact with IMDb. It provides functionalities to:
- Retrieve movie and TV show details by title and year, or IMDb ID, with robust exception handling, with support for multiple locales.
- Fetch data like plot, actors, genres, ratings, and similar titles.
- Narrow results using "best match" algorithms or strict filters.
Key features include:
- Localized searches using the
locale
option. - Built-in caching for optimized performance.
-
v2
tag works from PHP 8.1 onwards.v1
tag Works from PHP 7.3 onwards. -
- -
Installation
Release tag v1
is compatible with PHP versions 7.3
, 7.4
and 8.0
(monolog ^2.0
).
Install the package via Composer:
Release tag v2
is compatible with PHP versions 8.1
, 8.2
, 8.3
, 8.4
(monolog ^3.0
).
Install the package via Composer:
Usage
Basic Example
All methods return a Mfonte\ImdbScraper\Title
object with the following properties.
The Title
Object
The Title
object represents detailed information about a movie or TV show fetched using the ImdbScraper
library. It encapsulates all key attributes of a title, including metadata, cast, genres, and links to related content.
Properties of the Title
Object
Property | Type | Description |
---|---|---|
id |
string |
The unique IMDb ID of the title (e.g., "tt1234567" ). |
isTvSeries |
bool |
Indicates whether the title is a TV series (true ) or a movie (false ). |
link |
string |
The URL of the IMDb page for the title. |
title |
string |
The official title of the movie or TV show. |
originalTitle |
string |
The original title of the movie or TV show. |
year |
`int | null` | |
length |
`string | null` | |
rating |
`float | null` | |
ratingVotes |
`int | null` | |
popularityScore |
`int | null` | |
metaScore |
`int | null` | |
genres |
array |
A list of genres associated with the title (e.g., ["Action", "Drama"] ). |
posterUrl |
`string | null` | |
trailerUrl |
`string | null` | |
plot |
`string | null` | |
actors |
Dataset |
A dataset containing the cast members of the title. (Person objects) |
similars |
Dataset |
A dataset containing similar titles to the one fetched. (Title objects) |
seasonRefs |
array |
A list of season numbers for a TV series (e.g., [1, 2, 3, 4] ). |
seasons |
Dataset |
A dataset containing detailed information about seasons for a TV series. (Season objects) |
metadata |
array |
Raw metadata associated with the title. |
Options
The scraper provides various configuration options during initialization:
Option | Default | Description |
---|---|---|
cache |
false |
Enables caching of results. |
locale |
en |
Sets the locale for searches (e.g., it for Italian). |
seasons |
false |
If true , fetches season data for TV shows. |
guzzleLogFile |
null |
File path for logging HTTP requests (useful for debugging). |
Example: Setting Options
Methods
Best Match Overview
The movie()
and tvSeries()
methods find the best match for a given title. The library uses a Levenshtein algorithm to rank results and selects the closest match.
Example with movie()
By Year Overview
The movieByYear()
and tvSeriesByYear()
methods perform a strict search for titles matching the specified year. If no exact match is found, the library checks for movies released one year before or after the given year.
Example with movieByYear()
Handling Exceptions in movie()
, tvSeries()
, movieByYear()
, and tvSeriesByYear()
The methods movie()
, tvSeries()
, movieByYear()
, and tvSeriesByYear()
in the Imdb
class throw exceptions when specific conditions are not met during the search:
-
NoSearchResults
Exception:- Thrown when no results are found for the provided query.
- Example:
-
MultipleSearchResults
Exception:- Thrown when the query returns multiple results but the method cannot narrow them down to a single title.
- Example:
BadMethodCall
Exception:- Thrown when invalid input is provided to the
id()
method or other API methods. - Example:
- Thrown when invalid input is provided to the
The id()
Method
The id()
method allows you to fetch detailed information about a movie or TV show using its unique IMDb ID.
Key Features:
- Accepts only valid IMDb IDs in the format
tt1234567
. -
Throws a
BadMethodCall
exception if the input is invalid. -
- -
The search()
Method
The search()
method performs a general search query and returns a Dataset
containing SearchResult
objects for all matches.
Key Features:
- Returns a
Dataset
ofSearchResult
objects. -
Each
SearchResult
includes fields likeid
,title
,year
,type
, and more. -
- -
Summary of Exceptions and Methods
Method | Description | Exceptions Thrown |
---|---|---|
movie($title) |
Fetches the best match for a movie title. | NoSearchResults , MultipleSearchResults |
tvSeries($title) |
Fetches the best match for a TV series title. | NoSearchResults , MultipleSearchResults |
movieByYear($title, $year) |
Fetches a movie by title and year. | NoSearchResults , MultipleSearchResults |
tvSeriesByYear($title, $year) |
Fetches a TV series by title and year. | NoSearchResults , MultipleSearchResults |
id($imdbId) |
Fetches a movie or TV show by IMDb ID (e.g., tt1234567 ). |
BadMethodCall |
search($query) |
Performs a general search and returns a Dataset of SearchResult objects. |
- |
With these robust exception-handling mechanisms and versatile methods, the Imdb
class offers both flexibility and reliability for your IMDb scraping needs.
Advanced Features
Caching
Enable caching for faster repeated lookups. Cache works seamlessly and stores results locally.
Locale
Retrieve localized movie titles, plots, and other data by setting the locale
option.
Contributing
Contributions are welcome! Feel free to open an issue or submit a pull request.
License
This project is licensed under the MIT License. See the LICENSE file for details.
All versions of imdb-scraper with dependencies
paquettg/php-html-parser Version ^3.0
monolog/monolog Version ^3.8
voku/simple-cache Version ^4.1
voku/simple_html_dom Version ^4.8
voku/portable-utf8 Version ^6.0