Skip to content

TMDB

Usage

To access TMDB data points, first ensure you have loaded the TMDB source through:

await phylm.load_source("tmdb")

Alternatively you can instantiate the TMDB source class directly through:

from phylm.sources import Tmdb

tmdb = Tmdb(raw_title="The Matrix", raw_year=1999)  # raw_year is optional
await tmdb.load_source()

Movie ID

If you know the TMDB movie ID you can instantiate the Phylm class with a tmdb_id property:

from phylm.sources import Tmdb

tmdb = Tmdb(raw_title="The Matrix", tmdb_id="609")

Then, when running load_source for tmdb, phylm will first perform a search based on the ID. If the ID is valid the result will be selected, if not then it will fall back to a title search.

Alternatively, you can pass it to load_source with "tmdb" as the first argument:

await phylm.load_source("tmdb", tmdb_id="609")

Or instantiate the TMDB source class with the ID:

from phylm.sources import Tmdb

tmdb = Tmdb(movie_id="0133093")

If instantiating the class directly you must supply at least one of movie_id or raw_title, otherwise a ValueError will be raised.

Note that TMDB doesn't provide any fuzzy search for title, only exact matches are returned.

Reference

Class to abstract a TMDB result.

id: Optional[str] property

Return the TMDB id.

Returns:

Type Description
Optional[str]

the id of the movie

imdb_id: Optional[str] property

Return the IMDb id.

Returns:

Type Description
Optional[str]

the IMDb id of the movie

plot: Optional[str] property

Return the plot.

Returns:

Type Description
Optional[str]

the plot of the movie

rating: Optional[float] property

Return the TMDB rating.

Returns:

Type Description
Optional[float]

the rating of the movie

release_date: Optional[str] property

Return the movie's release_date.

Returns:

Type Description
Optional[str]

the release date of the movie

runtime: Optional[int] property

Return the runtime.

Returns:

Type Description
Optional[int]

the runtime of the movie

title: Optional[str] property

Return the TMDB title.

Returns:

Type Description
Optional[str]

the title of the movie

year: Optional[int] property

Return the movie's year.

Returns:

Type Description
Optional[int]

the year the movie was made

__init__(raw_title: Optional[str] = None, movie_id: Optional[str] = None, raw_year: Optional[int] = None, api_key: Optional[str] = None, session: Optional[ClientSession] = None) -> None

Initialize the object.

Note that at least one of raw_title or movie_id must be given to be used as a search term. movie_id is preferred over raw_title.

Parameters:

Name Type Description Default
raw_title Optional[str]

the title of the movie. Note that TMDB doesn't support fuzzy search.

None
movie_id Optional[str]

the TMDB id of the movie.

None
raw_year Optional[int]

an optional year for improved matching if only title is given.

None
api_key Optional[str]

a TMDB api key. Must be supplied here or as an env var

None
session Optional[ClientSession]

a aiohttp.ClientSession instance. One will be created if not supplied.

None

Raises:

Type Description
ValueError

if neither raw_title nor movie_id is supplied.

genres(limit: int = 3) -> List[str]

Return the genres.

Parameters:

Name Type Description Default
limit int

an optional number of genres to return

3

Returns:

Type Description
List[str]

a list of the movie's genres

load_source(session: Optional[ClientSession] = None) -> None async

Asynchronously load the data for from the source.

Parameters:

Name Type Description Default
session Optional[ClientSession]

an optional aiohttp.ClientSession instance

None

Last update: 2023-10-18