parent
96a3acf8e9
commit
3a944251da
@ -0,0 +1,106 @@
|
||||
import os
|
||||
import re
|
||||
import logging
|
||||
import tmdbsimple as tmdb
|
||||
from database import database
|
||||
|
||||
tmdb.API_KEY = 'e5577e69d409c601acb98d5bfcee31c7'
|
||||
|
||||
|
||||
def list_series_directories(root_dir):
|
||||
series_directories = []
|
||||
|
||||
try:
|
||||
root_dir_path = database.execute("SELECT path FROM t_rootdir WHERE id=?", (root_dir,),
|
||||
only_one=True)['path']
|
||||
except:
|
||||
pass
|
||||
else:
|
||||
for i, directory_temp in enumerate(os.listdir(root_dir_path)):
|
||||
directory_original = re.sub(r"\(\b(19|20)\d{2}\b\)", '', directory_temp).rstrip()
|
||||
directory = re.sub(r"\s\b(19|20)\d{2}\b", '', directory_original).rstrip()
|
||||
if directory.endswith(', The'):
|
||||
directory = 'The ' + directory.rstrip(', The')
|
||||
elif directory.endswith(', A'):
|
||||
directory = 'A ' + directory.rstrip(', A')
|
||||
if not directory.startswith('.'):
|
||||
series_directories.append(
|
||||
{
|
||||
'id': i,
|
||||
'directory': directory_temp,
|
||||
'rootDir': root_dir
|
||||
}
|
||||
)
|
||||
finally:
|
||||
return series_directories
|
||||
|
||||
|
||||
def get_series_match(directory):
|
||||
directory_temp = directory
|
||||
directory_original = re.sub(r"\(\b(19|20)\d{2}\b\)", '', directory_temp).rstrip()
|
||||
directory = re.sub(r"\s\b(19|20)\d{2}\b", '', directory_original).rstrip()
|
||||
|
||||
search = tmdb.Search()
|
||||
try:
|
||||
series_temp = search.tv(query=directory)
|
||||
except Exception as e:
|
||||
logging.exception('BAZARR is facing issues index series: {0}'.format(repr(e)))
|
||||
else:
|
||||
matching_series = []
|
||||
if series_temp['total_results']:
|
||||
for item in series_temp['results']:
|
||||
year = None
|
||||
if 'first_air_date' in item:
|
||||
year = item['first_air_date'][:4]
|
||||
matching_series.append(
|
||||
{
|
||||
'title': item['original_name'],
|
||||
'year': year or 'n/a',
|
||||
'tmdbId': item['id']
|
||||
}
|
||||
)
|
||||
return matching_series
|
||||
|
||||
|
||||
def get_series_metadata(tmdbid):
|
||||
series_metadata = {}
|
||||
if tmdbid:
|
||||
try:
|
||||
tmdbSeries = tmdb.TV(id=tmdbid)
|
||||
series_info = tmdbSeries.info()
|
||||
alternative_titles = tmdbSeries.alternative_titles()
|
||||
external_ids = tmdbSeries.external_ids()
|
||||
except Exception as e:
|
||||
logging.exception('BAZARR is facing issues index series: {0}'.format(repr(e)))
|
||||
else:
|
||||
images_url = 'https://image.tmdb.org/t/p/original{0}'
|
||||
|
||||
series_metadata = {
|
||||
'title': series_info['original_name'],
|
||||
'sortTitle': normalize_title(series_info['original_name']),
|
||||
'year': series_info['first_air_date'][:4],
|
||||
'tmdbId': tmdbid,
|
||||
'overview': series_info['overview'],
|
||||
'poster': images_url.format(series_info['poster_path']),
|
||||
'fanart': images_url.format(series_info['backdrop_path']),
|
||||
'alternateTitles': [x['title'] for x in alternative_titles['results']],
|
||||
'tvdbId': external_ids['tvdb_id']
|
||||
}
|
||||
|
||||
return series_metadata
|
||||
|
||||
|
||||
def normalize_title(title):
|
||||
WordDelimiterRegex = re.compile(r"(\s|\.|,|_|-|=|\|)+")
|
||||
PunctuationRegex = re.compile(r"[^\w\s]")
|
||||
CommonWordRegex = re.compile(r"\b(a|an|the|and|or|of)\b\s?")
|
||||
DuplicateSpacesRegex = re.compile(r"\s{2,}")
|
||||
|
||||
title = title.lower()
|
||||
|
||||
title = re.sub(WordDelimiterRegex, " ", title)
|
||||
title = re.sub(PunctuationRegex, "", title)
|
||||
title = re.sub(CommonWordRegex, "", title)
|
||||
title = re.sub(DuplicateSpacesRegex, " ", title)
|
||||
|
||||
return title.strip()
|
@ -0,0 +1,53 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
tmdbsimple
|
||||
~~~~~~~~~~
|
||||
|
||||
*tmdbsimple* is a wrapper, written in Python, for The Movie Database (TMDb)
|
||||
API v3. By calling the functions available in *tmdbsimple* you can simplify
|
||||
your code and easily access a vast amount of movie, tv, and cast data. To find
|
||||
out more about The Movie Database API, check out the overview page
|
||||
http://www.themoviedb.org/documentation/api and documentation page
|
||||
https://developers.themoviedb.org/3/getting-started
|
||||
https://www.themoviedb.org/documentation/api/status-codes
|
||||
|
||||
:copyright: (c) 2013-2020 by Celia Oakley.
|
||||
:license: GPLv3, see LICENSE for more details
|
||||
"""
|
||||
|
||||
__title__ = 'tmdbsimple'
|
||||
__version__ = '2.4.2'
|
||||
__author__ = 'Celia Oakley'
|
||||
__copyright__ = 'Copyright (c) 2013-2020 Celia Oakley'
|
||||
__license__ = 'GPLv3'
|
||||
|
||||
import os
|
||||
|
||||
from .account import Account, Authentication, GuestSessions, Lists
|
||||
from .base import APIKeyError
|
||||
from .changes import Changes
|
||||
from .configuration import Configuration, Certifications, Timezones
|
||||
from .discover import Discover
|
||||
from .find import Find, Trending
|
||||
from .genres import Genres
|
||||
from .movies import Movies, Collections, Companies, Keywords, Reviews
|
||||
from .people import People, Credits, Jobs
|
||||
from .search import Search
|
||||
from .tv import TV, TV_Seasons, TV_Episodes, TV_Episode_Groups, TV_Changes, Networks
|
||||
|
||||
__all__ = ['Account', 'Authentication', 'GuestSessions', 'Lists',
|
||||
'APIKeyError',
|
||||
'Changes',
|
||||
'Configuration', 'Certifications', 'Timezones',
|
||||
'Discover',
|
||||
'Find', 'Trending',
|
||||
'Genres',
|
||||
'Movies', 'Collections', 'Companies', 'Keywords', 'Reviews',
|
||||
'People', 'Credits', 'Jobs',
|
||||
'Search',
|
||||
'TV', 'TV_Seasons', 'TV_Episodes', 'TV_Episode_Groups', 'TV_Changes', 'Networks'
|
||||
]
|
||||
|
||||
API_KEY = os.environ.get('TMDB_API_KEY', None)
|
||||
API_VERSION = '3'
|
@ -0,0 +1,578 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
tmdbsimple.account
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
This module implements the Account, Authentication, and Lists functionality
|
||||
of tmdbsimple.
|
||||
|
||||
Created by Celia Oakley on 2013-10-31.
|
||||
|
||||
:copyright: (c) 2013-2020 by Celia Oakley
|
||||
:license: GPLv3, see LICENSE for more details
|
||||
"""
|
||||
|
||||
from .base import TMDB
|
||||
|
||||
|
||||
class Account(TMDB):
|
||||
"""
|
||||
Account functionality.
|
||||
|
||||
See: https://developers.themoviedb.org/3/account
|
||||
https://www.themoviedb.org/documentation/api/sessions
|
||||
"""
|
||||
BASE_PATH = 'account'
|
||||
URLS = {
|
||||
'info': '',
|
||||
'lists': '/{id}/lists',
|
||||
'favorite_movies': '/{id}/favorite/movies',
|
||||
'favorite_tv': '/{id}/favorite/tv',
|
||||
'favorite': '/{id}/favorite',
|
||||
'rated_movies': '/{id}/rated/movies',
|
||||
'rated_tv': '/{id}/rated/tv',
|
||||
'rated_tv_episodes': '/{id}/rated/tv/episodes',
|
||||
'watchlist_movies': '/{id}/watchlist/movies',
|
||||
'watchlist_tv': '/{id}/watchlist/tv',
|
||||
'watchlist': '/{id}/watchlist',
|
||||
}
|
||||
|
||||
def __init__(self, session_id):
|
||||
super(Account, self).__init__()
|
||||
self.session_id = session_id
|
||||
|
||||
def info(self, **kwargs):
|
||||
"""
|
||||
Get your account details.
|
||||
|
||||
Call this method first, before calling other Account methods.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_path('info')
|
||||
kwargs.update({'session_id': self.session_id})
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self.id = response['id']
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def lists(self, **kwargs):
|
||||
"""
|
||||
Get all of the lists created by an account. Will include private lists if you are the owner.
|
||||
|
||||
Args:
|
||||
page: (optional) Minimum 1, maximum 1000.
|
||||
language: (optional) ISO 639-1 code.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('lists')
|
||||
kwargs.update({'session_id': self.session_id})
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def favorite_movies(self, **kwargs):
|
||||
"""
|
||||
Get the list of your favorite movies.
|
||||
|
||||
Args:
|
||||
page: (optional) Minimum 1, maximum 1000.
|
||||
sort_by: (optional) 'created_at.asc' | 'created_at.desc'
|
||||
language: (optional) ISO 639-1 code.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('favorite_movies')
|
||||
kwargs.update({'session_id': self.session_id})
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def favorite_tv(self, **kwargs):
|
||||
"""
|
||||
Get the list of your favorite TV shows.
|
||||
|
||||
Args:
|
||||
page: (optional) Minimum 1, maximum 1000.
|
||||
sort_by: (optional) 'created_at.asc' | 'created_at.desc'
|
||||
language: (optional) ISO 639-1 code.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('favorite_tv')
|
||||
kwargs.update({'session_id': self.session_id})
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def favorite(self, **kwargs):
|
||||
"""
|
||||
This method allows you to mark a movie or TV show as a favorite item.
|
||||
|
||||
Args:
|
||||
media_type: 'movie' | 'tv'
|
||||
media_id: The id of the media.
|
||||
favorite: True (to add) | False (to remove).
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('favorite')
|
||||
kwargs.update({'session_id': self.session_id})
|
||||
|
||||
payload = {
|
||||
'media_type': kwargs.pop('media_type', None),
|
||||
'media_id': kwargs.pop('media_id', None),
|
||||
'favorite': kwargs.pop('favorite', None),
|
||||
}
|
||||
|
||||
response = self._POST(path, kwargs, payload)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def rated_movies(self, **kwargs):
|
||||
"""
|
||||
Get a list of all the movies you have rated.
|
||||
|
||||
Args:
|
||||
page: (optional) Minimum 1, maximum 1000.
|
||||
sort_by: (optional) 'created_at.asc' | 'created_at.desc'
|
||||
language: (optional) ISO 639-1 code.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('rated_movies')
|
||||
kwargs.update({'session_id': self.session_id})
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def rated_tv(self, **kwargs):
|
||||
"""
|
||||
Get a list of all the TV shows you have rated.
|
||||
|
||||
Args:
|
||||
page: (optional) Minimum 1, maximum 1000.
|
||||
sort_by: (optional) 'created_at.asc' | 'created_at.desc'
|
||||
language: (optional) ISO 639-1 code.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('rated_tv')
|
||||
kwargs.update({'session_id': self.session_id})
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def rated_tv_episodes(self, **kwargs):
|
||||
"""
|
||||
Get a list of all the TV episodes you have rated.
|
||||
|
||||
Args:
|
||||
page: (optional) Minimum 1, maximum 1000.
|
||||
sort_by: (optional) 'created_at.asc' | 'created_at.desc'
|
||||
language: (optional) ISO 639-1 code.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('rated_tv_episodes')
|
||||
kwargs.update({'session_id': self.session_id})
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def watchlist_movies(self, **kwargs):
|
||||
"""
|
||||
Get a list of all the movies you have added to your watchlist.
|
||||
|
||||
Args:
|
||||
page: (optional) Minimum 1, maximum 1000.
|
||||
sort_by: (optional) 'created_at.asc' | 'created_at.desc'
|
||||
language: (optional) ISO 639-1 code.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('watchlist_movies')
|
||||
kwargs.update({'session_id': self.session_id})
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def watchlist_tv(self, **kwargs):
|
||||
"""
|
||||
Get a list of all the TV shows you have added to your watchlist.
|
||||
|
||||
Args:
|
||||
page: (optional) Minimum 1, maximum 1000.
|
||||
sort_by: (optional) 'created_at.asc' | 'created_at.desc'
|
||||
language: (optional) ISO 639-1 code.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('watchlist_tv')
|
||||
kwargs.update({'session_id': self.session_id})
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def watchlist(self, **kwargs):
|
||||
"""
|
||||
Add a movie or TV show to your watchlist.
|
||||
|
||||
Args:
|
||||
media_type: 'movie' | 'tv'
|
||||
media_id: The id of the media.
|
||||
watchlist: True (to add) | False (to remove).
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('watchlist')
|
||||
kwargs.update({'session_id': self.session_id})
|
||||
|
||||
payload = {
|
||||
'media_type': kwargs.pop('media_type', None),
|
||||
'media_id': kwargs.pop('media_id', None),
|
||||
'watchlist': kwargs.pop('watchlist', None),
|
||||
}
|
||||
|
||||
response = self._POST(path, kwargs, payload)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
|
||||
class Authentication(TMDB):
|
||||
"""
|
||||
Authentication functionality.
|
||||
|
||||
See: https://developers.themoviedb.org/3/authentication
|
||||
https://www.themoviedb.org/documentation/api/sessions
|
||||
"""
|
||||
BASE_PATH = 'authentication'
|
||||
URLS = {
|
||||
'guest_session_new': '/guest_session/new',
|
||||
'token_new': '/token/new',
|
||||
'session_new': '/session/new',
|
||||
'token_validate_with_login': '/token/validate_with_login',
|
||||
}
|
||||
|
||||
def guest_session_new(self, **kwargs):
|
||||
"""
|
||||
This method will let you create a new guest session. Guest sessions
|
||||
are a type of session that will let a user rate movies and TV shows
|
||||
but not require them to have a TMDb user account. More
|
||||
information about user authentication can be found here
|
||||
(https://developers.themoviedb.org/3/authentication/how-do-i-generate-a-session-id).
|
||||
|
||||
Please note, you should only generate a single guest session per
|
||||
user (or device) as you will be able to attach the ratings to a
|
||||
TMDb user account in the future. There is also IP limits in place
|
||||
so you should always make sure it's the end user doing the guest
|
||||
session actions.
|
||||
|
||||
If a guest session is not used for the first time within 24 hours,
|
||||
it will be automatically deleted.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_path('guest_session_new')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def token_new(self, **kwargs):
|
||||
"""
|
||||
Create a temporary request token that can be used to validate a TMDb
|
||||
user login. More details about how this works can be found here
|
||||
(https://developers.themoviedb.org/3/authentication/how-do-i-generate-a-session-id).
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_path('token_new')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def session_new(self, **kwargs):
|
||||
"""
|
||||
You can use this method to create a fully valid session ID once a user
|
||||
has validated the request token. More information about how this works
|
||||
can be found here
|
||||
(https://developers.themoviedb.org/3/authentication/how-do-i-generate-a-session-id).
|
||||
|
||||
Args:
|
||||
request_token: The token you generated for the user to approve.
|
||||
The token needs to be approved before being
|
||||
used here.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_path('session_new')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def token_validate_with_login(self, **kwargs):
|
||||
"""
|
||||
This method allows an application to validate a request token by entering
|
||||
a username and password.
|
||||
|
||||
Not all applications have access to a web view so this can be used as a
|
||||
substitute.
|
||||
|
||||
Please note, the preferred method of validating a request token is to
|
||||
have a user authenticate the request via the TMDb website. You can read
|
||||
about that method here
|
||||
(https://developers.themoviedb.org/3/authentication/how-do-i-generate-a-session-id).
|
||||
|
||||
If you decide to use this method please use HTTPS.
|
||||
|
||||
Args:
|
||||
username: The user's username on TMDb.
|
||||
password: The user's password on TMDb.
|
||||
request_token: The token you generated for the user to approve.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_path('token_validate_with_login')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
|
||||
class GuestSessions(TMDB):
|
||||
"""
|
||||
Guest Sessions functionality.
|
||||
|
||||
See: https://developers.themoviedb.org/3/guest-sessions
|
||||
"""
|
||||
BASE_PATH = 'guest_session'
|
||||
URLS = {
|
||||
'rated_movies': '/{guest_session_id}/rated/movies',
|
||||
'rated_tv': '/{guest_session_id}/rated/tv',
|
||||
'rated_tv_episodes': '/{guest_session_id}/rated/tv/episodes',
|
||||
}
|
||||
|
||||
def __init__(self, guest_session_id=0):
|
||||
super(GuestSessions, self).__init__()
|
||||
self.guest_session_id = guest_session_id
|
||||
|
||||
def rated_movies(self, **kwargs):
|
||||
"""
|
||||
Get the rated movies for a guest session.
|
||||
|
||||
Args:
|
||||
page: (optional) Minimum 1, maximum 1000.
|
||||
sort_by: (optional) 'created_at.asc' | 'created_at.desc'
|
||||
language: (optional) ISO 639-1 code.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_guest_session_id_path('rated_movies')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def rated_tv(self, **kwargs):
|
||||
"""
|
||||
Get the rated TV shows for a guest session.
|
||||
|
||||
Args:
|
||||
page: (optional) Minimum 1, maximum 1000.
|
||||
sort_by: (optional) 'created_at.asc' | 'created_at.desc'
|
||||
language: (optional) ISO 639-1 code.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_guest_session_id_path('rated_tv')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def rated_tv_episodes(self, **kwargs):
|
||||
"""
|
||||
Get the rated TV episodes for a guest session.
|
||||
|
||||
Args:
|
||||
page: (optional) Minimum 1, maximum 1000.
|
||||
sort_by: (optional) 'created_at.asc' | 'created_at.desc'
|
||||
language: (optional) ISO 639-1 code.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_guest_session_id_path('rated_tv_episodes')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
|
||||
class Lists(TMDB):
|
||||
"""
|
||||
Lists functionality.
|
||||
|
||||
See: https://developers.themoviedb.org/3/lists
|
||||
"""
|
||||
BASE_PATH = 'list'
|
||||
URLS = {
|
||||
'info': '/{id}',
|
||||
'item_status': '/{id}/item_status',
|
||||
'create_list': '',
|
||||
'add_item': '/{id}/add_item',
|
||||
'remove_item': '/{id}/remove_item',
|
||||
'clear': '/{id}/clear',
|
||||
}
|
||||
|
||||
def __init__(self, id=0, session_id=0):
|
||||
super(Lists, self).__init__()
|
||||
self.id = id
|
||||
self.session_id = session_id
|
||||
|
||||
def info(self, **kwargs):
|
||||
"""
|
||||
Get the details of a list.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('info')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def item_status(self, **kwargs):
|
||||
"""
|
||||
You can use this method to check if a movie has already been added to
|
||||
the list.
|
||||
|
||||
Args:
|
||||
movie_id: The id of the movie.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('item_status')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def create_list(self, **kwargs):
|
||||
"""
|
||||
Create a list.
|
||||
|
||||
Args:
|
||||
name: Name of the list.
|
||||
description: Description of the list.
|
||||
language: (optional) ISO 639-1 code.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_path('create_list')
|
||||
kwargs.update({'session_id': self.session_id})
|
||||
|
||||
payload = {
|
||||
'name': kwargs.pop('name', None),
|
||||
'description': kwargs.pop('description', None),
|
||||
}
|
||||
if 'language' in kwargs:
|
||||
payload['language'] = kwargs['language']
|
||||
|
||||
response = self._POST(path, kwargs, payload)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def add_item(self, **kwargs):
|
||||
"""
|
||||
Add a movie to a list.
|
||||
|
||||
Args:
|
||||
media_id: A movie id.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('add_item')
|
||||
kwargs.update({'session_id': self.session_id})
|
||||
|
||||
payload = {
|
||||
'media_id': kwargs.pop('media_id', None),
|
||||
}
|
||||
|
||||
response = self._POST(path, kwargs, payload)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def remove_item(self, **kwargs):
|
||||
"""
|
||||
Remove a movie from a list.
|
||||
|
||||
Args:
|
||||
media_id: A movie id.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('remove_item')
|
||||
kwargs.update({'session_id': self.session_id})
|
||||
|
||||
payload = {
|
||||
'media_id': kwargs.pop('media_id', None),
|
||||
}
|
||||
|
||||
response = self._POST(path, kwargs, payload)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def clear_list(self, **kwargs):
|
||||
"""
|
||||
Clear all of the items from a list.
|
||||
|
||||
Args:
|
||||
confirm: True (do it) | False (don't do it)
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('clear')
|
||||
kwargs.update({'session_id': self.session_id})
|
||||
|
||||
payload = {}
|
||||
|
||||
response = self._POST(path, kwargs, payload)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
@ -0,0 +1,114 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
tmdbsimple.base
|
||||
~~~~~~~~~~~~~~~
|
||||
This module implements the base class of tmdbsimple.
|
||||
|
||||
Created by Celia Oakley on 2013-10-31.
|
||||
|
||||
:copyright: (c) 2013-2020 by Celia Oakley
|
||||
:license: GPLv3, see LICENSE for more details
|
||||
"""
|
||||
|
||||
import json
|
||||
import requests
|
||||
|
||||
|
||||
class APIKeyError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class TMDB(object):
|
||||
headers = {'Content-Type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
'Connection': 'close'}
|
||||
BASE_PATH = ''
|
||||
URLS = {}
|
||||
|
||||
def __init__(self):
|
||||
from . import API_VERSION
|
||||
self.base_uri = 'https://api.themoviedb.org'
|
||||
self.base_uri += '/{version}'.format(version=API_VERSION)
|
||||
|
||||
def _get_path(self, key):
|
||||
return self.BASE_PATH + self.URLS[key]
|
||||
|
||||
def _get_id_path(self, key):
|
||||
return self._get_path(key).format(id=self.id)
|
||||
|
||||
def _get_guest_session_id_path(self, key):
|
||||
return self._get_path(key).format(
|
||||
guest_session_id=self.guest_session_id)
|
||||
|
||||
def _get_credit_id_path(self, key):
|
||||
return self._get_path(key).format(credit_id=self.credit_id)
|
||||
|
||||
def _get_media_type_time_window_path(self, key):
|
||||
return self._get_path(key).format(
|
||||
media_type=self.media_type, time_window=self.time_window)
|
||||
|
||||
def _get_tv_id_season_number_path(self, key):
|
||||
return self._get_path(key).format(
|
||||
tv_id=self.tv_id, season_number=self.season_number)
|
||||
|
||||
def _get_tv_id_season_number_episode_number_path(self, key):
|
||||
return self._get_path(key).format(
|
||||
tv_id=self.tv_id, season_number=self.season_number,
|
||||
episode_number=self.episode_number)
|
||||
|
||||
def _get_complete_url(self, path):
|
||||
return '{base_uri}/{path}'.format(base_uri=self.base_uri, path=path)
|
||||
|
||||
def _get_params(self, params):
|
||||
from . import API_KEY
|
||||
if not API_KEY:
|
||||
raise APIKeyError
|
||||
|
||||
api_dict = {'api_key': API_KEY}
|
||||
if params:
|
||||
params.update(api_dict)
|
||||
for key, value in params.items():
|
||||
if isinstance(params[key], bool):
|
||||
params[key] = 'true' if value is True else 'false'
|
||||
|
||||
else:
|
||||
params = api_dict
|
||||
return params
|
||||
|
||||
def _request(self, method, path, params=None, payload=None):
|
||||
url = self._get_complete_url(path)
|
||||
params = self._get_params(params)
|
||||
|
||||
response = requests.request(
|
||||
method, url, params=params,
|
||||
data=json.dumps(payload) if payload else payload,
|
||||
headers=self.headers)
|
||||
|
||||
response.raise_for_status()
|
||||
response.encoding = 'utf-8'
|
||||
return response.json()
|
||||
|
||||
def _GET(self, path, params=None):
|
||||
return self._request('GET', path, params=params)
|
||||
|
||||
def _POST(self, path, params=None, payload=None):
|
||||
return self._request('POST', path, params=params, payload=payload)
|
||||
|
||||
def _DELETE(self, path, params=None, payload=None):
|
||||
return self._request('DELETE', path, params=params, payload=payload)
|
||||
|
||||
def _set_attrs_to_values(self, response={}):
|
||||
"""
|
||||
Set attributes to dictionary values.
|
||||
|
||||
- e.g.
|
||||
>>> import tmdbsimple as tmdb
|
||||
>>> movie = tmdb.Movies(103332)
|
||||
>>> response = movie.info()
|
||||
>>> movie.title # instead of response['title']
|
||||
"""
|
||||
if isinstance(response, dict):
|
||||
for key in response.keys():
|
||||
if not hasattr(self, key) or not callable(getattr(self, key)):
|
||||
setattr(self, key, response[key])
|
@ -0,0 +1,97 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
tmdbsimple.changes
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
This module implements the Changes functionality of tmdbsimple.
|
||||
|
||||
Created by Celia Oakley on 2013-10-31.
|
||||
|
||||
:copyright: (c) 2013-2020 by Celia Oakley
|
||||
:license: GPLv3, see LICENSE for more details
|
||||
"""
|
||||
|
||||
from .base import TMDB
|
||||
|
||||
|
||||
class Changes(TMDB):
|
||||
"""
|
||||
Changes functionality.
|
||||
|
||||
See: https://developers.themoviedb.org/3/changes
|
||||
"""
|
||||
BASE_PATH = ''
|
||||
URLS = {
|
||||
'movie': 'movie/changes',
|
||||
'tv': 'tv/changes',
|
||||
'person': 'person/changes',
|
||||
}
|
||||
|
||||
def movie(self, **kwargs):
|
||||
"""
|
||||
Get a list of all of the movie ids that have been changed
|
||||
in the past 24 hours.
|
||||
|
||||
You can query it for up to 14 days worth of changed IDs at
|
||||
a time with the start_date and end_date query parameters.
|
||||
100 items are returned per page.
|
||||
|
||||
Args:
|
||||
page: (optional) Minimum 1, maximum 1000.
|
||||
start_date: (optional) Expected format is 'YYYY-MM-DD'.
|
||||
end_date: (optional) Expected format is 'YYYY-MM-DD'.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_path('movie')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def tv(self, **kwargs):
|
||||
"""
|
||||
Get a list of all of the TV show ids that have been changed
|
||||
in the past 24 hours.
|
||||
|
||||
You can query it for up to 14 days worth of changed IDs at
|
||||
a time with the start_date and end_date query parameters.
|
||||
100 items are returned per page.
|
||||
|
||||
Args:
|
||||
page: (optional) Minimum 1, maximum 1000.
|
||||
start_date: (optional) Expected format is 'YYYY-MM-DD'.
|
||||
end_date: (optional) Expected format is 'YYYY-MM-DD'.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_path('tv')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def person(self, **kwargs):
|
||||
"""
|
||||
Get a list of all of the person ids that have been changed
|
||||
in the past 24 hours.
|
||||
|
||||
You can query it for up to 14 days worth of changed IDs at
|
||||
a time with the start_date and end_date query parameters.
|
||||
100 items are returned per page.
|
||||
|
||||
Args:
|
||||
page: (optional) Minimum 1, maximum 1000.
|
||||
start_date: (optional) Expected format is 'YYYY-MM-DD'.
|
||||
end_date: (optional) Expected format is 'YYYY-MM-DD'.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_path('person')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
@ -0,0 +1,181 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
tmdbsimple.discover
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
This module implements the Discover functionality of tmdbsimple.
|
||||
|
||||
Created by Celia Oakley on 2013-10-31.
|
||||
|
||||
:copyright: (c) 2013-2020 by Celia Oakley
|
||||
:license: GPLv3, see LICENSE for more details
|
||||
"""
|
||||
|
||||
from .base import TMDB
|
||||
|
||||
|
||||
class Discover(TMDB):
|
||||
"""
|
||||
Discover functionality.
|
||||
|
||||
See: https://developers.themoviedb.org/3/discover
|
||||
"""
|
||||
BASE_PATH = 'discover'
|
||||
URLS = {
|
||||
'movie': '/movie',
|
||||
'tv': '/tv',
|
||||
}
|
||||
|
||||
def movie(self, **kwargs):
|
||||
"""
|
||||
Discover movies by different types of data like average rating, number
|
||||
of votes, genres and certifications. You can get a valid list of
|
||||
certifications from the certifications list method.
|
||||
|
||||
Discover also supports a nice list of sort options. See below for all
|
||||
of the available options.
|
||||
|
||||
Please note, when using certification / certification.lte you must also
|
||||
specify certification_country. These two parameters work together in
|
||||
order to filter the results. You can only filter results with the
|
||||
countries we have added to our certifications list.
|
||||
|
||||
If you specify the region parameter, the regional release date will be
|
||||
used instead of the primary release date. The date returned will be the
|
||||
first date based on your query (ie. if a with_release_type is
|
||||
specified). It's important to note the order of the release types that
|
||||
are used. Specifying "2|3" would return the limited theatrical release
|
||||
date as opposed to "3|2" which would return the theatrical date.
|
||||
|
||||
Also note that a number of filters support being comma (,) or pipe (|)
|
||||
separated. Comma's are treated like an AND and query while pipe's are
|
||||
an OR.
|
||||
|
||||
Some examples of what can be done with discover can be found at
|
||||
https://www.themoviedb.org/documentation/api/discover.
|
||||
|
||||
Args:
|
||||
page: (optional) Minimum 1, maximum 1000.
|
||||
language: (optional) ISO 639-1 code.
|
||||
sort_by: (optional) Available options are 'vote_average.desc',
|
||||
'vote_average.asc', 'release_date.desc', 'release_date.asc'
|
||||
'popularity.desc', 'popularity.asc'.
|
||||
include_adult: (optional) Toggle the inclusion of adult titles.
|
||||
Expected value is a boolean, True or False.
|
||||
year: (optional) Filter the results release dates to matches that
|
||||
include this value. Expected value is a year.
|
||||
primary_release_year: (optional) Filter the results so that
|
||||
only the primary release date year has
|
||||
this value. Expected value is a year.
|
||||
vote_count.gte or vote_count_gte: (optional) Only include movies
|
||||
that are equal to, or have a vote count higher
|
||||
than this value. Expected value is an integer.
|
||||
vote_average.gte or vote_average_gte: (optional) Only include
|
||||
movies that are equal to, or have a higher
|
||||
average rating than this value. Expected value
|
||||
is a float.
|
||||
with_genres: (optional) Only include movies with the specified
|
||||
genres. Expected value is an integer (the id of
|
||||
a genre). Multiple values can be specified.
|
||||
Comma separated indicates an 'AND' query, while
|
||||
a pipe (|) separated value indicates an 'OR'.
|
||||
release_date.gte or release_date_gte: (optional) The minimum
|
||||
release to include. Expected format is
|
||||
'YYYY-MM-DD'.
|
||||
releaste_date.lte or release_date_lte: (optional) The maximum
|
||||
release to include. Expected format is
|
||||
'YYYY-MM-DD'.
|
||||
certification_country: (optional) Only include movies with
|
||||
certifications for a specific country. When
|
||||
this value is specified, 'certification.lte'
|
||||
is required. An ISO 3166-1 is expected.
|
||||
certification.lte or certification_lte: (optional) Only include
|
||||
movies with this certification and lower.
|
||||
Expected value is a valid certification for
|
||||
the specified 'certification_country'.
|
||||
with_companies: (optional) Filter movies to include a specific
|
||||
company. Expected value is an integer (the id
|
||||
of a company). They can be comma separated
|
||||
to indicate an 'AND' query.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
# Periods are not allowed in keyword arguments but several API
|
||||
# arguments contain periods. See both usages in tests/test_discover.py.
|
||||
for param in dict(kwargs):
|
||||
if '_lte' in param:
|
||||
kwargs[param.replace('_lte', '.lte')] = kwargs.pop(param)
|
||||
if '_gte' in param:
|
||||
kwargs[param.replace('_gte', '.gte')] = kwargs.pop(param)
|
||||
|
||||
path = self._get_path('movie')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def tv(self, **kwargs):
|
||||
"""
|
||||
Discover TV shows by different types of data like average rating,
|
||||
number of votes, genres, the network they aired on and air dates.
|
||||
|
||||
Discover also supports a nice list of sort options. See below for all
|
||||
of the available options.
|
||||
|
||||
Also note that a number of filters support being comma (,) or pipe (|)
|
||||
separated. Comma's are treated like an AND and query while pipe's are
|
||||
an OR.
|
||||
|
||||
Some examples of what can be done with discover can be found at
|
||||
https://www.themoviedb.org/documentation/api/discover.
|
||||
|
||||
Args:
|
||||
page: (optional) Minimum 1, maximum 1000.
|
||||
language: (optional) ISO 639-1 code.
|
||||
sort_by: (optional) Available options are 'vote_average.desc',
|
||||
'vote_average.asc', 'first_air_date.desc',
|
||||
'first_air_date.asc', 'popularity.desc', 'popularity.asc'
|
||||
first_air_year: (optional) Filter the results release dates to
|
||||
matches that include this value. Expected value
|
||||
is a year.
|
||||
vote_count.gte or vote_count_gte: (optional) Only include TV shows
|
||||
that are equal to,
|
||||
or have vote count higher than this value. Expected
|
||||
value is an integer.
|
||||
vote_average.gte or vote_average_gte: (optional) Only include TV
|
||||
shows that are equal
|
||||
to, or have a higher average rating than this
|
||||
value. Expected value is a float.
|
||||
with_genres: (optional) Only include TV shows with the specified
|
||||
genres. Expected value is an integer (the id of a
|
||||
genre). Multiple valued can be specified. Comma
|
||||
separated indicates an 'AND' query, while a
|
||||
pipe (|) separated value indicates an 'OR'.
|
||||
with_networks: (optional) Filter TV shows to include a specific
|
||||
network. Expected value is an integer (the id of a
|
||||
network). They can be comma separated to indicate an
|
||||
'AND' query.
|
||||
first_air_date.gte or first_air_date_gte: (optional) The minimum
|
||||
release to include.
|
||||
Expected format is 'YYYY-MM-DD'.
|
||||
first_air_date.lte or first_air_date_lte: (optional) The maximum
|
||||
release to include.
|
||||
Expected format is 'YYYY-MM-DD'.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
# Periods are not allowed in keyword arguments but several API
|
||||
# arguments contain periods. See both usages in tests/test_discover.py.
|
||||
for param in dict(kwargs):
|
||||
if '_lte' in param:
|
||||
kwargs[param.replace('_lte', '.lte')] = kwargs.pop(param)
|
||||
if '_gte' in param:
|
||||
kwargs[param.replace('_gte', '.gte')] = kwargs.pop(param)
|
||||
|
||||
path = self._get_path('tv')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
@ -0,0 +1,101 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
tmdbsimple.find
|
||||
~~~~~~~~~~~~~~~
|
||||
This module implements the Find functionality of tmdbsimple.
|
||||
|
||||
Created by Celia Oakley on 2013-10-31.
|
||||
|
||||
:copyright: (c) 2013-2020 by Celia Oakley
|
||||
:license: GPLv3, see LICENSE for more details
|
||||
"""
|
||||
|
||||
from .base import TMDB
|
||||
|
||||
|
||||
class Find(TMDB):
|
||||
"""
|
||||
Find functionality.
|
||||
|
||||
See: https://developers.themoviedb.org/3/find
|
||||
"""
|
||||
BASE_PATH = 'find'
|
||||
URLS = {
|
||||
'info': '/{id}',
|
||||
}
|
||||
|
||||
def __init__(self, id=0):
|
||||
super(Find, self).__init__()
|
||||
self.id = id
|
||||
|
||||
def info(self, **kwargs):
|
||||
"""
|
||||
The find method makes it easy to search for objects in our database by
|
||||
an external id. For example, an IMDB ID.
|
||||
|
||||
This method will search all objects (movies, TV shows and people) and
|
||||
return the results in a single response.
|
||||
|
||||
The supported external sources for each object are as follows.
|
||||
Media Databases: IMDb ID, TVDB ID, Freebase MID*, Freebase ID*,
|
||||
TVRage ID*
|
||||
Social IDs: Facebook, Insagram, Twitter
|
||||
|
||||
Args:
|
||||
external_source: See lists above.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('info')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
|
||||
class Trending(TMDB):
|
||||
"""
|
||||
Trending functionality.
|
||||
|
||||
See: https://developers.themoviedb.org/3/trending
|
||||
"""
|
||||
BASE_PATH = 'trending'
|
||||
URLS = {
|
||||
'info': '/{media_type}/{time_window}',
|
||||
}
|
||||
|
||||
def __init__(self, media_type='all', time_window='day'):
|
||||
super(Trending, self).__init__()
|
||||
self.media_type = media_type
|
||||
self.time_window = time_window
|
||||
|
||||
def info(self, **kwargs):
|
||||
"""
|
||||
Get the daily or weekly trending items. The daily trending list tracks
|
||||
items over the period of a day while items have a 24 hour half life.
|
||||
The weekly list tracks items over a 7 day period, with a 7 day half
|
||||
life.
|
||||
|
||||
Valid Media Types
|
||||
'all': Include all movies, TV shows and people in the results as a
|
||||
global trending list.
|
||||
'movie': Show the trending movies in the results.
|
||||
'tv': Show the trending TV shows in the results.
|
||||
'people': Show the trending people in the results.
|
||||
|
||||
Valid Time Windows
|
||||
'day': View the trending list for the day.
|
||||
'week': View the trending list for the week.
|
||||
|
||||
Args:
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_media_type_time_window_path('info')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
@ -0,0 +1,88 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
tmdbsimple.genres
|
||||
~~~~~~~~~~~~~~~~~
|
||||
This module implements the Genres functionality of tmdbsimple.
|
||||
|
||||
Created by Celia Oakley on 2013-10-31.
|
||||
|
||||
:copyright: (c) 2013-2020 by Celia Oakley
|
||||
:license: GPLv3, see LICENSE for more details
|
||||
"""
|
||||
|
||||
from .base import TMDB
|
||||
|
||||
|
||||
class Genres(TMDB):
|
||||
"""
|
||||
Genres functionality.
|
||||
|
||||
See: https://developers.themoviedb.org/3/genres
|
||||
"""
|
||||
BASE_PATH = 'genre'
|
||||
URLS = {
|
||||
'movie_list': '/movie/list',
|
||||
'tv_list': '/tv/list',
|
||||
'movies': '/{id}/movies', # backward compatability
|
||||
}
|
||||
|
||||
def __init__(self, id=0):
|
||||
super(Genres, self).__init__()
|
||||
self.id = id
|
||||
|
||||
def movie_list(self, **kwargs):
|
||||
"""
|
||||
Get the list of official genres for movies.
|
||||
|
||||
Args:
|
||||
language: (optional) ISO 639-1 code.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_path('movie_list')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def tv_list(self, **kwargs):
|
||||
"""
|
||||
Get the list of official genres for TV shows.
|
||||
|
||||
Args:
|
||||
language: (optional) ISO 639-1 code.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_path('tv_list')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
# backward compatability
|
||||
def movies(self, **kwargs):
|
||||
"""
|
||||
Get the list of movies for a particular genre by id. By default, only
|
||||
movies with 10 or more votes are included.
|
||||
|
||||
Args:
|
||||
page: (optional) Minimum 1, maximum 1000.
|
||||
language: (optional) ISO 639-1 code.
|
||||
include_all_movies: (optional) Toggle the inclusion of all movies
|
||||
and not just those with 10 or more ratings.
|
||||
Expected value is: True or False.
|
||||
include_adult: (optional) Toggle the inclusion of adult titles.
|
||||
Expected value is: True or False.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('movies')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
@ -0,0 +1,717 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
tmdbsimple.movies
|
||||
~~~~~~~~~~~~~~~~~
|
||||
This module implements the Movies, Collections, Companies, Keywords, and
|
||||
Reviews functionality of tmdbsimple.
|
||||
|
||||
Created by Celia Oakley on 2013-10-31.
|
||||
|
||||
:copyright: (c) 2013-2020 by Celia Oakley
|
||||
:license: GPLv3, see LICENSE for more details
|
||||
"""
|
||||
|
||||
from .base import TMDB
|
||||
|
||||
|
||||
class Movies(TMDB):
|
||||
"""
|
||||
Movies functionality.
|
||||
|
||||
See: https://developers.themoviedb.org/3/movies
|
||||
"""
|
||||
BASE_PATH = 'movie'
|
||||
URLS = {
|
||||
'info': '/{id}',
|
||||
'account_states': '/{id}/account_states',
|
||||
'alternative_titles': '/{id}/alternative_titles',
|
||||
'changes': '/{id}/changes',
|
||||
'credits': '/{id}/credits',
|
||||
'external_ids': '/{id}/external_ids',
|
||||
'images': '/{id}/images',
|
||||
'keywords': '/{id}/keywords',
|
||||
'release_dates': '/{id}/release_dates',
|
||||
'videos': '/{id}/videos',
|
||||
'translations': '/{id}/translations',
|
||||
'recommendations': '/{id}/recommendations',
|
||||
'similar_movies': '/{id}/similar_movies',
|
||||
'reviews': '/{id}/reviews',
|
||||
'lists': '/{id}/lists',
|
||||
'latest': '/latest',
|
||||
'now_playing': '/now_playing',
|
||||
'popular': '/popular',
|
||||
'top_rated': '/top_rated',
|
||||
'upcoming': '/upcoming',
|
||||
'rating': '/{id}/rating', # backward compatability
|
||||
'releases': '/{id}/releases', # backward compatability
|
||||
}
|
||||
|
||||
def __init__(self, id=0):
|
||||
super(Movies, self).__init__()
|
||||
self.id = id
|
||||
|
||||
def info(self, **kwargs):
|
||||
"""
|
||||
Get the primary information about a movie.
|
||||
|
||||
Supports append_to_response. Read more about this at
|
||||
https://developers.themoviedb.org/3/getting-started/append-to-response.
|
||||
|
||||
Args:
|
||||
language: (optional) ISO 639-1 code.
|
||||
append_to_response: (optional) Comma separated, any movie method.
|
||||
|
||||
Returns:
|
||||
A dict representation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('info')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def account_states(self, **kwargs):
|
||||
"""
|
||||
Grab the following account states for a session:
|
||||
- Movie rating
|
||||
- If it belongs to your watchlist
|
||||
- If it belongs to your favourite list
|
||||
|
||||
Args:
|
||||
session_id: see Authentication.
|
||||
|
||||
Returns:
|
||||
A dict representation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('account_states')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def alternative_titles(self, **kwargs):
|
||||
"""
|
||||
Get all of the alternative titles for a movie.
|
||||
|
||||
Args:
|
||||
country: (optional) ISO 3166-1 code.
|
||||
append_to_response: (optional) Comma separated, any movie method.
|
||||
|
||||
Returns:
|
||||
A dict representation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('alternative_titles')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def changes(self, **kwargs):
|
||||
"""
|
||||
Get the changes for a movie. By default only the last 24 hours are returned.
|
||||
|
||||
You can query up to 14 days in a single query by using the start_date
|
||||
and end_date query parameters.
|
||||
|
||||
Args:
|
||||
start_date: (optional) Expected format is 'YYYY-MM-DD'.
|
||||
end_date: (optional) Expected format is 'YYYY-MM-DD'.
|
||||
|
||||
Returns:
|
||||
A dict representation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('changes')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def credits(self, **kwargs):
|
||||
"""
|
||||
Get the cast and crew for a movie.
|
||||
|
||||
Args:
|
||||
append_to_response: (optional) Comma separated, any movie method.
|
||||
|
||||
Returns:
|
||||
A dict representation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('credits')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def external_ids(self, **kwargs):
|
||||
"""
|
||||
Get the external ids for a movie. We currently support the following
|
||||
external sources.
|
||||
|
||||
Media Databases - IMDb
|
||||
Social IDs - Facebok, Instagram, Twitter
|
||||
|
||||
Args:
|
||||
language: (optional) ISO 639-1 code.
|
||||
append_to_response: (optional) Comma separated, any movie method.
|
||||
|
||||
Returns:
|
||||
A dict representation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('external_ids')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def images(self, **kwargs):
|
||||
"""
|
||||
Get the images that belong to a movie.
|
||||
|
||||
Querying images with a language parameter will filter the results. If
|
||||
you want to include a fallback language (especially useful for
|
||||
backdrops) you can use the include_image_language parameter. This
|
||||
should be a comma seperated value like so:
|
||||
include_image_language=en,null.
|
||||
|
||||
Args:
|
||||
language: (optional) ISO 639-1 code.
|
||||
append_to_response: (optional) Comma separated, any movie method.
|
||||
include_image_language: (optional) Comma separated, a valid
|
||||
ISO 69-1.
|
||||
|
||||
Returns:
|
||||
A dict representation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('images')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def keywords(self):
|
||||
"""
|
||||
Get the keywords that have been added to a movie.
|
||||
|
||||
Returns:
|
||||
A dict representation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('keywords')
|
||||
|
||||
response = self._GET(path)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def release_dates(self, **kwargs):
|
||||
"""
|
||||
Get the release date along with the certification for a movie.
|
||||
|
||||
Release dates support different types:
|
||||
|
||||
1. Premiere
|
||||
2. Theatrical (limited)
|
||||
3. Theatrical
|
||||
4. Digital
|
||||
5. Physical
|
||||
6. TV
|
||||
|
||||
Args:
|
||||
append_to_response: (optional) Comma separated, any movie method.
|
||||
|
||||
Returns:
|
||||
A dict representation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('release_dates')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def videos(self, **kwargs):
|
||||
"""
|
||||
Get the videos that have been added to a movie.
|
||||
|
||||
Args:
|
||||
append_to_response: (optional) Comma separated, any movie method.
|
||||
|
||||
Returns:
|
||||
A dict representation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('videos')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def translations(self, **kwargs):
|
||||
"""
|
||||
Get a list of translations that have been created for a movie.
|
||||
|
||||
Args:
|
||||
append_to_response: (optional) Comma separated, any movie method.
|
||||
|
||||
Returns:
|
||||
A dict representation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('translations')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def recommendations(self, **kwargs):
|
||||
"""
|
||||
Get a list of recommended movies for a movie.
|
||||
|
||||
Args:
|
||||
language: (optional) ISO 639-1 code.
|
||||
page: (optional) Minimum value of 1. Expected value is an integer.
|
||||
|
||||
Returns:
|
||||
A dict representation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('recommendations')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def similar_movies(self, **kwargs):
|
||||
"""
|
||||
Get a list of similar movies. This is not the same as the
|
||||
"Recommendation" system you see on the website.
|
||||
|
||||
These items are assembled by looking at keywords and genres.
|
||||
|
||||
Args:
|
||||
page: (optional) Minimum value of 1. Expected value is an integer.
|
||||
language: (optional) ISO 639-1 code.
|
||||
append_to_response: (optional) Comma separated, any movie method.
|
||||
|
||||
Returns:
|
||||
A dict representation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('similar_movies')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def reviews(self, **kwargs):
|
||||
"""
|
||||
Get the user reviews for a movie.
|
||||
|
||||
Args:
|
||||
page: (optional) Minimum value of 1. Expected value is an integer.
|
||||
language: (optional) ISO 639-1 code.
|
||||
append_to_response: (optional) Comma separated, any movie method.
|
||||
|
||||
Returns:
|
||||
A dict representation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('reviews')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def lists(self, **kwargs):
|
||||
"""
|
||||
Get a list of lists that this movie belongs to.
|
||||
|
||||
Args:
|
||||
page: (optional) Minimum value of 1. Expected value is an integer.
|
||||
language: (optional) ISO 639-1 code.
|
||||
append_to_response: (optional) Comma separated, any movie method.
|
||||
|
||||
Returns:
|
||||
A dict representation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('lists')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def rating(self, **kwargs):
|
||||
"""
|
||||
Rate a movie.
|
||||
|
||||
A valid session or guest session ID is required. You can read more
|
||||
about how this works at
|
||||
https://developers.themoviedb.org/3/authentication/how-do-i-generate-a-session-id.
|
||||
|
||||
Args:
|
||||
session_id: see Authentication.
|
||||
guest_session_id: see Authentication.
|
||||
value: Rating value.
|
||||
|
||||
Returns:
|
||||
A dict representation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('rating')
|
||||
|
||||
payload = {
|
||||
'value': kwargs.pop('value', None),
|
||||
}
|
||||
|
||||
response = self._POST(path, kwargs, payload)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def latest(self, **kwargs):
|
||||
"""
|
||||
Get the most newly created movie. This is a live response and will
|
||||
continuously change.
|
||||
|
||||
Returns:
|
||||
A dict representation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_path('latest')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def now_playing(self, **kwargs):
|
||||
"""
|
||||
Get a list of movies in theatres. This is a release type query that
|
||||
looks for all movies that have a release type of 2 or 3 within the
|
||||
specified date range.
|
||||
|
||||
You can optionally specify a region prameter which will narrow the
|
||||
search to only look for theatrical release dates within the specified
|
||||
country.
|
||||
|
||||
Args:
|
||||
page: (optional) Minimum value of 1. Expected value is an integer.
|
||||
language: (optional) ISO 639-1 code.
|
||||
|
||||
Returns:
|
||||
A dict representation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_path('now_playing')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def popular(self, **kwargs):
|
||||
"""
|
||||
Get a list of the current popular movies on TMDb. This list updates
|
||||
daily.
|
||||
|
||||
Args:
|
||||
page: (optional) Minimum value of 1. Expected value is an integer.
|
||||
language: (optional) ISO 639-1 code.
|
||||
|
||||
Returns:
|
||||
A dict representation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_path('popular')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def top_rated(self, **kwargs):
|
||||
"""
|
||||
Get the top rated movies on TMDb.
|
||||
|
||||
Args:
|
||||
page: (optional) Minimum value of 1. Expected value is an integer.
|
||||
language: (optional) ISO 639-1 code.
|
||||
|
||||
Returns:
|
||||
A dict representation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_path('top_rated')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def upcoming(self, **kwargs):
|
||||
"""
|
||||
Get a list of upcoming movies in theatres. This is a release type query
|
||||
that looks for all movies that have a release type of 2 or 3 within the
|
||||
specified date range.
|
||||
|
||||
You can optionally specify a region prameter which will narrow the
|
||||
search to only look for theatrical release dates within the specified
|
||||
country.
|
||||
|
||||
Args:
|
||||
page: (optional) Minimum value of 1. Expected value is an integer.
|
||||
language: (optional) ISO 639-1 code.
|
||||
|
||||
Returns:
|
||||
A dict representation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_path('upcoming')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
# backward compatability
|
||||
def releases(self, **kwargs):
|
||||
"""
|
||||
Get the release date and certification information by country for a
|
||||
specific movie id.
|
||||
|
||||
Args:
|
||||
append_to_response: (optional) Comma separated, any movie method.
|
||||
|
||||
Returns:
|
||||
A dict representation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('releases')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
|
||||
class Collections(TMDB):
|
||||
"""
|
||||
Collections functionality.
|
||||
|
||||
See: https://developers.themoviedb.org/3/collections
|
||||
"""
|
||||
BASE_PATH = 'collection'
|
||||
URLS = {
|
||||
'info': '/{id}',
|
||||
'images': '/{id}/images',
|
||||
'translations': '/{id}/translations',
|
||||
}
|
||||
|
||||
def __init__(self, id):
|
||||
super(Collections, self).__init__()
|
||||
self.id = id
|
||||
|
||||
def info(self, **kwargs):
|
||||
"""
|
||||
Get collection details by id.
|
||||
|
||||
Args:
|
||||
language: (optional) ISO 639-1 code.
|
||||
append_to_response: (optional) Comma separated, any movie method.
|
||||
|
||||
Returns:
|
||||
A dict representation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('info')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def images(self, **kwargs):
|
||||
"""
|
||||
Get the images for a collection by id.
|
||||
|
||||
Args:
|
||||
language: (optional) ISO 639-1 code.
|
||||
append_to_response: (optional) Comma separated, any movie method.
|
||||
include_image_language: (optional) Comma separated, a valid
|
||||
ISO 69-1.
|
||||
|
||||
Returns:
|
||||
A dict representation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('images')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def translations(self, **kwargs):
|
||||
"""
|
||||
Get a list of the translations for a collection by id.
|
||||
|
||||
Args:
|
||||
language: (optional) ISO 639-1 code.
|
||||
append_to_response: (optional) Comma separated, any movie method.
|
||||
|
||||
Returns:
|
||||
A dict representation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('translations')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
|
||||
class Companies(TMDB):
|
||||
"""
|
||||
Companies functionality.
|
||||
|
||||
See: https://developers.themoviedb.org/3/companies
|
||||
"""
|
||||
BASE_PATH = 'company'
|
||||
URLS = {
|
||||
'info': '/{id}',
|
||||
'alternative_names': '/{id}/alternative_names',
|
||||
'images': '/{id}/images',
|
||||
'movies': '/{id}/movies', # backward compatability
|
||||
}
|
||||
|
||||
def __init__(self, id=0):
|
||||
super(Companies, self).__init__()
|
||||
self.id = id
|
||||
|
||||
def info(self, **kwargs):
|
||||
"""
|
||||
Get a companies details by id.
|
||||
|
||||
Args:
|
||||
append_to_response: (optional) Comma separated, any movie method.
|
||||
|
||||
Returns:
|
||||
A dict representation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('info')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def alternative_names(self, **kwargs):
|
||||
"""
|
||||
Get the alternative names of a company.
|
||||
|
||||
Args:
|
||||
|
||||
Returns:
|
||||
A dict representation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('alternative_names')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def images(self, **kwargs):
|
||||
"""
|
||||
Get a company's logos by id.
|
||||
|
||||
There are two image formats that are supported for companies, PNG's and
|
||||
SVG's. You can see which type the original file is by looking at the
|
||||
file_type field. We prefer SVG's as they are resolution independent and
|
||||
as such, the width and height are only there to reflect the original
|
||||
asset that was uploaded. An SVG can be scaled properly beyond those
|
||||
dimensions if you call them as a PNG.
|
||||
|
||||
For more information about how SVG's and PNG's can be used, take a read
|
||||
through https://developers.themoviedb.org/3/getting-started/images.
|
||||
|
||||
Args:
|
||||
|
||||
Returns:
|
||||
A dict representation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('images')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
# backward compatability
|
||||
def movies(self, **kwargs):
|
||||
"""
|
||||
Get the list of movies associated with a particular company.
|
||||
|
||||
Args:
|
||||
page: (optional) Minimum value of 1. Expected value is an integer.
|
||||
language: (optional) ISO 639-1 code.
|
||||
append_to_response: (optional) Comma separated, any movie method.
|
||||
|
||||
Returns:
|
||||
A dict representation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('movies')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
|
||||
class Keywords(TMDB):
|
||||
"""
|
||||
Keywords functionality.
|
||||
|
||||
See: https://developers.themoviedb.org/3/keywords
|
||||
"""
|
||||
BASE_PATH = 'keyword'
|
||||
URLS = {
|
||||
'info': '/{id}',
|
||||
'movies': '/{id}/movies',
|
||||
}
|
||||
|
||||
def __init__(self, id):
|
||||
super(Keywords, self).__init__()
|
||||
self.id = id
|
||||
|
||||
def info(self, **kwargs):
|
||||
"""
|
||||
Get the details of a keyword.
|
||||
|
||||
Returns:
|
||||
A dict representation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('info')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def movies(self, **kwargs):
|
||||
"""
|
||||
Get the movies that belong to a keyword.
|
||||
|
||||
We highly recommend using movie discover instead of this method as it
|
||||
is much more flexible.
|
||||
|
||||
Args:
|
||||
page: (optional) Minimum value of 1. Expected value is an integer.
|
||||
language: (optional) ISO 639-1 code.
|
||||
|
||||
Returns:
|
||||
A dict representation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('movies')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
|
||||
class Reviews(TMDB):
|
||||
"""
|
||||
Reviews functionality.
|
||||
|
||||
See: https://developers.themoviedb.org/3/reviews
|
||||
"""
|
||||
BASE_PATH = 'review'
|
||||
URLS = {
|
||||
'info': '/{id}',
|
||||
}
|
||||
|
||||
def __init__(self, id):
|
||||
super(Reviews, self).__init__()
|
||||
self.id = id
|
||||
|
||||
def info(self, **kwargs):
|
||||
"""
|
||||
Get the review details by id.
|
||||
|
||||
Returns:
|
||||
A dict representation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('info')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
@ -0,0 +1,282 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
tmdbsimple.people
|
||||
~~~~~~~~~~~~~~~~~
|
||||
This module implements the People, Credits, and Jobs functionality
|
||||
of tmdbsimple.
|
||||
|
||||
Created by Celia Oakley on 2013-10-31.
|
||||
|
||||
:copyright: (c) 2013-2020 by Celia Oakley
|
||||
:license: GPLv3, see LICENSE for more details
|
||||
"""
|
||||
|
||||
from .base import TMDB
|
||||
|
||||
|
||||
class People(TMDB):
|
||||
"""
|
||||
People functionality.
|
||||
|
||||
See: https://developers.themoviedb.org/3/people
|
||||
"""
|
||||
BASE_PATH = 'person'
|
||||
URLS = {
|
||||
'info': '/{id}',
|
||||
'changes': '/{id}/changes',
|
||||
'movie_credits': '/{id}/movie_credits',
|
||||
'tv_credits': '/{id}/tv_credits',
|
||||
'combined_credits': '/{id}/combined_credits',
|
||||
'external_ids': '/{id}/external_ids',
|
||||
'images': '/{id}/images',
|
||||
'tagged_images': '/{id}/tagged_images',
|
||||
'translations': '/{id}/translations',
|
||||
'latest': '/latest',
|
||||
'popular': '/popular',
|
||||
}
|
||||
|
||||
def __init__(self, id=0):
|
||||
super(People, self).__init__()
|
||||
self.id = id
|
||||
|
||||
def info(self, **kwargs):
|
||||
"""
|
||||
Get the primary person details by id.
|
||||
|
||||
Supports append_to_response. Read more about this at
|
||||
https://developers.themoviedb.org/3/getting-started/append-to-response.
|
||||
|
||||
Args:
|
||||
append_to_response: (optional) Comma separated, any person method.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('info')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def changes(self, **kwargs):
|
||||
"""
|
||||
Get the changes for a person. By default only the last 24 hours are returned.
|
||||
|
||||
You can query up to 14 days in a single query by using the start_date
|
||||
and end_date query parameters.
|
||||
|
||||
Args:
|
||||
start_date: (optional) Expected format is 'YYYY-MM-DD'.
|
||||
end_date: (optional) Expected format is 'YYYY-MM-DD'.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('changes')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def movie_credits(self, **kwargs):
|
||||
"""
|
||||
Get the movie credits for a person.
|
||||
|
||||
Args:
|
||||
language: (optional) ISO 639-1 code.
|
||||
append_to_response: (optional) Comma separated, any person method.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('movie_credits')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def tv_credits(self, **kwargs):
|
||||
"""
|
||||
Get the TV show credits for a person.
|
||||
|
||||
You can query for some extra details about the credit with the credit
|
||||
method.
|
||||
|
||||
Args:
|
||||
language: (optional) ISO 639-1 code.
|
||||
append_to_response: (optional) Comma separated, any person method.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('tv_credits')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def combined_credits(self, **kwargs):
|
||||
"""
|
||||
Get the movie and TV credits together in a single response.
|
||||
|
||||
Args:
|
||||
language: (optional) ISO 639-1 code.
|
||||
append_to_response: (optional) Comma separated, any person method.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('combined_credits')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def external_ids(self, **kwargs):
|
||||
"""
|
||||
Get the external ids for a person. We currently support the following external sources.
|
||||
|
||||
External Sources
|
||||
- IMDB ID
|
||||
- Facebook
|
||||
- Freebase MID
|
||||
- Freebase ID
|
||||
- Instagram
|
||||
- TVRage ID
|
||||
- Twitter
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('external_ids')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def images(self, **kwargs):
|
||||
"""
|
||||
Get the images for a person.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('images')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def tagged_images(self, **kwargs):
|
||||
"""
|
||||
Get the images that this person has been tagged in.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('tagged_images')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def translations(self, **kwargs):
|
||||
"""
|
||||
Get a list of translations that have been created for a person.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('translations')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def latest(self, **kwargs):
|
||||
"""
|
||||
Get the most newly created person. This is a live response and will
|
||||
continuously change.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_path('latest')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def popular(self, **kwargs):
|
||||
"""
|
||||
Get the list of popular people on TMDb. This list updates daily.
|
||||
|
||||
Args:
|
||||
page: (optional) Minimum 1, maximum 1000.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_path('popular')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
|
||||
class Credits(TMDB):
|
||||
"""
|
||||
Credits functionality.
|
||||
|
||||
See: https://developers.themoviedb.org/3/credits
|
||||
"""
|
||||
BASE_PATH = 'credit'
|
||||
URLS = {
|
||||
'info': '/{credit_id}',
|
||||
}
|
||||
|
||||
def __init__(self, credit_id):
|
||||
super(Credits, self).__init__()
|
||||
self.credit_id = credit_id
|
||||
|
||||
def info(self, **kwargs):
|
||||
"""
|
||||
Get a movie or TV credit details by id.
|
||||
|
||||
Args:
|
||||
language: (optional) ISO 639-1 code.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_credit_id_path('info')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
|
||||
class Jobs(TMDB):
|
||||
"""
|
||||
Jobs functionality.
|
||||
|
||||
See: https://developers.themoviedb.org/3/jobs
|
||||
"""
|
||||
BASE_PATH = 'job'
|
||||
URLS = {
|
||||
'list': '/list',
|
||||
}
|
||||
|
||||
def list(self, **kwargs):
|
||||
"""
|
||||
Get a list of valid jobs.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_path('list')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
@ -0,0 +1,186 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
tmdbsimple.search
|
||||
~~~~~~~~~~~~~~~~~
|
||||
This module implements the Search functionality of tmdbsimple.
|
||||
|
||||
Created by Celia Oakley on 2013-10-31.
|
||||
|
||||
:copyright: (c) 2013-2020 by Celia Oakley
|
||||
:license: GPLv3, see LICENSE for more details
|
||||
"""
|
||||
|
||||
from .base import TMDB
|
||||
|
||||
|
||||
class Search(TMDB):
|
||||
"""
|
||||
Search functionality
|
||||
|
||||
See: https://developers.themoviedb.org/3/search
|
||||
"""
|
||||
BASE_PATH = 'search'
|
||||
URLS = {
|
||||
'company': '/company',
|
||||
'collection': '/collection',
|
||||
'keyword': '/keyword',
|
||||
'movie': '/movie',
|
||||
'multi': '/multi',
|
||||
'person': '/person',
|
||||
'tv': '/tv',
|
||||
}
|
||||
|
||||
def company(self, **kwargs):
|
||||
"""
|
||||
Search for companies.
|
||||
|
||||
Args:
|
||||
query: CGI escpaed string.
|
||||
page: (optional) Minimum value of 1. Expected value is an integer.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_path('company')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def collection(self, **kwargs):
|
||||
"""
|
||||
Search for collections.
|
||||
|
||||
Args:
|
||||
query: CGI escpaed string.
|
||||
page: (optional) Minimum value of 1. Expected value is an integer.
|
||||
language: (optional) ISO 639-1 code.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_path('collection')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def keyword(self, **kwargs):
|
||||
"""
|
||||
Search for keywords.
|
||||
|
||||
Args:
|
||||
query: CGI escpaed string.
|
||||
page: (optional) Minimum value of 1. Expected value is an integer.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_path('keyword')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def movie(self, **kwargs):
|
||||
"""
|
||||
Search for movies.
|
||||
|
||||
Args:
|
||||
query: CGI escpaed string.
|
||||
page: (optional) Minimum value of 1. Expected value is an integer.
|
||||
language: (optional) ISO 639-1 code.
|
||||
include_adult: (optional) Toggle the inclusion of adult titles.
|
||||
Expected value is True or False.
|
||||
year: (optional) Filter the results release dates to matches that
|
||||
include this value.
|
||||
primary_release_year: (optional) Filter the results so that only
|
||||
the primary release dates have this value.
|
||||
search_type: (optional) By default, the search type is 'phrase'.
|
||||
This is almost guaranteed the option you will want.
|
||||
It's a great all purpose search type and by far the
|
||||
most tuned for every day querying. For those wanting
|
||||
more of an "autocomplete" type search, set this
|
||||
option to 'ngram'.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_path('movie')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def multi(self, **kwargs):
|
||||
"""
|
||||
Search multiple models in a single request. Multi search currently
|
||||
supports searching for movies, tv shows and people in a single request.
|
||||
|
||||
Args:
|
||||
query: CGI escpaed string.
|
||||
page: (optional) Minimum value of 1. Expected value is an integer.
|
||||
language: (optional) ISO 639-1 code.
|
||||
include_adult: (optional) Toggle the inclusion of adult titles.
|
||||
Expected value is True or False.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_path('multi')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def person(self, **kwargs):
|
||||
"""
|
||||
Search for people.
|
||||
|
||||
Args:
|
||||
query: CGI escpaed string.
|
||||
page: (optional) Minimum value of 1. Expected value is an integer.
|
||||
include_adult: (optional) Toggle the inclusion of adult titles.
|
||||
Expected value is True or False.
|
||||
search_type: (optional) By default, the search type is 'phrase'.
|
||||
This is almost guaranteed the option you will want.
|
||||
It's a great all purpose search type and by far the
|
||||
most tuned for every day querying. For those wanting
|
||||
more of an "autocomplete" type search, set this
|
||||
option to 'ngram'.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_path('person')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def tv(self, **kwargs):
|
||||
"""
|
||||
Search for a TV show.
|
||||
|
||||
Args:
|
||||
query: CGI escpaed string.
|
||||
page: (optional) Minimum value of 1. Expected value is an integer.
|
||||
language: (optional) ISO 639-1 code.
|
||||
first_air_date_year: (optional) Filter the results to only match
|
||||
shows that have a air date with with value.
|
||||
search_type: (optional) By default, the search type is 'phrase'.
|
||||
This is almost guaranteed the option you will want.
|
||||
It's a great all purpose search type and by far the
|
||||
most tuned for every day querying. For those wanting
|
||||
more of an "autocomplete" type search, set this
|
||||
option to 'ngram'.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_path('tv')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
@ -0,0 +1,951 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
tmdbsimple.tv
|
||||
~~~~~~~~~~~~~
|
||||
This module implements the TV, TV Seasons, TV Episodes, and Networks
|
||||
functionality of tmdbsimple.
|
||||
|
||||
Created by Celia Oakley on 2013-10-31.
|
||||
|
||||
:copyright: (c) 2013-2020 by Celia Oakley
|
||||
:license: GPLv3, see LICENSE for more details
|
||||
"""
|
||||
|
||||
from .base import TMDB
|
||||
|
||||
|
||||
class TV(TMDB):
|
||||
"""
|
||||
TV functionality.
|
||||
|
||||
See: https://developers.themoviedb.org/3/tv
|
||||
"""
|
||||
BASE_PATH = 'tv'
|
||||
URLS = {
|
||||
'info': '/{id}',
|
||||
'account_states': '/{id}/account_states',
|
||||
'alternative_titles': '/{id}/alternative_titles',
|
||||
'content_ratings': '/{id}/content_ratings',
|
||||
'credits': '/{id}/credits',
|
||||
'episode_groups': '/{id}/episode_groups',
|
||||
'external_ids': '/{id}/external_ids',
|
||||
'images': '/{id}/images',
|
||||
'keywords': '/{id}/keywords',
|
||||
'recommendations': '/{id}/recommendations',
|
||||
'reviews': '/{id}/reviews',
|
||||
'screened_theatrically': '/{id}/screened_theatrically',
|
||||
'similar': '/{id}/similar',
|
||||
'translations': '/{id}/translations',
|
||||
'videos': '/{id}/videos',
|
||||
'rating': '/{id}/rating',
|
||||
'latest': '/latest',
|
||||
'airing_today': '/airing_today',
|
||||
'on_the_air': '/on_the_air',
|
||||
'popular': '/popular',
|
||||
'top_rated': '/top_rated',
|
||||
}
|
||||
|
||||
def __init__(self, id=0):
|
||||
super(TV, self).__init__()
|
||||
self.id = id
|
||||
|
||||
def info(self, **kwargs):
|
||||
"""
|
||||
Get the primary TV show details by id.
|
||||
|
||||
Supports append_to_response. Read more about this at
|
||||
https://developers.themoviedb.org/3/getting-started/append-to-response.
|
||||
|
||||
Args:
|
||||
language: (optional) ISO 639 code.
|
||||
append_to_response: (optional) Comma separated, any TV series
|
||||
method.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('info')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def account_states(self, **kwargs):
|
||||
"""
|
||||
Grab the following account states for a session:
|
||||
- TV show rating
|
||||
- If it belongs to your watchlist
|
||||
- If it belongs to your favourite list
|
||||
|
||||
Args:
|
||||
language: (optional) ISO 3166-1 code.
|
||||
append_to_response: (optional) Comma separated, any tv method.
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('account_states')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def alternative_titles(self, **kwargs):
|
||||
"""
|
||||
Returns all of the alternative titles for a TV show.
|
||||
|
||||
Args:
|
||||
language: (optional) ISO 3166-1 code.
|
||||
append_to_response: (optional) Comma separated, any tv method.
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('alternative_titles')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def content_ratings(self, **kwargs):
|
||||
"""
|
||||
Get the list of content ratings (certifications) that have been added
|
||||
to a TV show.
|
||||
|
||||
Args:
|
||||
language: (optional) ISO 639 code.
|
||||
append_to_response: (optional) Comma separated, any collection
|
||||
method.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('content_ratings')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def credits(self, **kwargs):
|
||||
"""
|
||||
Get the credits (cast and crew) that have been added to a TV show.
|
||||
|
||||
Args:
|
||||
language: (optional) ISO 639 code.
|
||||
append_to_response: (optional) Comma separated, any collection
|
||||
method.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('credits')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def episode_groups(self, **kwargs):
|
||||
"""
|
||||
Get all of the episode groups that have been created for a TV show.
|
||||
With a group ID you can call the get TV episode group details method.
|
||||
|
||||
Args:
|
||||
language: (optional) ISO 639 code.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('episode_groups')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def external_ids(self, **kwargs):
|
||||
"""
|
||||
Get the external ids for a TV show. We currently support the following
|
||||
external sources.
|
||||
|
||||
Media Databases: IMDb ID, TVDB ID, Freebase MID*, Freebase ID*, TVRage
|
||||
ID*
|
||||
Social IDs: Facebook, Instagram, Twitter
|
||||
|
||||
*Defunct or no longer available as a service.
|
||||
|
||||
Args:
|
||||
language: (optional) ISO 639 code.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('external_ids')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def images(self, **kwargs):
|
||||
"""
|
||||
Get the images that belong to a TV show.
|
||||
|
||||
Querying images with a language parameter will filter the results. If
|
||||
you want to include a fallback language (especially useful for
|
||||
backdrops) you can use the include_image_language parameter. This
|
||||
should be a comma seperated value like so:
|
||||
include_image_language=en,null.
|
||||
|
||||
Args:
|
||||
language: (optional) ISO 639 code.
|
||||
include_image_language: (optional) Comma separated, a valid
|
||||
ISO 69-1.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('images')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def keywords(self, **kwargs):
|
||||
"""
|
||||
Get the keywords that have been added to a TV show.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('keywords')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def recommendations(self, **kwargs):
|
||||
"""
|
||||
Get the list of TV show recommendations for this item.
|
||||
|
||||
Args:
|
||||
page: (optional) Minimum value of 1. Expected value is an integer.
|
||||
language: (optional) ISO 639-1 code.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('recommendations')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def reviews(self, **kwargs):
|
||||
"""
|
||||
Get the reviews for a TV show.
|
||||
|
||||
Args:
|
||||
page: (optional) Minimum value of 1. Expected value is an integer.
|
||||
language: (optional) ISO 639-1 code.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('reviews')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def screened_theatrically(self, **kwargs):
|
||||
"""
|
||||
Get a list of seasons or episodes that have been screened in a film
|
||||
festival or theatre.
|
||||
|
||||
Args:
|
||||
page: (optional) Minimum value of 1. Expected value is an integer.
|
||||
language: (optional) ISO 639-1 code.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('screened_theatrically')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def similar(self, **kwargs):
|
||||
"""
|
||||
Get a list of similar TV shows. These items are assembled by looking at
|
||||
keywords and genres.
|
||||
|
||||
Args:
|
||||
page: (optional) Minimum value of 1. Expected value is an integer.
|
||||
language: (optional) ISO 639-1 code.
|
||||
append_to_response: (optional) Comma separated, any TV method.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('similar')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def translations(self, **kwargs):
|
||||
"""
|
||||
Get a list of the translations that exist for a TV show.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('translations')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def videos(self, **kwargs):
|
||||
"""
|
||||
Get the videos that have been added to a TV show.
|
||||
|
||||
Args:
|
||||
language: (optional) ISO 639 code.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('videos')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def rating(self, **kwargs):
|
||||
"""
|
||||
Rate a TV show.
|
||||
|
||||
A valid session or guest session ID is required. You can read more
|
||||
about how this works at
|
||||
https://developers.themoviedb.org/3/authentication/how-do-i-generate-a-session-id.
|
||||
|
||||
Args:
|
||||
session_id: see Authentication.
|
||||
guest_session_id: see Authentication.
|
||||
value: Rating value.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('rating')
|
||||
|
||||
payload = {
|
||||
'value': kwargs.pop('value', None),
|
||||
}
|
||||
|
||||
response = self._POST(path, kwargs, payload)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def latest(self, **kwargs):
|
||||
"""
|
||||
Get the most newly created TV show. This is a live response and will
|
||||
continuously change.
|
||||
|
||||
Args:
|
||||
language: (optional) ISO 639 code.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('latest')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def airing_today(self, **kwargs):
|
||||
"""
|
||||
Get a list of TV shows that are airing today. This query is purely day
|
||||
based as we do not currently support airing times.
|
||||
|
||||
You can specify a timezone to offset the day calculation. Without a
|
||||
specified timezone, this query defaults to EST (Eastern Time
|
||||
UTC-05:00).
|
||||
|
||||
Args:
|
||||
page: (optional) Minimum 1, maximum 1000.
|
||||
language: (optional) ISO 639 code.
|
||||
timezone: (optional) Valid value from the list of timezones.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_path('airing_today')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def on_the_air(self, **kwargs):
|
||||
"""
|
||||
Get a list of shows that are currently on the air.
|
||||
|
||||
This query looks for any TV show that has an episode with an air date
|
||||
in the next 7 days.
|
||||
|
||||
Args:
|
||||
page: (optional) Minimum 1, maximum 1000.
|
||||
language: (optional) ISO 639 code.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_path('on_the_air')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def popular(self, **kwargs):
|
||||
"""
|
||||
Get a list of the current popular TV shows on TMDb. This list updates
|
||||
daily.
|
||||
|
||||
Args:
|
||||
page: (optional) Minimum 1, maximum 1000.
|
||||
language: (optional) ISO 639 code.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_path('popular')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def top_rated(self, **kwargs):
|
||||
"""
|
||||
Get a list of the top rated TV shows on TMDb.
|
||||
|
||||
Args:
|
||||
page: (optional) Minimum 1, maximum 1000.
|
||||
language: (optional) ISO 639 code.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_path('top_rated')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
|
||||
class TV_Seasons(TMDB):
|
||||
"""
|
||||
TV Seasons functionality.
|
||||
|
||||
See: https://developers.themoviedb.org/3/tv-seasons
|
||||
"""
|
||||
BASE_PATH = 'tv/{tv_id}/season/{season_number}'
|
||||
URLS = {
|
||||
'info': '',
|
||||
'account_states': '/account_states',
|
||||
'credits': '/credits',
|
||||
'external_ids': '/external_ids',
|
||||
'images': '/images',
|
||||
'videos': '/videos',
|
||||
}
|
||||
|
||||
def __init__(self, tv_id, season_number):
|
||||
super(TV_Seasons, self).__init__()
|
||||
self.tv_id = tv_id
|
||||
self.season_number = season_number
|
||||
|
||||
def info(self, **kwargs):
|
||||
"""
|
||||
Get the TV season details by id.
|
||||
|
||||
Supports append_to_response. Read more about this at
|
||||
https://developers.themoviedb.org/3/getting-started/append-to-response.
|
||||
|
||||
Args:
|
||||
language: (optional) ISO 639 code.
|
||||
append_to_response: (optional) Comma separated, any TV series
|
||||
method.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_tv_id_season_number_path('info')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def account_states(self, **kwargs):
|
||||
"""
|
||||
Returns all of the user ratings for the season's episodes.
|
||||
|
||||
Args:
|
||||
language: (optional) ISO 639 code.
|
||||
append_to_response: (optional) Comma separated, any TV series
|
||||
method.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_tv_id_season_number_path('account_states')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def credits(self, **kwargs):
|
||||
"""
|
||||
Get the credits for TV season.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_tv_id_season_number_path('credits')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def external_ids(self, **kwargs):
|
||||
"""
|
||||
Get the external ids for a TV season. We currently support the
|
||||
following external sources.
|
||||
|
||||
Media Databases: TVDB ID, Freebase MID*, Freebase ID*, TVRage ID*
|
||||
|
||||
*Defunct or no longer available as a service.
|
||||
|
||||
Args:
|
||||
language: (optional) ISO 639 code.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_tv_id_season_number_path('external_ids')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def images(self, **kwargs):
|
||||
"""
|
||||
Get the images that belong to a TV season.
|
||||
|
||||
Querying images with a language parameter will filter the results. If
|
||||
you want to include a fallback language (especially useful for
|
||||
backdrops) you can use the include_image_language parameter. This
|
||||
should be a comma seperated value like so:
|
||||
include_image_language=en,null.
|
||||
|
||||
Args:
|
||||
language: (optional) ISO 639 code.
|
||||
include_image_language: (optional) Comma separated, a valid
|
||||
ISO 69-1.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_tv_id_season_number_path('images')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def videos(self, **kwargs):
|
||||
"""
|
||||
Get the videos that have been added to a TV season.
|
||||
|
||||
Args:
|
||||
language: (optional) ISO 639 code.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_tv_id_season_number_path('videos')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
|
||||
class TV_Episodes(TMDB):
|
||||
"""
|
||||
TV Episodes functionality.
|
||||
|
||||
See: https://developers.themoviedb.org/3/tv-episodes
|
||||
"""
|
||||
BASE_PATH = 'tv/{tv_id}/season/{season_number}/episode/{episode_number}'
|
||||
URLS = {
|
||||
'info': '',
|
||||
'account_states': '/account_states',
|
||||
'credits': '/credits',
|
||||
'external_ids': '/external_ids',
|
||||
'images': '/images',
|
||||
'translations': '/translations',
|
||||
'rating': '/rating',
|
||||
'videos': '/videos',
|
||||
}
|
||||
|
||||
def __init__(self, tv_id, season_number, episode_number):
|
||||
super(TV_Episodes, self).__init__()
|
||||
self.tv_id = tv_id
|
||||
self.season_number = season_number
|
||||
self.episode_number = episode_number
|
||||
|
||||
def info(self, **kwargs):
|
||||
"""
|
||||
Get the TV episode details by id.
|
||||
|
||||
Supports append_to_response. Read more about this at
|
||||
https://developers.themoviedb.org/3/getting-started/append-to-response.
|
||||
|
||||
Args:
|
||||
language: (optional) ISO 639 code.
|
||||
append_to_response: (optional) Comma separated, any TV series
|
||||
method.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_tv_id_season_number_episode_number_path('info')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def account_states(self, **kwargs):
|
||||
"""
|
||||
Get your rating for an episode.
|
||||
|
||||
Args:
|
||||
language: (optional) ISO 639 code.
|
||||
append_to_response: (optional) Comma separated, any TV series
|
||||
method.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_tv_id_season_number_episode_number_path('account_states')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def credits(self, **kwargs):
|
||||
"""
|
||||
Get the credits (cast, crew and guest stars) for a TV episode.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_tv_id_season_number_episode_number_path('credits')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def external_ids(self, **kwargs):
|
||||
"""
|
||||
Get the external ids for a TV episode. We currently support the
|
||||
following external sources.
|
||||
|
||||
External Sources: IMDb ID, TVDB ID, Freebase MID*, Freebase ID*, TVRage
|
||||
ID*
|
||||
|
||||
*Defunct or no longer available as a service.
|
||||
|
||||
Args:
|
||||
language: (optional) ISO 639 code.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_tv_id_season_number_episode_number_path(
|
||||
'external_ids')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def images(self, **kwargs):
|
||||
"""
|
||||
Get the images that belong to a TV episode.
|
||||
|
||||
Querying images with a language parameter will filter the results. If
|
||||
you want to include a fallback language (especially useful for
|
||||
backdrops) you can use the include_image_language parameter. This
|
||||
should be a comma seperated value like so:
|
||||
include_image_language=en,null.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_tv_id_season_number_episode_number_path('images')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def translations(self, **kwargs):
|
||||
"""
|
||||
Get the translation data for an episode.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_tv_id_season_number_episode_number_path('translations')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def rating(self, **kwargs):
|
||||
"""
|
||||
Rate a TV episode.
|
||||
|
||||
A valid session or guest session ID is required. You can read more
|
||||
about how this works at
|
||||
https://developers.themoviedb.org/3/authentication/how-do-i-generate-a-session-id.
|
||||
|
||||
Args:
|
||||
session_id: see Authentication.
|
||||
guest_session_id: see Authentication.
|
||||
value: Rating value.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_tv_id_season_number_episode_number_path('rating')
|
||||
|
||||
payload = {
|
||||
'value': kwargs.pop('value', None),
|
||||
}
|
||||
|
||||
response = self._POST(path, kwargs, payload)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def videos(self, **kwargs):
|
||||
"""
|
||||
Get the videos that have been added to a TV episode.
|
||||
|
||||
Args:
|
||||
language: (optional) ISO 639 code.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_tv_id_season_number_episode_number_path('videos')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
|
||||
class TV_Episode_Groups(TMDB):
|
||||
"""
|
||||
TV Episode Groups functionality.
|
||||
|
||||
See: https://developers.themoviedb.org/3/tv-episode-groups
|
||||
"""
|
||||
BASE_PATH = 'tv/episode_group'
|
||||
URLS = {
|
||||
'info': '/{id}',
|
||||
}
|
||||
|
||||
def __init__(self, id):
|
||||
super(TV_Episode_Groups, self).__init__()
|
||||
self.id = id
|
||||
|
||||
def info(self, **kwargs):
|
||||
"""
|
||||
Get the details of a TV episode group. Groups support 7 different types
|
||||
which are enumerated as the following:
|
||||
1. Original air date
|
||||
2. Absolute
|
||||
3. DVD
|
||||
4. Digital
|
||||
5. Story arc
|
||||
6. Production
|
||||
7. TV
|
||||
|
||||
Args:
|
||||
language: (optional) ISO 639 code.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('info')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
|
||||
class TV_Changes(TMDB):
|
||||
"""
|
||||
Changes functionality for TV Series, Season and Episode.
|
||||
|
||||
See: https://developers.themoviedb.org/3/tv/get-tv-changes
|
||||
https://developers.themoviedb.org/3/tv-seasons/get-tv-season-changes
|
||||
https://developers.themoviedb.org/3/tv-episodes/get-tv-episode-changes
|
||||
"""
|
||||
BASE_PATH = 'tv'
|
||||
URLS = {
|
||||
'series': '/{id}/changes', # id => tv_id
|
||||
'season': '/season/{id}/changes', # id => season_id
|
||||
'episode': '/episode/{id}/changes', # id => episode_id
|
||||
}
|
||||
|
||||
def __init__(self, id=0):
|
||||
super(TV_Changes, self).__init__()
|
||||
self.id = id
|
||||
|
||||
def series(self, **kwargs):
|
||||
"""
|
||||
Get the changes for a TV show. By default only the last 24 hours are returned.
|
||||
|
||||
You can query up to 14 days in a single query by using the start_date
|
||||
and end_date query parameters.
|
||||
|
||||
TV show changes are different than movie changes in that there are some
|
||||
edits on seasons and episodes that will create a change entry at the
|
||||
show level. These can be found under the season and episode keys. These
|
||||
keys will contain a series_id and episode_id. You can use the season
|
||||
changes and episode changes methods to look these up individually.
|
||||
|
||||
Args:
|
||||
start_date: (optional) Expected format is 'YYYY-MM-DD'.
|
||||
end_date: (optional) Expected format is 'YYYY-MM-DD'.
|
||||
page: (optional) Minimum 1, maximum 1000.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('series')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def season(self, **kwargs):
|
||||
"""
|
||||
Get the changes for a TV season. By default only the last 24 hours are returned.
|
||||
|
||||
You can query up to 14 days in a single query by using the start_date
|
||||
and end_date query parameters.
|
||||
|
||||
Args:
|
||||
start_date: (optional) Expected format is 'YYYY-MM-DD'.
|
||||
end_date: (optional) Expected format is 'YYYY-MM-DD'.
|
||||
page: (optional) Minimum 1, maximum 1000.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('season')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def episode(self, **kwargs):
|
||||
"""
|
||||
Get the changes for a TV episode. By default only the last 24 hours are returned.
|
||||
|
||||
You can query up to 14 days in a single query by using the start_date
|
||||
and end_date query parameters.
|
||||
|
||||
Args:
|
||||
start_date: (optional) Expected format is 'YYYY-MM-DD'.
|
||||
end_date: (optional) Expected format is 'YYYY-MM-DD'.
|
||||
page: (optional) Minimum 1, maximum 1000.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('episode')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
|
||||
class Networks(TMDB):
|
||||
"""
|
||||
Networks functionality.
|
||||
|
||||
See: https://developers.themoviedb.org/3/networks
|
||||
"""
|
||||
BASE_PATH = 'network'
|
||||
URLS = {
|
||||
'info': '/{id}',
|
||||
'alternative_names': '/{id}/alternative_names',
|
||||
'images': '/{id}/images',
|
||||
}
|
||||
|
||||
def __init__(self, id):
|
||||
super(Networks, self).__init__()
|
||||
self.id = id
|
||||
|
||||
def info(self, **kwargs):
|
||||
"""
|
||||
Get the details of a network.
|
||||
|
||||
Returns:
|
||||
A dict respresentation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('info')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def alternative_names(self, **kwargs):
|
||||
"""
|
||||
Get the alternative names of a network.
|
||||
|
||||
Args:
|
||||
|
||||
Returns:
|
||||
A dict representation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('alternative_names')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
||||
|
||||
def images(self, **kwargs):
|
||||
"""
|
||||
Get a TV network logos by id.
|
||||
|
||||
There are two image formats that are supported for networks, PNG's and
|
||||
SVG's. You can see which type the original file is by looking at the
|
||||
file_type field. We prefer SVG's as they are resolution independent and
|
||||
as such, the width and height are only there to reflect the original
|
||||
asset that was uploaded. An SVG can be scaled properly beyond those
|
||||
dimensions if you call them as a PNG.
|
||||
|
||||
For more information about how SVG's and PNG's can be used, take a read
|
||||
through https://developers.themoviedb.org/3/getting-started/images.
|
||||
|
||||
Args:
|
||||
|
||||
Returns:
|
||||
A dict representation of the JSON returned from the API.
|
||||
"""
|
||||
path = self._get_id_path('images')
|
||||
|
||||
response = self._GET(path, kwargs)
|
||||
self._set_attrs_to_values(response)
|
||||
return response
|
Loading…
Reference in new issue