You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This Python module implements the v3 API for TheMovieDb.org, allowing access
to movie and cast information, as well as related artwork. More information
can be found at:
Access to the API requires a personal key. You can create one by signing up
for an account on TheMovieDb.org, and generating one from your Account Details
page. Once done, the PyTMDB3 module must be be given this key as follows:
>>> from tmdb3 import set_key
>>> set_key('your_api_key')
Caching Engine
In order to limit excessive usage against the online API server, the PyTMDB3
module supports caching of requests. Cached data is keyed off the request URL,
and is currently stored for one hour. API requests are limited to thirty (30)
within ten (10) seconds. Requests beyond this limit are blocking until they
can be processed.
There are currently two engines available for use. The null engine merely
discards all information, and is only intended for debugging use. The file
engine is defualt, and will store to /tmp/pytmdb3.cache unless configured
otherwise. The cache engine can be configured as follows.
>>> from tmdb3 import set_cache
>>> set_cache('null')
>>> set_cache(filename='/full/path/to/cache') # the 'file' engine is assumed
>>> set_cache(filename='tmdb3.cache') # relative paths are put in /tmp
>>> set_cache(engine='file', filename='~/.tmdb3cache')
Locale Configuration
The previous v2 API supported language selection, but would fall through to
the defaults for any fields that did not have language-specific values. The
v3 API no longer performs this fall through, leaving it up to clients to
optionally implement it on their own.
The PyTMDB3 module supports the use of locales in two separate manners. One
can define a global locale that is automatically used if not specified
otherwise, or a specific locale can be supplied directly to searches and
data queries using the locale= keyword argument, which is then propogated
through any subsequent queries made through those objects.
Locale settings are controlled through two functions
set_locale() is used to set the global default locale. It optionally accepts
language and country keyword arguments. If not supplied, it will attempt
to pull such information from your environment. It also accepts a
fallthrough keyword argument, which is used to control the language and
country filter fall through. This is disabled by default, meaning if a
language is set, it will only return information specific to that language.
get_locale() also accepts optional language and country keyword arguments,
and can be used to generate locales to use directly, overriding the global
configuration. If none is given, this instead returns the global
configuration. Note that fall through behavior is applied module-wide, and
individual locales cannot be used to change that behavior.
Authentication
This is not yet supported.
Searching
There are currently six search methods available for use: movies, people,
studios, lists, collections, and series. Search results from TheMovieDb
are sent iteratively, twenty results per page. The search methods provided by
the PyTMDB3 module return list-like structures that will automatically grab
new pages as needed.
>>> from tmdb3 import searchMovie
>>> res = searchMovie('A New Hope')
>>> res
<Search Results: A New Hope>
>>> len(res)
4
>>> res[0]
<Movie 'Star Wars: Episode IV - A New Hope' (1977)>
The movieSearch() method accepts an 'adult' keyword to allow adult content
to be returned. By default, this is set to False and such content is filtered
out. The people search method behaves similarly.
>>> from tmdb import searchPerson
>>> res = searchPerson('Hanks')
>>> res
<Search Results: Hanks>
>>> res[0]
<Person 'Tom Hanks'>
>>> from tmdb import searchStudio
>>> res = searchStudio('Sony Pictures')
>>> res
<Search Results: Sony Pictures>
>>> res[0]
<Studio 'Sony Pictures'>
The movieSearch() method accepts a year keyword, which tells TMDB to
filter for movies of only that specific year. There is a helper method,
movieSearchWithYear(), which will process the release year from movie
names where the year is contained in parentheses, as in:
>>> from tmdb import searchMovieWithYear
>>> list(searchMovieWithYear('Star Wars (1977)'))
[<Movie 'Star Wars: Episode IV - A New Hope' (1977)>, <Movie 'The Making of 'Star Wars'' (1977)>]
Direct Queries
There are currently four data types that support direct access: Collections,
Movies, Persons, and Studios. These each take a single integer ID as an
argument. All data attributes are implemented as properties, and populated
on-demand as used, rather than when the object is created.
>>> from tmdb3 import Collection, Movie, Person, Studio
>>> Collection(10)
<Collection 'Star Wars Collection'>
>>> Movie(11)
<Movie 'Star Wars: Episode IV - A New Hope' (1977)>
>>> Person(2)
<Person 'Mark Hamill'>
>>> Studio(1)
<Studio 'Lucasfilm'>
The Genre class cannot be called by id directly, however it does have a
getAll classmethod, capable of returning all available genres for a specified
language.
Image Behavior
TheMovieDb currently offers three types of artwork: backdrops, posters, and
profiles. The three data queries above will each carry a default one of these
and potentially a list of additionals to choose from. Each can be downloaded
directly, or at one of several pre-scaled reduced resolutions. The PyTMDB3
module provides a list of available sizes, and will generate a URL to download
a requested size. Invalid sizes return an error.
>>> from tmdb3 import Movie
>>> p = Movie(11).poster
>>> p
<Poster 'tvSlBzAdRE29bZe5yYWrJ2ds137.jpg'>
>>> p.sizes()
[u'w92', u'w154', u'w185', u'w342', u'w500', u'original']
>>> p.geturl()
u'http://cf2.imgobject.com/t/p/original/tvSlBzAdRE29bZe5yYWrJ2ds137.jpg'
>>> p.geturl('w342')
u'http://cf2.imgobject.com/t/p/w342/tvSlBzAdRE29bZe5yYWrJ2ds137.jpg'
>>> p.geturl('w300')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "tmdb3/tmdb_api.py", line 101, in geturl
raise TMDBImageSizeError
tmdb3.tmdb_exceptions.TMDBImageSizeError: None
Trailers
TheMovieDb offers access to trailers on Youtube and Apple, however their use
is slightly different. Youtube trailers offer an individual file, while Apple
trailers offer multiple sizes.