diff --git a/ext/readme.md b/ext/readme.md
index 72da760a4e..bc5cba778a 100644
--- a/ext/readme.md
+++ b/ext/readme.md
@@ -55,7 +55,7 @@ ext | `six` | [1.15.0](https://pypi.org/project/six/1.15.0/) | **`medusa`**, `ad
ext | **`soupsieve`** | [1.9.6](https://pypi.org/project/soupsieve/1.9.6/) | `beautifulsoup4` | -
ext | **`stevedore`** | [1.30.1](https://pypi.org/project/stevedore/1.30.1/) | `subliminal` | -
ext | **`subliminal`** | [2.1.0](https://pypi.org/project/subliminal/2.1.0/) | **`medusa`** | -
-ext | **`tmdbsimple`** | [2.2.11](https://pypi.org/project/tmdbsimple/2.2.11/) | **`medusa`** | -
+ext | **`tmdbsimple`** | [2.7.0](https://pypi.org/project/tmdbsimple/2.7.0/) | **`medusa`** | -
ext | **`tornado`** | [5.1.1](https://pypi.org/project/tornado/5.1.1/) | **`medusa`**, `tornroutes` | -
ext | **`tornroutes`** | [0.5.1](https://pypi.org/project/tornroutes/0.5.1/) | **`medusa`** | -
ext | `trans` | [2.1.0](https://pypi.org/project/trans/2.1.0/) | `imdbpie` | File: `trans.py`
diff --git a/ext/tmdbsimple/__init__.py b/ext/tmdbsimple/__init__.py
index 2099330faf..b7d8a53439 100644
--- a/ext/tmdbsimple/__init__.py
+++ b/ext/tmdbsimple/__init__.py
@@ -4,11 +4,11 @@
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
+*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
@@ -17,25 +17,39 @@
"""
__title__ = 'tmdbsimple'
-__version__ = '2.2.11'
+__version__ = '2.7.0'
__author__ = 'Celia Oakley'
__copyright__ = 'Copyright (c) 2013-2020 Celia Oakley'
__license__ = 'GPLv3'
import os
+import requests
from .account import Account, Authentication, GuestSessions, Lists
from .base import APIKeyError
from .changes import Changes
-from .configuration import Configuration, Certifications, Timezones
+from .configuration import Configuration, Certifications
from .discover import Discover
-from .find import Find
+from .find import Find, Trending
from .genres import Genres
from .movies import Movies, Collections, Companies, Keywords, Reviews
-from .people import People, Credits, Jobs
+from .people import People, Credits
from .search import Search
-from .tv import TV, TV_Seasons, TV_Episodes, TV_Changes, Networks
-
+from .tv import TV, TV_Seasons, TV_Episodes, TV_Episode_Groups, TV_Changes, Networks
+
+__all__ = ['Account', 'Authentication', 'GuestSessions', 'Lists',
+ 'APIKeyError',
+ 'Changes',
+ 'Configuration', 'Certifications',
+ 'Discover',
+ 'Find', 'Trending',
+ 'Genres',
+ 'Movies', 'Collections', 'Companies', 'Keywords', 'Reviews',
+ 'People', 'Credits'
+ 'Search',
+ 'TV', 'TV_Seasons', 'TV_Episodes', 'TV_Episode_Groups', 'TV_Changes', 'Networks'
+ ]
API_KEY = os.environ.get('TMDB_API_KEY', None)
API_VERSION = '3'
+REQUESTS_SESSION = requests.Session()
diff --git a/ext/tmdbsimple/account.py b/ext/tmdbsimple/account.py
index e1ba13c1d4..b1da44a2d7 100644
--- a/ext/tmdbsimple/account.py
+++ b/ext/tmdbsimple/account.py
@@ -3,7 +3,7 @@
"""
tmdbsimple.account
~~~~~~~~~~~~~~~~~~
-This module implements the Account, Authentication, and Lists functionality
+This module implements the Account, Authentication, and Lists functionality
of tmdbsimple.
Created by Celia Oakley on 2013-10-31.
@@ -25,7 +25,7 @@ class Account(TMDB):
BASE_PATH = 'account'
URLS = {
'info': '',
- 'lists': '/{id}/lists',
+ 'lists': '/{id}/lists',
'favorite_movies': '/{id}/favorite/movies',
'favorite_tv': '/{id}/favorite/tv',
'favorite': '/{id}/favorite',
@@ -43,9 +43,9 @@ def __init__(self, session_id):
def info(self, **kwargs):
"""
- Get the basic information for an account.
+ Get your account details.
- Call this method first, before calling other Account methods.
+ Args:
Returns:
A dict respresentation of the JSON returned from the API.
@@ -57,14 +57,15 @@ def info(self, **kwargs):
self.id = response['id']
self._set_attrs_to_values(response)
return response
-
+
def lists(self, **kwargs):
"""
- Get the lists that you have created and marked as a favorite.
+ 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.
+ page: (optional) Minimum 1, maximum 1000, default 1.
Returns:
A dict respresentation of the JSON returned from the API.
@@ -78,12 +79,12 @@ def lists(self, **kwargs):
def favorite_movies(self, **kwargs):
"""
- Get the list of favorite movies for an account.
+ 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.
+ sort_by: (optional) Allowed Values: created_at.asc, created_at.desc
+ page: (optional) Minimum 1, maximum 1000, default 1.
Returns:
A dict respresentation of the JSON returned from the API.
@@ -97,12 +98,12 @@ def favorite_movies(self, **kwargs):
def favorite_tv(self, **kwargs):
"""
- Get the list of favorite TV series for an account.
+ 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.
+ sort_by: (optional) Allowed Values: created_at.asc, created_at.desc
+ page: (optional) Minimum 1, maximum 1000, default 1.
Returns:
A dict respresentation of the JSON returned from the API.
@@ -116,7 +117,7 @@ def favorite_tv(self, **kwargs):
def favorite(self, **kwargs):
"""
- Add or remove a movie to an accounts favorite list.
+ This method allows you to mark a movie or TV show as a favorite item.
Args:
media_type: 'movie' | 'tv'
@@ -130,8 +131,8 @@ def favorite(self, **kwargs):
kwargs.update({'session_id': self.session_id})
payload = {
- 'media_type': kwargs.pop('media_type', None),
- 'media_id': kwargs.pop('media_id', None),
+ 'media_type': kwargs.pop('media_type', None),
+ 'media_id': kwargs.pop('media_id', None),
'favorite': kwargs.pop('favorite', None),
}
@@ -141,12 +142,12 @@ def favorite(self, **kwargs):
def rated_movies(self, **kwargs):
"""
- Get the list of rated movies (and associated rating) for an account.
+ 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.
+ language: (optional) ISO 639-1 value.
+ sort_by: (optional) Allowed Values: created_at.asc, created_at.desc
+ page: (optional) Minimum 1, maximum 1000, default 1.
Returns:
A dict respresentation of the JSON returned from the API.
@@ -160,12 +161,12 @@ def rated_movies(self, **kwargs):
def rated_tv(self, **kwargs):
"""
- Get the list of rated TV shows (and associated rating) for an account.
+ 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.
+ language: (optional) ISO 639-1 value.
+ sort_by: (optional) Allowed Values: created_at.asc, created_at.desc
+ page: (optional) Minimum 1, maximum 1000, default 1.
Returns:
A dict respresentation of the JSON returned from the API.
@@ -182,9 +183,9 @@ 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.
+ language: (optional) ISO 639-1 value.
+ sort_by: (optional) Allowed Values: created_at.asc, created_at.desc
+ page: (optional) Minimum 1, maximum 1000, default 1.
Returns:
A dict respresentation of the JSON returned from the API.
@@ -198,12 +199,12 @@ def rated_tv_episodes(self, **kwargs):
def watchlist_movies(self, **kwargs):
"""
- Get the list of movies on an account watchlist.
+ 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.
+ language: (optional) ISO 639-1 value.
+ sort_by: (optional) Allowed Values: created_at.asc, created_at.desc
+ page: (optional) Minimum 1, maximum 1000, default 1.
Returns:
A dict respresentation of the JSON returned from the API.
@@ -217,12 +218,12 @@ def watchlist_movies(self, **kwargs):
def watchlist_tv(self, **kwargs):
"""
- Get the list of TV series on an account watchlist.
+ 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.
+ language: (optional) ISO 639-1 value.
+ sort_by: (optional) Allowed Values: created_at.asc, created_at.desc
+ page: (optional) Minimum 1, maximum 1000, default 1.
Returns:
A dict respresentation of the JSON returned from the API.
@@ -236,7 +237,7 @@ def watchlist_tv(self, **kwargs):
def watchlist(self, **kwargs):
"""
- Add or remove a movie to an accounts watch list.
+ Add a movie or TV show to your watchlist.
Args:
media_type: 'movie' | 'tv'
@@ -250,8 +251,8 @@ def watchlist(self, **kwargs):
kwargs.update({'session_id': self.session_id})
payload = {
- 'media_type': kwargs.pop('media_type', None),
- 'media_id': kwargs.pop('media_id', None),
+ 'media_type': kwargs.pop('media_type', None),
+ 'media_id': kwargs.pop('media_id', None),
'watchlist': kwargs.pop('watchlist', None),
}
@@ -259,6 +260,7 @@ def watchlist(self, **kwargs):
self._set_attrs_to_values(response)
return response
+
class Authentication(TMDB):
"""
Authentication functionality.
@@ -268,48 +270,53 @@ class Authentication(TMDB):
"""
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',
- 'session_new': '/session/new',
- 'guest_session_new': '/guest_session/new',
+ 'session_delete': '/session',
}
- def token_new(self, **kwargs):
+ def guest_session_new(self, **kwargs):
"""
- Generate a valid request token for user based authentication.
+ 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).
- A request token is required to ask the user for permission to
- access their account.
+ 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.
- After obtaining the request_token, either:
- (1) Direct your user to:
- https://www.themoviedb.org/authenticate/REQUEST_TOKEN
- or:
- (2) Call token_validate_with_login() below.
+ If a guest session is not used for the first time within 24 hours,
+ it will be automatically deleted.
+
+ Args:
Returns:
A dict respresentation of the JSON returned from the API.
"""
- path = self._get_path('token_new')
+ path = self._get_path('guest_session_new')
response = self._GET(path, kwargs)
self._set_attrs_to_values(response)
return response
- def token_validate_with_login(self, **kwargs):
+ def token_new(self, **kwargs):
"""
- Authenticate a user with a TMDb username and password. The user
- must have a verified email address and be registered on TMDb.
+ 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).
Args:
- request_token: The token you generated for the user to approve.
- username: The user's username on TMDb.
- password: The user's password on TMDb.
Returns:
A dict respresentation of the JSON returned from the API.
"""
- path = self._get_path('token_validate_with_login')
+ path = self._get_path('token_new')
response = self._GET(path, kwargs)
self._set_attrs_to_values(response)
@@ -317,9 +324,10 @@ def token_validate_with_login(self, **kwargs):
def session_new(self, **kwargs):
"""
- Generate a session id for user based authentication.
-
- A session id is required in order to use any of the write methods.
+ 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.
@@ -335,19 +343,56 @@ def session_new(self, **kwargs):
self._set_attrs_to_values(response)
return response
- def guest_session_new(self, **kwargs):
+ def token_validate_with_login(self, **kwargs):
"""
- Generate a guest session id.
+ 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('guest_session_new')
+ path = self._get_path('token_validate_with_login')
response = self._GET(path, kwargs)
self._set_attrs_to_values(response)
return response
+ def session_delete(self, **kwargs):
+ """
+ If you would like to delete (or "logout") from a session, call this
+ method with a valid session ID.
+
+ Args:
+
+ Returns:
+ A dict respresentation of the JSON returned from the API.
+ """
+ path = self._get_path('session_delete')
+
+ payload = {
+ 'session_id': kwargs.pop('session_id', None),
+ }
+
+ response = self._DELETE(path, kwargs, payload)
+ self._set_attrs_to_values(response)
+ return response
+
+
class GuestSessions(TMDB):
"""
Guest Sessions functionality.
@@ -356,7 +401,9 @@ class GuestSessions(TMDB):
"""
BASE_PATH = 'guest_session'
URLS = {
- 'rated_movies': '/{guest_session_id}/rated_movies',
+ '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):
@@ -365,12 +412,11 @@ def __init__(self, guest_session_id=0):
def rated_movies(self, **kwargs):
"""
- Get a list of rated moview for a specific guest session id.
+ 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.
+ sort_by: (optional) Allowed Values: created_at.asc, created_at.desc
Returns:
A dict respresentation of the JSON returned from the API.
@@ -380,7 +426,41 @@ def rated_movies(self, **kwargs):
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:
+ language: (optional) ISO 639-1 code.
+ sort_by: (optional) Allowed Values: created_at.asc, created_at.desc
+
+ 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:
+ language: (optional) ISO 639-1 code.
+ sort_by: (optional) Allowed Values: created_at.asc, created_at.desc
+
+ 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):
"""
@@ -391,11 +471,12 @@ class Lists(TMDB):
BASE_PATH = 'list'
URLS = {
'info': '/{id}',
- 'item_status': '/{id}/item_status',
- 'create_list': '',
+ 'item_status': '/{id}/item_status',
+ 'list_create': '',
'add_item': '/{id}/add_item',
'remove_item': '/{id}/remove_item',
- 'clear': '/{id}/clear',
+ 'list_clear': '/{id}/clear',
+ 'list_delete': '/{id}',
}
def __init__(self, id=0, session_id=0):
@@ -405,7 +486,10 @@ def __init__(self, id=0, session_id=0):
def info(self, **kwargs):
"""
- Get a list by id.
+ Get the details of a list.
+
+ Args:
+ language: (optional) ISO 639-1 code.
Returns:
A dict respresentation of the JSON returned from the API.
@@ -418,10 +502,11 @@ def info(self, **kwargs):
def item_status(self, **kwargs):
"""
- Check to see if a movie id is already added to a list.
+ 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.
+ movie_id: The id of the movie. Minimum 1.
Returns:
A dict respresentation of the JSON returned from the API.
@@ -432,11 +517,9 @@ def item_status(self, **kwargs):
self._set_attrs_to_values(response)
return response
- def create_list(self, **kwargs):
+ def list_create(self, **kwargs):
"""
- Create a new list.
-
- A valid session id is required.
+ Create a list.
Args:
name: Name of the list.
@@ -446,28 +529,26 @@ def create_list(self, **kwargs):
Returns:
A dict respresentation of the JSON returned from the API.
"""
- path = self._get_path('create_list')
+ path = self._get_path('list_create')
kwargs.update({'session_id': self.session_id})
payload = {
- 'name': kwargs.pop('name', None),
+ 'name': kwargs.pop('name', None),
'description': kwargs.pop('description', None),
+ 'language': kwargs.pop('language', None),
}
- if 'language' in kwargs:
- payload['language'] = kwargs['language']
response = self._POST(path, kwargs, payload)
self._set_attrs_to_values(response)
+ self.id = self.list_id
return response
def add_item(self, **kwargs):
"""
- Add new movies to a list that the user created.
-
- A valid session id is required.
+ Add a movie to a list.
Args:
- media_id: A movie id.
+ media_id: A movie id. Minimum 1.
Returns:
A dict respresentation of the JSON returned from the API.
@@ -476,21 +557,19 @@ def add_item(self, **kwargs):
kwargs.update({'session_id': self.session_id})
payload = {
- 'media_id': kwargs.pop('media_id', None),
+ '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):
"""
- Delete movies from a list that the user created.
-
- A valid session id is required.
+ Remove a movie from a list.
Args:
- media_id: A movie id.
+ media_id: A movie id. Minimum 1.
Returns:
A dict respresentation of the JSON returned from the API.
@@ -499,19 +578,16 @@ def remove_item(self, **kwargs):
kwargs.update({'session_id': self.session_id})
payload = {
- 'media_id': kwargs.pop('media_id', None),
+ '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):
+ def list_clear(self, **kwargs):
"""
- Clears all of the items within a list. This is an irreversible action
- and should be treated with caution.
-
- A valid session id is required.
+ Clear all of the items from a list.
Args:
confirm: True (do it) | False (don't do it)
@@ -519,7 +595,7 @@ def clear_list(self, **kwargs):
Returns:
A dict respresentation of the JSON returned from the API.
"""
- path = self._get_id_path('clear')
+ path = self._get_id_path('list_clear')
kwargs.update({'session_id': self.session_id})
payload = {}
@@ -527,3 +603,20 @@ def clear_list(self, **kwargs):
response = self._POST(path, kwargs, payload)
self._set_attrs_to_values(response)
return response
+
+ def list_delete(self, **kwargs):
+ """
+ Delete a list.
+
+ Args:
+ None
+
+ Returns:
+ A dict respresentation of the JSON returned from the API.
+ """
+ path = self._get_id_path('list_delete')
+ kwargs.update({'session_id': self.session_id})
+
+ response = self._DELETE(path, kwargs)
+ self._set_attrs_to_values(response)
+ return response
diff --git a/ext/tmdbsimple/base.py b/ext/tmdbsimple/base.py
index 168c4259d8..61640d0ed4 100644
--- a/ext/tmdbsimple/base.py
+++ b/ext/tmdbsimple/base.py
@@ -12,7 +12,6 @@
"""
import json
-import requests
class APIKeyError(Exception):
@@ -27,9 +26,10 @@ class TMDB(object):
URLS = {}
def __init__(self):
- from . import API_VERSION
+ from . import API_VERSION, REQUESTS_SESSION
self.base_uri = 'https://api.themoviedb.org'
self.base_uri += '/{version}'.format(version=API_VERSION)
+ self.session = REQUESTS_SESSION
def _get_path(self, key):
return self.BASE_PATH + self.URLS[key]
@@ -40,17 +40,21 @@ def _get_id_path(self, key):
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)
+ 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,
+ 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):
@@ -76,8 +80,8 @@ 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,
+ response = self.session.request(
+ method, url, params=params,
data=json.dumps(payload) if payload else payload,
headers=self.headers)
@@ -108,4 +112,3 @@ def _set_attrs_to_values(self, response={}):
for key in response.keys():
if not hasattr(self, key) or not callable(getattr(self, key)):
setattr(self, key, response[key])
-
diff --git a/ext/tmdbsimple/changes.py b/ext/tmdbsimple/changes.py
index bbcf5736f3..674ef83b26 100644
--- a/ext/tmdbsimple/changes.py
+++ b/ext/tmdbsimple/changes.py
@@ -13,6 +13,7 @@
from .base import TMDB
+
class Changes(TMDB):
"""
Changes functionality.
@@ -22,18 +23,23 @@ class Changes(TMDB):
BASE_PATH = ''
URLS = {
'movie': 'movie/changes',
- 'person': 'person/changes',
'tv': 'tv/changes',
+ 'person': 'person/changes',
}
def movie(self, **kwargs):
"""
- Get a list of movie ids that have been edited.
+ 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'.
+ page: (optional) Minimum 1, maximum 1000, default 1.
Returns:
A dict respresentation of the JSON returned from the API.
@@ -44,37 +50,47 @@ def movie(self, **kwargs):
self._set_attrs_to_values(response)
return response
- def person(self, **kwargs):
+ def tv(self, **kwargs):
"""
- Get a list of people ids that have been edited.
+ 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'.
+ page: (optional) Minimum 1, maximum 1000, default 1.
Returns:
A dict respresentation of the JSON returned from the API.
"""
- path = self._get_path('person')
+ path = self._get_path('tv')
response = self._GET(path, kwargs)
self._set_attrs_to_values(response)
return response
- def tv(self, **kwargs):
+ def person(self, **kwargs):
"""
- Get a list of TV show ids that have been edited.
+ 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'.
+ page: (optional) Minimum 1, maximum 1000, default 1.
Returns:
A dict respresentation of the JSON returned from the API.
"""
- path = self._get_path('tv')
+ path = self._get_path('person')
response = self._GET(path, kwargs)
self._set_attrs_to_values(response)
diff --git a/ext/tmdbsimple/configuration.py b/ext/tmdbsimple/configuration.py
index f58f4d0755..681bd52b29 100644
--- a/ext/tmdbsimple/configuration.py
+++ b/ext/tmdbsimple/configuration.py
@@ -4,8 +4,8 @@
tmdbsimple.configuration
~~~~~~~~~~~~~~~~~~~~~~~~
-This module implements the Configuration, Certifications, and Timezones
-functionality of tmdbsimple.
+This module implements the Configuration and Certifications functionality of
+tmdbsimple.
Created by Celia Oakley on 2013-10-31.
@@ -34,7 +34,27 @@ class Configuration(TMDB):
def info(self, **kwargs):
"""
- Get the system wide configuration info.
+ Get the system wide configuration information. Some elements of the API
+ require some knowledge of this configuration data. The purpose of this
+ is to try and keep the actual API responses as light as possible. It is
+ recommended you cache this data within your application and check for
+ updates every few days.
+
+ This method currently holds the data relevant to building image URLs as
+ well as the change key map.
+
+ To build an image URL, you will need 3 pieces of data. The base_url,
+ size and file_path. Simply combine them all and you will have a fully
+ qualified URL. Here’s an example URL:
+
+ https://image.tmdb.org/t/p/w500/8uO0gUM8aNqYLs1OsTBQiXu0fEv.jpg
+
+ The configuration method also contains the list of change keys which
+ can be useful if you are building an app that consumes data from the
+ change feed.
+
+ Args:
+ None
Returns:
A dict respresentation of the JSON returned from the API.
@@ -49,6 +69,9 @@ def countries(self, **kwargs):
"""
Get the list of countries (ISO 3166-1 tags) used throughout TMDb.
+ Args:
+ None
+
Returns:
A dict respresentation of the JSON returned from the API.
"""
@@ -62,6 +85,9 @@ def jobs(self, **kwargs):
"""
Get a list of the jobs and departments we use on TMDb.
+ Args:
+ None
+
Returns:
A dict respresentation of the JSON returned from the API.
"""
@@ -75,6 +101,9 @@ def languages(self, **kwargs):
"""
Get the list of languages (ISO 639-1 tags) used throughout TMDb.
+ Args:
+ None
+
Returns:
A dict respresentation of the JSON returned from the API.
"""
@@ -88,6 +117,9 @@ def primary_translations(self, **kwargs):
"""
Get a list of the officially supported translations on TMDb.
+ Args:
+ None
+
Returns:
A dict respresentation of the JSON returned from the API.
"""
@@ -101,6 +133,9 @@ def timezones(self, **kwargs):
"""
Get the list of timezones used throughout TMDb.
+ Args:
+ None
+
Returns:
A dict respresentation of the JSON returned from the API.
"""
@@ -123,24 +158,13 @@ class Certifications(TMDB):
'tv_list': '/tv/list',
}
- # here for backward compatability, when only /movie/list existed
- def list(self, **kwargs):
- """
- Get the list of supported certifications for movies.
-
- 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 movie_list(self, **kwargs):
"""
Get an up to date list of the officially supported movie certifications on TMDb.
+ Args:
+ None
+
Returns:
A dict respresentation of the JSON returned from the API.
"""
@@ -154,6 +178,9 @@ def tv_list(self, **kwargs):
"""
Get an up to date list of the officially supported TV show certifications on TMDb.
+ Args:
+ None
+
Returns:
A dict respresentation of the JSON returned from the API.
"""
@@ -163,29 +190,19 @@ def tv_list(self, **kwargs):
self._set_attrs_to_values(response)
return response
-
-class Timezones(TMDB):
- """
- Timezones functionality.
-
- See: https://developers.themoviedb.org/3/timezones
- """
- BASE_PATH = 'timezones'
- URLS = {
- 'list': '/list',
- }
-
+ # backward compatability, when only /movie/list existed
def list(self, **kwargs):
"""
- Get the list of supported timezones for the API methods that support
- them.
+ Get the list of supported certifications for movies.
+
+ Args:
+ None
Returns:
A dict respresentation of the JSON returned from the API.
"""
- path = self._get_path('list')
+ path = self._get_path('movie_list')
response = self._GET(path, kwargs)
self._set_attrs_to_values(response)
return response
-
diff --git a/ext/tmdbsimple/discover.py b/ext/tmdbsimple/discover.py
index 7e8a41ba5f..352aa91e93 100644
--- a/ext/tmdbsimple/discover.py
+++ b/ext/tmdbsimple/discover.py
@@ -13,6 +13,7 @@
from .base import TMDB
+
class Discover(TMDB):
"""
Discover functionality.
@@ -27,64 +28,126 @@ class Discover(TMDB):
def movie(self, **kwargs):
"""
- Discover movies by different types of data like average rating,
- number of votes, genres and certifications.
+ 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.
-
+ region: (optional) Specify a ISO 3166-1 code.
+ sort_by: (optional) Allowed values: popularity.asc,
+ popularity.desc, release_date.asc, release_date.desc,
+ revenue.asc, revenue.desc, primary_release_date.asc,
+ primary_release_date.desc, original_title.asc,
+ original_title.desc, vote_average.asc, vote_average.desc,
+ vote_count.asc, vote_count.desc
+ Default: popularity.desc
+ certification_country: (optional) Used in conjunction with the
+ certification filter, use this to specify a country with a
+ valid certification.
+ certification: Filter results with a valid certification from the
+ 'certification_country' field.
+ certification.gte: Filter and only include movies that have a
+ certification that is greater than or equal to the specified
+ value.
+ certification.lte: Filter and only include movies that have a
+ certification that is less than or equal to the specified
+ value.
+ include_adult: (optional) A filter and include or exclude adult
+ movies.
+ include_video: (optional) A filter to include or exclude videos.
+ page: (optional) Minimum 1, maximum 1000, default 1.
+ primary_release_year: (optional) A filter to limit the results to a
+ specific primary release year.
+ primary_release_date.gte: (optional) Filter and only include movies
+ that have a primary release date that is greater or equal to
+ the specified value.
+ primary_release_date.lte: (optional) Filter and only include movies
+ that have a primary release date that is less than or equal to
+ the specified value.
+ release_date.gte: (optional) Filter and only include movies that
+ have a primary release date that is greater or equal to the
+ specified value.
+ releaste_date.lte: (optional) Filter and only include movies that
+ have a primary release date that is less than or equal to the
+ specified value.
+ with_release_type: (optional) Specify a comma (AND) or pipe (OR)
+ separated value to filter release types by. These release types
+ map to the same values found on the movie release date method.
+ Minimum 1, maximum 6.
+ year: (optional) A filter to limit the results to a specific year
+ (looking at all release dates).
+ vote_count.gte: (optional) Filter and only include movies that have
+ a vote count that is greater or equal to the specified value.
+ Minimum 0.
+ vote_count.lte: (optional) Filter and only include movies that have
+ a vote count that is less than or equal to the specified value.
+ Minimum 1.
+ vote_average.gte: (optional) Filter and only include movies that
+ have a rating that is greater or equal to the specified value.
+ Minimum 0.
+ vote_average.lte: (optional) Filter and only include movies that
+ have a rating that is less than or equal to the specified value.
+ Minimum 0.
+ with_cast: (optional) A comma separated list of person ID's. Only
+ include movies that have one of the ID's added as an actor.
+ with_crew: (optional) A comma separated list of person ID's. Only
+ include movies that have one of the ID's added as a crew member.
+ with_people: (optional) A comma separated list of person ID's. Only
+ include movies that have one of the ID's added as a either a
+ actor or a crew member.
+ with_companies: (optional) A comma separated list of production
+ company ID's. Only include movies that have one of the ID's
+ added as a production company.
+ with_genres: (optional) Comma separated value of genre ids that you
+ want to include in the results.
+ without_genres: (optional) Comma separated value of genre ids that
+ you want to exclude from the results.
+ with_keywords: (optional) A comma separated list of keyword ID's.
+ Only includes movies that have one of the ID's added as a
+ keyword.
+ without_keywords: (optional) Exclude items with certain keywords.
+ You can comma and pipe seperate these values to create an 'AND' or 'OR' logic.
+ with_runtime.gte: (optional) Filter and only include movies that
+ have a runtime that is greater or equal to a value.
+ with_runtime.lte: (optional) Filter and only include movies that
+ have a runtime that is less than or equal to a value.
+ with_original_language: (optional) Specify an ISO 639-1 string to
+ filter results by their original language value.
+
Returns:
A dict respresentation of the JSON returned from the API.
"""
- # Periods are not allowed in keyword arguments but several 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 kwargs:
+ 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)
@@ -93,53 +156,97 @@ def movie(self, **kwargs):
def tv(self, **kwargs):
"""
- Discover TV shows by different types of data like average rating,
+ 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',
+ 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'.
-
+ sort_by: (optional) Allowed values: vote_average.desc,
+ vote_average.asc, first_air_date.desc, first_air_date.asc,
+ popularity.desc, popularity.asc
+ Default: popularity.desc
+ air_date.gte: (optional) Filter and only include TV shows that have
+ a air date (by looking at all episodes) that is greater or
+ equal to the specified value.
+ air_date.lte: (optional) Filter and only include TV shows that have
+ a air date (by looking at all episodes) that is less than or
+ equal to the specified value.
+ first_air_date.gte: (optional) Filter and only include TV shows
+ that have a original air date that is greater or equal to the
+ specified value. Can be used in conjunction with the
+ "include_null_first_air_dates" filter if you want to include
+ items with no air date.
+ first_air_date.lte: (optional) Filter and only include TV shows
+ that have a original air date that is less than or equal to the
+ specified value. Can be used in conjunction with the
+ "include_null_first_air_dates" filter if you want to include
+ items with no air date.
+ first_air_date_year: (optional) Filter and only include TV shows
+ that have a original air date year that equal to the specified
+ value. Can be used in conjunction with the
+ "include_null_first_air_dates" filter if you want to include
+ items with no air date.
+ page: (optional) Specify the page of results to query. Default 1.
+ timezone: (optional) Used in conjunction with the air_date.gte/lte
+ filter to calculate the proper UTC offset. Default
+ America/New_York.
+ vote_average.gte: (optional) Filter and only include movies that
+ have a rating that is greater or equal to the specified value.
+ Minimum 0.
+ vote_count.gte: (optional) Filter and only include movies that have
+ a rating that is less than or equal to the specified value.
+ Minimum 0.
+ with_genres: (optional) Comma separated value of genre ids that you
+ want to include in the results.
+ with_networks: (optional) Comma separated value of network ids that
+ you want to include in the results.
+ without_genres: (optional) Comma separated value of genre ids that
+ you want to exclude from the results.
+ with_runtime.gte: (optional) Filter and only include TV shows with
+ an episode runtime that is greater than or equal to a value.
+ with_runtime.lte: (optional) Filter and only include TV shows with
+ an episode runtime that is less than or equal to a value.
+ include_null_first_air_dates: (optional) Use this filter to include
+ TV shows that don't have an air date while using any of the
+ "first_air_date" filters.
+ with_original_language: (optional) Specify an ISO 639-1 string to
+ filter results by their original language value.
+ without_keywords: (optional) Exclude items with certain keywords.
+ You can comma and pipe seperate these values to create an 'AND'
+ or 'OR' logic.
+ screened_theatrically: (optional) Filter results to include items
+ that have been screened theatrically.
+ with_companies: (optional) A comma separated list of production
+ company ID's. Only include movies that have one of the ID's
+ added as a production company.
+ with_keywords: (optional) A comma separated list of keyword ID's.
+ Only includes TV shows that have one of the ID's added as a
+ keyword.
+
Returns:
A dict respresentation of the JSON returned from the API.
"""
- # Periods are not allowed in keyword arguments but several 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 kwargs:
+ 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)
diff --git a/ext/tmdbsimple/find.py b/ext/tmdbsimple/find.py
index dd8e799076..a7ea64e07f 100644
--- a/ext/tmdbsimple/find.py
+++ b/ext/tmdbsimple/find.py
@@ -13,6 +13,7 @@
from .base import TMDB
+
class Find(TMDB):
"""
Find functionality.
@@ -23,24 +24,29 @@ class Find(TMDB):
URLS = {
'info': '/{id}',
}
+
def __init__(self, id=0):
super(Find, self).__init__()
self.id = id
def info(self, **kwargs):
"""
- Search for objects in the database by an external id. For instance,
- an IMDB ID. This will search all objects (movies, TV shows and people)
- and return the results in a single response. TV season and TV episode
- searches will be supported shortly.
+ The find method makes it easy to search for objects in our database by
+ an external id. For example, an IMDB ID.
- The supported external sources for each object are as follows:
- Movies: imdb_id
- People: imdb_id, freebase_mid, freebase_id, tvrage_id
- TV Series: imdb_id, freebase_mid, freebase_id, tvdb_id, tvrage_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.
+ language: (optional) ISO 639-1 code.
+ external_source: Allowed Values: imdb_id, freebase_mid,
+ freebase_id, tvdb_id, tvrage_id, facebook_id, twitter_id,
+ instagram_id
Returns:
A dict respresentation of the JSON returned from the API.
@@ -50,3 +56,50 @@ def info(self, **kwargs):
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:
+ None
+
+ 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
diff --git a/ext/tmdbsimple/genres.py b/ext/tmdbsimple/genres.py
index f98f62ffcc..0199c3cbad 100644
--- a/ext/tmdbsimple/genres.py
+++ b/ext/tmdbsimple/genres.py
@@ -24,7 +24,7 @@ class Genres(TMDB):
URLS = {
'movie_list': '/movie/list',
'tv_list': '/tv/list',
- 'movies': '/{id}/movies',
+ 'movies': '/{id}/movies', # backward compatability
}
def __init__(self, id=0):
@@ -33,7 +33,7 @@ def __init__(self, id=0):
def movie_list(self, **kwargs):
"""
- Get the list of Movie genres.
+ Get the list of official genres for movies.
Args:
language: (optional) ISO 639-1 code.
@@ -49,7 +49,7 @@ def movie_list(self, **kwargs):
def tv_list(self, **kwargs):
"""
- Get the list of TV genres.
+ Get the list of official genres for TV shows.
Args:
language: (optional) ISO 639-1 code.
@@ -63,6 +63,7 @@ def tv_list(self, **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
@@ -71,8 +72,8 @@ def movies(self, **kwargs):
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.
+ 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.
diff --git a/ext/tmdbsimple/movies.py b/ext/tmdbsimple/movies.py
index c4e06b3865..40a6a266d3 100644
--- a/ext/tmdbsimple/movies.py
+++ b/ext/tmdbsimple/movies.py
@@ -14,6 +14,7 @@
from .base import TMDB
+
class Movies(TMDB):
"""
Movies functionality.
@@ -23,27 +24,28 @@ class Movies(TMDB):
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',
- 'releases': '/{id}/releases',
'videos': '/{id}/videos',
'translations': '/{id}/translations',
+ 'recommendations': '/{id}/recommendations',
'similar_movies': '/{id}/similar_movies',
'reviews': '/{id}/reviews',
'lists': '/{id}/lists',
- 'changes': '/{id}/changes',
+ 'rating': '/{id}/rating',
+ 'rating_delete': '/{id}/rating',
'latest': '/latest',
- 'upcoming': '/upcoming',
'now_playing': '/now_playing',
'popular': '/popular',
'top_rated': '/top_rated',
- 'account_states': '/{id}/account_states',
- 'rating': '/{id}/rating',
- 'recommendations': '/{id}/recommendations'
+ 'upcoming': '/upcoming',
+ 'releases': '/{id}/releases', # backward compatability
}
def __init__(self, id=0):
@@ -52,11 +54,15 @@ def __init__(self, id=0):
def info(self, **kwargs):
"""
- Get the basic movie information for a specific movie id.
+ 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.
+ append_to_response: (optional) Append requests within the same
+ namespace to the response.
Returns:
A dict representation of the JSON returned from the API.
@@ -67,13 +73,32 @@ def info(self, **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: (required) See Authentication.
+ guest_session_id: (optional) 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 the alternative titles for a specific movie id.
+ 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.
@@ -84,12 +109,35 @@ def alternative_titles(self, **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) Filter the results with a start date.
+ Expected format is 'YYYY-MM-DD'.
+ end_date: (optional) Filter the results with a end date.
+ Expected format is 'YYYY-MM-DD'.
+ page: (optional) Minimum 1, maximum 1000, default 1.
+
+ 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 information for a specific movie id.
+ Get the cast and crew for a movie.
Args:
- append_to_response: (optional) Comma separated, any movie method.
+ None
Returns:
A dict representation of the JSON returned from the API.
@@ -102,11 +150,14 @@ def credits(self, **kwargs):
def external_ids(self, **kwargs):
"""
- Get the external ids for a specific movie id.
+ 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.
+ None
Returns:
A dict representation of the JSON returned from the API.
@@ -119,11 +170,16 @@ def external_ids(self, **kwargs):
def images(self, **kwargs):
"""
- Get the images (posters and backdrops) for a specific movie id.
+ 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.
@@ -138,7 +194,10 @@ def images(self, **kwargs):
def keywords(self):
"""
- Get the plot keywords for a specific movie id.
+ Get the keywords that have been added to a movie.
+
+ Args:
+ None
Returns:
A dict representation of the JSON returned from the API.
@@ -149,29 +208,21 @@ def keywords(self):
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.
+ def release_dates(self, **kwargs):
"""
- path = self._get_id_path('recommendations')
+ Get the release date along with the certification for a movie.
- response = self._GET(path, kwargs)
- self._set_attrs_to_values(response)
- return response
+ Release dates support different types:
- def release_dates(self, **kwargs):
- """
- Get the release dates and certification for a specific movie id.
+ 1. Premiere
+ 2. Theatrical (limited)
+ 3. Theatrical
+ 4. Digital
+ 5. Physical
+ 6. TV
Args:
- append_to_response: (optional) Comma separated, any movie method.
+ None
Returns:
A dict representation of the JSON returned from the API.
@@ -182,51 +233,50 @@ def release_dates(self, **kwargs):
self._set_attrs_to_values(response)
return response
- def releases(self, **kwargs):
+ def videos(self, **kwargs):
"""
- Get the release date and certification information by country for a
- specific movie id.
+ Get the videos that have been added to a movie.
Args:
- append_to_response: (optional) Comma separated, any movie method.
+ language: (optional) ISO 639-1 code.
Returns:
A dict representation of the JSON returned from the API.
"""
- path = self._get_id_path('releases')
+ path = self._get_id_path('videos')
response = self._GET(path, kwargs)
self._set_attrs_to_values(response)
return response
- def videos(self, **kwargs):
+ def translations(self, **kwargs):
"""
- Get the videos (trailers, teasers, clips, etc...) for a
- specific movie id.
+ Get a list of translations that have been created for a movie.
Args:
- append_to_response: (optional) Comma separated, any movie method.
+ None
Returns:
A dict representation of the JSON returned from the API.
"""
- path = self._get_id_path('videos')
+ path = self._get_id_path('translations')
response = self._GET(path, kwargs)
self._set_attrs_to_values(response)
return response
- def translations(self, **kwargs):
+ def recommendations(self, **kwargs):
"""
- Get the translations for a specific movie id.
+ Get a list of recommended movies for a movie.
Args:
- append_to_response: (optional) Comma separated, any movie method.
+ language: (optional) ISO 639-1 code.
+ page: (optional) Minimum 1, maximum 1000, default 1.
Returns:
A dict representation of the JSON returned from the API.
"""
- path = self._get_id_path('translations')
+ path = self._get_id_path('recommendations')
response = self._GET(path, kwargs)
self._set_attrs_to_values(response)
@@ -234,12 +284,14 @@ def translations(self, **kwargs):
def similar_movies(self, **kwargs):
"""
- Get the similar movies for a specific movie id.
+ 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.
+ page: (optional) Minimum 1, maximum 1000, default 1.
Returns:
A dict representation of the JSON returned from the API.
@@ -252,12 +304,11 @@ def similar_movies(self, **kwargs):
def reviews(self, **kwargs):
"""
- Get the reviews for a particular movie id.
+ 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.
+ page: (optional) Minimum 1, maximum 1000, default 1.
Returns:
A dict representation of the JSON returned from the API.
@@ -270,12 +321,11 @@ def reviews(self, **kwargs):
def lists(self, **kwargs):
"""
- Get the lists that the movie belongs to.
+ 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.
+ page: (optional) Minimum 1, maximum 1000, default 1.
Returns:
A dict representation of the JSON returned from the API.
@@ -286,54 +336,70 @@ def lists(self, **kwargs):
self._set_attrs_to_values(response)
return response
- def changes(self, **kwargs):
+ def rating(self, **kwargs):
"""
- Get the changes for a specific movie id.
+ Rate a movie.
- Changes are grouped by key, and ordered by date in descending order.
- By default, only the last 24 hours of changes are returned. The
- maximum number of days that can be returned in a single request is 14.
- The language is present on fields that are translatable.
+ 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:
- start_date: (optional) Expected format is 'YYYY-MM-DD'.
- end_date: (optional) Expected format is 'YYYY-MM-DD'.
+ session_id: (optional) See Authentication.
+ guest_session_id: (optional) See Authentication.
+ value: (required) This is the value of the rating you want to
+ submit. The value is expected to be between 0.5 and 10.0.
Returns:
A dict representation of the JSON returned from the API.
"""
- path = self._get_id_path('changes')
+ path = self._get_id_path('rating')
- response = self._GET(path, kwargs)
+ payload = {
+ 'value': kwargs.pop('value', None),
+ }
+
+ response = self._POST(path, kwargs, payload)
self._set_attrs_to_values(response)
return response
- def latest(self, **kwargs):
+ def rating_delete(self, **kwargs):
"""
- Get the latest movie id.
+ Remove your rating for 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: (optional) See Authentication.
+ guest_session_id: (optional) See Authentication.
Returns:
A dict representation of the JSON returned from the API.
"""
- path = self._get_path('latest')
+ path = self._get_id_path('rating_delete')
- response = self._GET(path, kwargs)
+ payload = {
+ 'value': kwargs.pop('value', None),
+ }
+
+ response = self._DELETE(path, kwargs, payload)
self._set_attrs_to_values(response)
return response
- def upcoming(self, **kwargs):
+ def latest(self, **kwargs):
"""
- Get the list of upcoming movies. This list refreshes every day.
- The maximum number of items this list will include is 100.
+ Get the most newly created movie. This is a live response and will
+ continuously change.
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')
+ path = self._get_path('latest')
response = self._GET(path, kwargs)
self._set_attrs_to_values(response)
@@ -341,12 +407,19 @@ def upcoming(self, **kwargs):
def now_playing(self, **kwargs):
"""
- Get the list of movies playing in theatres. This list refreshes
- every day. The maximum number of items this list will include is 100.
+ 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.
+ page: (optional) Minimum 1, maximum 1000, default 1.
+ region: (optional) Specify a ISO 3166-1 code to filter release
+ dates. Must be uppercase.
Returns:
A dict representation of the JSON returned from the API.
@@ -359,12 +432,14 @@ def now_playing(self, **kwargs):
def popular(self, **kwargs):
"""
- Get the list of popular movies on The Movie Database. This list
- refreshes every day.
+ 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.
+ page: (optional) Minimum 1, maximum 1000, default 1.
+ region: (optional) Specify a ISO 3166-1 code to filter release
+ dates. Must be uppercase.
Returns:
A dict representation of the JSON returned from the API.
@@ -377,13 +452,13 @@ def popular(self, **kwargs):
def top_rated(self, **kwargs):
"""
- Get the list of top rated movies. By default, this list will only
- include movies that have 10 or more votes. This list refreshes every
- day.
+ 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.
+ page: (optional) Minimum 1, maximum 1000, default 1.
+ region: (optional) Specify a ISO 3166-1 code to filter release
+ dates. Must be uppercase.
Returns:
A dict representation of the JSON returned from the API.
@@ -394,44 +469,46 @@ def top_rated(self, **kwargs):
self._set_attrs_to_values(response)
return response
- def account_states(self, **kwargs):
+ def upcoming(self, **kwargs):
"""
- This method lets users get the status of whether or not the movie has
- been rated or added to their favourite or watch lists. A valid session
- id is required.
+ 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:
- session_id: see Authentication.
+ language: (optional) ISO 639-1 code.
+ page: (optional) Minimum 1, maximum 1000, default 1.
+ region: (optional) Specify a ISO 3166-1 code to filter release
+ dates. Must be uppercase.
Returns:
A dict representation of the JSON returned from the API.
"""
- path = self._get_id_path('account_states')
+ path = self._get_path('upcoming')
response = self._GET(path, kwargs)
self._set_attrs_to_values(response)
return response
- def rating(self, **kwargs):
+ # backward compatability
+ def releases(self, **kwargs):
"""
- This method lets users rate a movie. A valid session id or guest
- session id is required.
+ Get the release date and certification information by country for a
+ specific movie id.
Args:
- session_id: see Authentication.
- guest_session_id: see Authentication.
- value: Rating value.
+ None
Returns:
A dict representation of the JSON returned from the API.
"""
- path = self._get_id_path('rating')
-
- payload = {
- 'value': kwargs.pop('value', None),
- }
+ path = self._get_id_path('releases')
- response = self._POST(path, kwargs, payload)
+ response = self._GET(path, kwargs)
self._set_attrs_to_values(response)
return response
@@ -455,16 +532,10 @@ def __init__(self, id):
def info(self, **kwargs):
"""
- Get the basic collection information for a specific collection id.
- You can get the ID needed for this method by making a /movie/{id}
- request and paying attention to the belongs_to_collection hash.
-
- Movie parts are not sorted in any particular order. If you would like
- to sort them yourself you can use the provided release_date.
+ 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.
@@ -481,9 +552,6 @@ def images(self, **kwargs):
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.
@@ -500,7 +568,6 @@ def translations(self, **kwargs):
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.
@@ -511,6 +578,7 @@ def translations(self, **kwargs):
self._set_attrs_to_values(response)
return response
+
class Companies(TMDB):
"""
Companies functionality.
@@ -522,7 +590,7 @@ class Companies(TMDB):
'info': '/{id}',
'alternative_names': '/{id}/alternative_names',
'images': '/{id}/images',
- 'movies': '/{id}/movies',
+ 'movies': '/{id}/movies', # backward compatability
}
def __init__(self, id=0):
@@ -531,11 +599,9 @@ def __init__(self, id=0):
def info(self, **kwargs):
"""
- This method is used to retrieve all of the basic information about a
- company.
+ 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.
@@ -563,7 +629,17 @@ def alternative_names(self, **kwargs):
def images(self, **kwargs):
"""
- Get a companies logos by id.
+ 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:
@@ -576,15 +652,14 @@ def images(self, **kwargs):
self._set_attrs_to_values(response)
return response
- # here for backward compatability, when /movies existed
+ # 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.
+ page: (optional) Minimum value of 1. Expected value is an integer.
Returns:
A dict representation of the JSON returned from the API.
@@ -614,7 +689,10 @@ def __init__(self, id):
def info(self, **kwargs):
"""
- Get the basic information for a specific keyword id.
+ Get the details of a keyword.
+
+ Args:
+ None
Returns:
A dict representation of the JSON returned from the API.
@@ -627,11 +705,15 @@ def info(self, **kwargs):
def movies(self, **kwargs):
"""
- Get the list of movies for a particular keyword by id.
+ 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.
+ include_adult: Choose whether to inlcude adult (pornography)
+ content in the results.
Returns:
A dict representation of the JSON returned from the API.
@@ -642,6 +724,7 @@ def movies(self, **kwargs):
self._set_attrs_to_values(response)
return response
+
class Reviews(TMDB):
"""
Reviews functionality.
@@ -659,7 +742,10 @@ def __init__(self, id):
def info(self, **kwargs):
"""
- Get the full details of a review by ID.
+ Get the review details by id.
+
+ Args:
+ None
Returns:
A dict representation of the JSON returned from the API.
diff --git a/ext/tmdbsimple/people.py b/ext/tmdbsimple/people.py
index ce0f35ad83..7e317324ff 100644
--- a/ext/tmdbsimple/people.py
+++ b/ext/tmdbsimple/people.py
@@ -3,8 +3,7 @@
"""
tmdbsimple.people
~~~~~~~~~~~~~~~~~
-This module implements the People, Credits, and Jobs functionality
-of tmdbsimple.
+This module implements the People and Credits functionality of tmdbsimple.
Created by Celia Oakley on 2013-10-31.
@@ -14,6 +13,7 @@
from .base import TMDB
+
class People(TMDB):
"""
People functionality.
@@ -23,14 +23,16 @@ class People(TMDB):
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',
- 'changes': '/{id}/changes',
- 'popular': '/popular',
+ 'tagged_images': '/{id}/tagged_images',
+ 'translations': '/{id}/translations',
'latest': '/latest',
+ 'popular': '/popular',
}
def __init__(self, id=0):
@@ -39,10 +41,15 @@ def __init__(self, id=0):
def info(self, **kwargs):
"""
- Get the general person information for a specific id.
+ 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.
+ language: (optional) ISO 639-1 code.
+ append_to_response: (optional) Append requests within the same
+ namespace to the response.
Returns:
A dict respresentation of the JSON returned from the API.
@@ -53,13 +60,35 @@ def info(self, **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) Filter the results with a start date.
+ Expected format is 'YYYY-MM-DD'.
+ end_date: (optional) Filter the results with a end date.
+ Expected format is 'YYYY-MM-DD'.
+ page: (optional) Minimum 1, maximum 1000, default 1.
+
+ 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 specific person id.
+ 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.
@@ -72,11 +101,13 @@ def movie_credits(self, **kwargs):
def tv_credits(self, **kwargs):
"""
- Get the TV credits for a specific person id.
+ 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.
@@ -89,15 +120,10 @@ def tv_credits(self, **kwargs):
def combined_credits(self, **kwargs):
"""
- Get the combined (movie and TV) credits for a specific person id.
-
- To get the expanded details for each TV record, call the /credit method
- with the provided credit_id. This will provide details about which
- episode and/or season the credit is for.
+ 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.
@@ -110,7 +136,19 @@ def combined_credits(self, **kwargs):
def external_ids(self, **kwargs):
"""
- Get the external ids for a specific person id.
+ 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
+
+ Args:
+ language: (optional) ISO 639-1 code.
Returns:
A dict respresentation of the JSON returned from the API.
@@ -123,7 +161,10 @@ def external_ids(self, **kwargs):
def images(self, **kwargs):
"""
- Get the images for a specific person id.
+ Get the images for a person.
+
+ Args:
+ None
Returns:
A dict respresentation of the JSON returned from the API.
@@ -134,40 +175,34 @@ def images(self, **kwargs):
self._set_attrs_to_values(response)
return response
- def changes(self, **kwargs):
+ def tagged_images(self, **kwargs):
"""
- Get the changes for a specific person id.
-
- Changes are grouped by key, and ordered by date in descending order.
- By default, only the last 24 hours of changes are returned. The maximum
- number of days that can be returned in a single request is 14. The
- language is present on fields that are translatable.
+ Get the images that this person has been tagged in.
Args:
- start_date: (optional) Expected format is 'YYYY-MM-DD'.
- end_date: (optional) Expected format is 'YYYY-MM-DD'.
+ language: (optional) ISO 639-1 code.
+ page: (optional) Minimum 1, maximum 1000, default 1.
Returns:
A dict respresentation of the JSON returned from the API.
"""
- path = self._get_id_path('changes')
+ path = self._get_id_path('tagged_images')
response = self._GET(path, kwargs)
self._set_attrs_to_values(response)
return response
- def popular(self, **kwargs):
+ def translations(self, **kwargs):
"""
- Get the list of popular people on The Movie Database. This list
- refreshes every day.
+ Get a list of translations that have been created for a person.
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_path('popular')
+ path = self._get_id_path('translations')
response = self._GET(path, kwargs)
self._set_attrs_to_values(response)
@@ -175,7 +210,11 @@ def popular(self, **kwargs):
def latest(self, **kwargs):
"""
- Get the latest person id.
+ Get the most newly created person. This is a live response and will
+ continuously change.
+
+ Args:
+ language: (optional) ISO 639-1 code.
Returns:
A dict respresentation of the JSON returned from the API.
@@ -186,67 +225,51 @@ def latest(self, **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):
+ def popular(self, **kwargs):
"""
- Get the detailed information about a particular credit record. This is
- currently only supported with the new credit model found in TV. These
- ids can be found from any TV credit response as well as the tv_credits
- and combined_credits methods for people.
-
- The episodes object returns a list of episodes and are generally going
- to be guest stars. The season array will return a list of season
- numbers. Season credits are credits that were marked with the
- "add to every season" option in the editing interface and are
- assumed to be "season regulars".
+ Get the list of popular people on TMDb. This list updates daily.
Args:
language: (optional) ISO 639-1 code.
+ page: (optional) Minimum 1, maximum 1000, default 1.
Returns:
A dict respresentation of the JSON returned from the API.
"""
- path = self._get_credit_id_path('info')
+ path = self._get_path('popular')
response = self._GET(path, kwargs)
self._set_attrs_to_values(response)
return response
-class Jobs(TMDB):
+
+class Credits(TMDB):
"""
- Jobs functionality.
+ Credits functionality.
- See: https://developers.themoviedb.org/3/jobs
+ See: https://developers.themoviedb.org/3/credits
"""
- BASE_PATH = 'job'
+ BASE_PATH = 'credit'
URLS = {
- 'list': '/list',
+ 'info': '/{credit_id}',
}
- def list(self, **kwargs):
+ def __init__(self, credit_id):
+ super(Credits, self).__init__()
+ self.credit_id = credit_id
+
+ def info(self, **kwargs):
"""
- Get a list of valid jobs.
+ Get a movie or TV credit details by id.
+
+ Args:
+ None
Returns:
A dict respresentation of the JSON returned from the API.
"""
- path = self._get_path('list')
+ path = self._get_credit_id_path('info')
response = self._GET(path, kwargs)
self._set_attrs_to_values(response)
return response
-
diff --git a/ext/tmdbsimple/search.py b/ext/tmdbsimple/search.py
index 6d10c153e3..4d57d52d6a 100644
--- a/ext/tmdbsimple/search.py
+++ b/ext/tmdbsimple/search.py
@@ -13,6 +13,7 @@
from .base import TMDB
+
class Search(TMDB):
"""
Search functionality
@@ -21,40 +22,28 @@ class Search(TMDB):
"""
BASE_PATH = 'search'
URLS = {
- 'movie': '/movie',
- 'collection': '/collection',
- 'tv': '/tv',
- 'person': '/person',
'company': '/company',
+ 'collection': '/collection',
'keyword': '/keyword',
- 'multi': '/multi'
+ 'movie': '/movie',
+ 'multi': '/multi',
+ 'person': '/person',
+ 'tv': '/tv',
}
- def movie(self, **kwargs):
+ def company(self, **kwargs):
"""
- Search for movies by title.
+ Search for companies.
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'.
+ query: (required) Pass a text query to search. This value should be
+ URI encoded.
+ page: (optional) Minimum 1, maximum 1000, default 1.
Returns:
A dict respresentation of the JSON returned from the API.
"""
- path = self._get_path('movie')
+ path = self._get_path('company')
response = self._GET(path, kwargs)
self._set_attrs_to_values(response)
@@ -62,12 +51,13 @@ def movie(self, **kwargs):
def collection(self, **kwargs):
"""
- Search for collections by name.
+ 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.
+ language: (optional) (optional) ISO 639-1 code.
+ query: (required) Pass a text query to search. This value should be
+ URI encoded.
+ page: (optional) Minimum 1, maximum 1000, default 1.
Returns:
A dict respresentation of the JSON returned from the API.
@@ -78,106 +68,116 @@ def collection(self, **kwargs):
self._set_attrs_to_values(response)
return response
- def tv(self, **kwargs):
+ def keyword(self, **kwargs):
"""
- Search for TV shows by title.
+ Search for keywords.
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'.
+ query: (required) Pass a text query to search. This value should be
+ URI encoded.
+ page: (optional) Minimum 1, maximum 1000, default 1.
Returns:
A dict respresentation of the JSON returned from the API.
"""
- path = self._get_path('tv')
+ path = self._get_path('keyword')
response = self._GET(path, kwargs)
self._set_attrs_to_values(response)
return response
- def person(self, **kwargs):
+ def movie(self, **kwargs):
"""
- Search for people by name.
+ Search for movies.
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'.
+ language: (optional) (optional) ISO 639-1 code.
+ query: (required) Pass a text query to search. This value should be
+ URI encoded.
+ page: (optional) Minimum 1, maximum 1000, default 1.
+ include_adult: (optional) Choose whether to inlcude adult
+ (pornography) content in the results.
+ region: (optional) Specify a ISO 3166-1 code to filter release
+ dates. Must be uppercase.
+ year: (optional) A filter to limit the results to a specific year
+ (looking at all release dates).
+ primary_release_year: (optional) A filter to limit the results to a
+ specific primary release year.
Returns:
A dict respresentation of the JSON returned from the API.
"""
- path = self._get_path('person')
+ path = self._get_path('movie')
response = self._GET(path, kwargs)
self._set_attrs_to_values(response)
return response
- def company(self, **kwargs):
+ def multi(self, **kwargs):
"""
- Search for companies by name.
+ 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) (optional) ISO 639-1 code.
+ query: (required) Pass a text query to search. This value should be
+ URI encoded.
+ page: (optional) Minimum 1, maximum 1000, default 1.
+ include_adult: (optional) Choose whether to inlcude adult
+ (pornography) content in the results.
+ region: (optional) Specify a ISO 3166-1 code to filter release
+ dates. Must be uppercase.
Returns:
A dict respresentation of the JSON returned from the API.
"""
- path = self._get_path('company')
+ path = self._get_path('multi')
response = self._GET(path, kwargs)
self._set_attrs_to_values(response)
return response
- def keyword(self, **kwargs):
+ def person(self, **kwargs):
"""
- Search for keywords by name.
+ Search for people.
Args:
- query: CGI escpaed string.
- page: (optional) Minimum value of 1. Expected value is an integer.
+ language: (optional) (optional) ISO 639-1 code.
+ query: (required) Pass a text query to search. This value should be
+ URI encoded.
+ page: (optional) Minimum 1, maximum 1000, default 1.
+ include_adult: (optional) Choose whether to inlcude adult
+ (pornography) content in the results.
+ region: (optional) Specify a ISO 3166-1 code to filter release
+ dates. Must be uppercase.
Returns:
A dict respresentation of the JSON returned from the API.
"""
- path = self._get_path('keyword')
+ path = self._get_path('person')
response = self._GET(path, kwargs)
self._set_attrs_to_values(response)
return response
- def multi(self, **kwargs):
+ def tv(self, **kwargs):
"""
- Search the movie, tv show and person collections with a single query.
+ 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.
- include_adult: (optional) Toggle the inclusion of adult titles.
- Expected value is True or False.
+ language: (optional) (optional) ISO 639-1 code.
+ query: (required) Pass a text query to search. This value should be
+ URI encoded.
+ page: (optional) Minimum 1, maximum 1000, default 1.
+ include_adult: (optional) Choose whether to inlcude adult
+ (pornography) content in the results.
+ first_air_date_year: (optional) Filter the results to only match
+ shows that have an air date with with value.
Returns:
A dict respresentation of the JSON returned from the API.
"""
- path = self._get_path('multi')
+ path = self._get_path('tv')
response = self._GET(path, kwargs)
self._set_attrs_to_values(response)
diff --git a/ext/tmdbsimple/tv.py b/ext/tmdbsimple/tv.py
index 85ca8c2b58..2e8410e0fa 100644
--- a/ext/tmdbsimple/tv.py
+++ b/ext/tmdbsimple/tv.py
@@ -14,6 +14,7 @@
from .base import TMDB
+
class TV(TMDB):
"""
TV functionality.
@@ -23,22 +24,26 @@ class TV(TMDB):
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',
- 'rating': '/{id}/rating',
- 'similar': '/{id}/similar',
+ 'keywords': '/{id}/keywords',
'recommendations': '/{id}/recommendations',
+ 'reviews': '/{id}/reviews',
+ 'screened_theatrically': '/{id}/screened_theatrically',
+ 'similar': '/{id}/similar',
'translations': '/{id}/translations',
'videos': '/{id}/videos',
- 'keywords': '/{id}/keywords',
+ 'rating': '/{id}/rating',
'latest': '/latest',
- 'on_the_air': '/on_the_air',
'airing_today': '/airing_today',
- 'top_rated': '/top_rated',
+ 'on_the_air': '/on_the_air',
'popular': '/popular',
+ 'top_rated': '/top_rated',
}
def __init__(self, id=0):
@@ -47,12 +52,15 @@ def __init__(self, id=0):
def info(self, **kwargs):
"""
- Get the primary information about a TV series by id.
+ 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.
+ append_to_response: (optional) Append requests within the same
+ namespace to the response.
Returns:
A dict respresentation of the JSON returned from the API.
@@ -63,14 +71,34 @@ def info(self, **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.
+ session_id: (required) See Authentication.
+ guest_session_id: (optional) See Authentication.
+
+ 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):
"""
- Get the alternative titles for a specific tv id.
+ 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.
"""
@@ -80,15 +108,13 @@ def alternative_titles(self, **kwargs):
self._set_attrs_to_values(response)
return response
-
def content_ratings(self, **kwargs):
"""
- Get the content ratings for a TV Series.
+ 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.
+ language: (optional) ISO 3166-1 code.
Returns:
A dict respresentation of the JSON returned from the API.
@@ -101,13 +127,10 @@ def content_ratings(self, **kwargs):
def credits(self, **kwargs):
"""
- Get the cast & crew information about a TV series. Just like the
- website, we pull this information from the last season of the series.
+ 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.
@@ -118,9 +141,33 @@ def credits(self, **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 that we have stored for a TV series.
+ 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.
@@ -136,12 +183,16 @@ def external_ids(self, **kwargs):
def images(self, **kwargs):
"""
- Get the images (posters and backdrops) for a TV series.
+ 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.
@@ -152,59 +203,86 @@ def images(self, **kwargs):
self._set_attrs_to_values(response)
return response
- def rating(self, **kwargs):
+ def keywords(self, **kwargs):
"""
- This method lets users rate a TV show. A valid session id or guest
- session id is required.
+ Get the keywords that have been added to a TV show.
Args:
- session_id: see Authentication.
- guest_session_id: see Authentication.
- value: Rating value.
+ None
Returns:
A dict respresentation of the JSON returned from the API.
"""
- path = self._get_id_path('rating')
+ path = self._get_id_path('keywords')
- payload = {
- 'value': kwargs.pop('value', None),
- }
+ response = self._GET(path, kwargs)
+ self._set_attrs_to_values(response)
+ return response
- response = self._POST(path, kwargs, payload)
+ def recommendations(self, **kwargs):
+ """
+ Get the list of TV show recommendations for this item.
+
+ Args:
+ language: (optional) ISO 639-1 code.
+ page: (optional) Minimum 1, maximum 1000, default 1.
+
+ 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 similar(self, **kwargs):
+ def reviews(self, **kwargs):
"""
- Get the similar TV series for a specific TV series id.
+ 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.
- append_to_response: (optional) Comma separated, any TV method.
+ page: (optional) Minimum 1, maximum 1000, default 1.
Returns:
A dict respresentation of the JSON returned from the API.
"""
- path = self._get_id_path('similar')
+ path = self._get_id_path('reviews')
response = self._GET(path, kwargs)
self._set_attrs_to_values(response)
return response
- def recommendations(self, **kwargs):
+ def screened_theatrically(self, **kwargs):
+ """
+ Get a list of seasons or episodes that have been screened in a film
+ festival or theatre.
+
+ Args:
+ None
+
+ 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 the recommendations for TV series for a specific TV series id.
+ 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.
+ page: (optional) Minimum 1, maximum 1000, default 1.
Returns:
A dict respresentation of the JSON returned from the API.
"""
- path = self._get_id_path('recommendations')
+ path = self._get_id_path('similar')
response = self._GET(path, kwargs)
self._set_attrs_to_values(response)
@@ -212,8 +290,10 @@ def recommendations(self, **kwargs):
def translations(self, **kwargs):
"""
- Get the list of translations that exist for a TV series. These
- translations cascade down to the episode level.
+ Get a list of the translations that exist for a TV show.
+
+ Args:
+ None
Returns:
A dict respresentation of the JSON returned from the API.
@@ -226,8 +306,7 @@ def translations(self, **kwargs):
def videos(self, **kwargs):
"""
- Get the videos that have been added to a TV series (trailers, opening
- credits, etc...).
+ Get the videos that have been added to a TV show.
Args:
language: (optional) ISO 639 code.
@@ -241,50 +320,70 @@ def videos(self, **kwargs):
self._set_attrs_to_values(response)
return response
- def keywords(self, **kwargs):
+ def rating(self, **kwargs):
"""
- Get the list of keywords related to a TV series.
+ 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: (optional) See Authentication.
+ guest_session_id: (optional) See Authentication.
+ value: (required) This is the value of the rating you want to
+ submit. The value is expected to be between 0.5 and 10.0.
Returns:
A dict respresentation of the JSON returned from the API.
"""
- path = self._get_id_path('keywords')
+ path = self._get_id_path('rating')
- response = self._GET(path, kwargs)
+ payload = {
+ 'value': kwargs.pop('value', None),
+ }
+
+ response = self._POST(path, kwargs, payload)
self._set_attrs_to_values(response)
return response
- def latest(self, **kwargs):
+ def rating_delete(self, **kwargs):
"""
- Get the most newly created TV show. This is a live response
- and will continuously change.
+ Remove your rating for 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:
- language: (optional) ISO 639 code.
+ session_id: (optional) See Authentication.
+ guest_session_id: (optional) See Authentication.
Returns:
A dict respresentation of the JSON returned from the API.
"""
- path = self._get_id_path('latest')
+ path = self._get_id_path('rating')
- response = self._GET(path, kwargs)
+ payload = {
+ 'value': kwargs.pop('value', None),
+ }
+
+ response = self._DELETE(path, kwargs, payload)
self._set_attrs_to_values(response)
return response
- def on_the_air(self, **kwargs):
+ def latest(self, **kwargs):
"""
- Get the list of TV 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.
+ Get the most newly created TV show. This is a live response and will
+ continuously change.
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')
+ path = self._get_id_path('latest')
response = self._GET(path, kwargs)
self._set_attrs_to_values(response)
@@ -292,13 +391,16 @@ def on_the_air(self, **kwargs):
def airing_today(self, **kwargs):
"""
- Get the list of TV shows that air today. Without a specified timezone,
- this query defaults to EST (Eastern Time UTC-05:00).
+ 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.
+ page: (optional) Minimum 1, maximum 1000, default 1.
Returns:
A dict respresentation of the JSON returned from the API.
@@ -309,20 +411,21 @@ def airing_today(self, **kwargs):
self._set_attrs_to_values(response)
return response
- def top_rated(self, **kwargs):
+ def on_the_air(self, **kwargs):
"""
- Get the list of top rated TV shows. By default, this list will only
- include TV shows that have 2 or more votes. This list refreshes every
- day.
+ 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.
+ page: (optional) Minimum 1, maximum 1000, default 1.
Returns:
A dict respresentation of the JSON returned from the API.
"""
- path = self._get_path('top_rated')
+ path = self._get_path('on_the_air')
response = self._GET(path, kwargs)
self._set_attrs_to_values(response)
@@ -330,11 +433,12 @@ def top_rated(self, **kwargs):
def popular(self, **kwargs):
"""
- Get the list of popular TV shows. This list refreshes every day.
+ 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.
+ page: (optional) Minimum 1, maximum 1000, default 1.
Returns:
A dict respresentation of the JSON returned from the API.
@@ -345,6 +449,23 @@ def popular(self, **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:
+ language: (optional) ISO 639 code.
+ page: (optional) Minimum 1, maximum 1000, default 1.
+
+ 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):
"""
@@ -355,6 +476,7 @@ class TV_Seasons(TMDB):
BASE_PATH = 'tv/{tv_id}/season/{season_number}'
URLS = {
'info': '',
+ 'account_states': '/account_states',
'credits': '/credits',
'external_ids': '/external_ids',
'images': '/images',
@@ -368,12 +490,15 @@ def __init__(self, tv_id, season_number):
def info(self, **kwargs):
"""
- Get the primary information about a TV season by its season number.
+ 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.
+ append_to_response: (optional) Append requests within the same
+ namespace to the response.
Returns:
A dict respresentation of the JSON returned from the API.
@@ -384,9 +509,30 @@ def info(self, **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.
+ session_id: (required) See Authentication.
+ guest_session_id: (optional) See Authentication.
+
+ 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 cast & crew credits for a TV season by season number.
+ Get the credits for TV season.
+
+ Args:
+ language: (optional) ISO 639 code.
Returns:
A dict respresentation of the JSON returned from the API.
@@ -399,8 +545,12 @@ def credits(self, **kwargs):
def external_ids(self, **kwargs):
"""
- Get the external ids that we have stored for a TV season by season
- number.
+ 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.
@@ -416,13 +566,16 @@ def external_ids(self, **kwargs):
def images(self, **kwargs):
"""
- Get the images (posters) that we have stored for a TV season by season
- number.
+ 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.
@@ -435,8 +588,7 @@ def images(self, **kwargs):
def videos(self, **kwargs):
"""
- Get the videos that have been added to a TV season (trailers, teasers,
- etc...).
+ Get the videos that have been added to a TV season.
Args:
language: (optional) ISO 639 code.
@@ -460,9 +612,11 @@ class TV_Episodes(TMDB):
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',
}
@@ -475,13 +629,15 @@ def __init__(self, tv_id, season_number, episode_number):
def info(self, **kwargs):
"""
- Get the primary information about a TV episode by combination of a
- season and episode number.
+ 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.
+ append_to_response: (optional) Append requests within the same
+ namespace to the response.
Returns:
A dict respresentation of the JSON returned from the API.
@@ -492,9 +648,29 @@ def info(self, **kwargs):
self._set_attrs_to_values(response)
return response
+ def account_states(self, **kwargs):
+ """
+ Get your rating for an episode.
+
+ Args:
+ session_id: (required) See Authentication.
+ guest_session_id: (optional) See Authentication.
+
+ 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 TV episode credits by combination of season and episode number.
+ Get the credits (cast, crew and guest stars) for a TV episode.
+
+ Args:
+ None
Returns:
A dict respresentation of the JSON returned from the API.
@@ -507,11 +683,16 @@ def credits(self, **kwargs):
def external_ids(self, **kwargs):
"""
- Get the external ids for a TV episode by combination of a season and
- episode number.
+ 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.
+ None
Returns:
A dict respresentation of the JSON returned from the API.
@@ -525,9 +706,16 @@ def external_ids(self, **kwargs):
def images(self, **kwargs):
"""
- Get the images (episode stills) for a TV episode by combination of a
- season and episode number. Since episode stills don't have a language,
- this call will always return all images.
+ 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.
+
+ Args:
+ None
Returns:
A dict respresentation of the JSON returned from the API.
@@ -538,15 +726,35 @@ def images(self, **kwargs):
self._set_attrs_to_values(response)
return response
+ def translations(self, **kwargs):
+ """
+ Get the translation data for an episode.
+
+ Args:
+ None
+
+ 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):
"""
- This method lets users rate a TV episode. A valid session id or guest
- session id is required.
+ 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.
+ session_id: (optional) See Authentication.
+ guest_session_id: (optional) See Authentication.
+ value: (required) This is the value of the rating you want to
+ submit. The value is expected to be between 0.5 and 10.0.
Returns:
A dict respresentation of the JSON returned from the API.
@@ -561,10 +769,34 @@ def rating(self, **kwargs):
self._set_attrs_to_values(response)
return response
+ def rating_delete(self, **kwargs):
+ """
+ Remove your rating for 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: (optional) See Authentication.
+ guest_session_id: (optional) See Authentication.
+
+ 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._DELETE(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 (teasers, clips,
- etc...).
+ Get the videos that have been added to a TV episode.
Args:
language: (optional) ISO 639 code.
@@ -579,6 +811,46 @@ def videos(self, **kwargs):
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.
@@ -600,16 +872,23 @@ def __init__(self, id=0):
def series(self, **kwargs):
"""
- Get the changes for a specific series id.
+ Get the changes for a TV show. By default only the last 24 hours are returned.
- Changes are grouped by key, and ordered by date in descending order.
- By default, only the last 24 hours of changes are returned. The
- maximum number of days that can be returned in a single request is 14.
+ 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.
+ start_date: (optional) Filter the results with a start date.
+ Expected format is 'YYYY-MM-DD'.
+ end_date: (optional) Filter the results with a end date.
+ Expected format is 'YYYY-MM-DD'.
+ page: (optional) Minimum 1, maximum 1000, default 1.
Returns:
A dict respresentation of the JSON returned from the API.
@@ -622,16 +901,17 @@ def series(self, **kwargs):
def season(self, **kwargs):
"""
- Get the changes for a specific season id.
+ Get the changes for a TV season. By default only the last 24 hours are returned.
- Changes are grouped by key, and ordered by date in descending order.
- By default, only the last 24 hours of changes are returned. The
- maximum number of days that can be returned in a single request is 14.
+ 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.
+ start_date: (optional) Filter the results with a start date.
+ Expected format is 'YYYY-MM-DD'.
+ end_date: (optional) Filter the results with a end date.
+ Expected format is 'YYYY-MM-DD'.
+ page: (optional) Minimum 1, maximum 1000, default 1.
Returns:
A dict respresentation of the JSON returned from the API.
@@ -644,16 +924,17 @@ def season(self, **kwargs):
def episode(self, **kwargs):
"""
- Get the changes for a specific episode id.
+ Get the changes for a TV episode. By default only the last 24 hours are returned.
- Changes are grouped by key, and ordered by date in descending order.
- By default, only the last 24 hours of changes are returned. The
- maximum number of days that can be returned in a single request is 14.
+ 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.
+ start_date: (optional) Filter the results with a start date.
+ Expected format is 'YYYY-MM-DD'.
+ end_date: (optional) Filter the results with a end date.
+ Expected format is 'YYYY-MM-DD'.
+ page: (optional) Minimum 1, maximum 1000, default 1.
Returns:
A dict respresentation of the JSON returned from the API.
@@ -674,6 +955,8 @@ class Networks(TMDB):
BASE_PATH = 'network'
URLS = {
'info': '/{id}',
+ 'alternative_names': '/{id}/alternative_names',
+ 'images': '/{id}/images',
}
def __init__(self, id):
@@ -682,9 +965,10 @@ def __init__(self, id):
def info(self, **kwargs):
"""
- This method is used to retrieve the basic information about a TV
- network. You can use this ID to search for TV shows with the discover.
- At this time we don't have much but this will be fleshed out over time.
+ Get the details of a network.
+
+ Args:
+ None
Returns:
A dict respresentation of the JSON returned from the API.
@@ -694,3 +978,45 @@ def info(self, **kwargs):
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:
+ None
+
+ 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:
+ None
+
+ 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
diff --git a/medusa/__main__.py b/medusa/__main__.py
index 215ecc0002..ed51da9203 100755
--- a/medusa/__main__.py
+++ b/medusa/__main__.py
@@ -578,7 +578,10 @@ def initialize(self, console_logging=True):
app.CPU_PRESET = check_setting_str(app.CFG, 'General', 'cpu_preset', 'NORMAL')
app.ANON_REDIRECT = check_setting_str(app.CFG, 'General', 'anon_redirect', 'http://dereferer.org/?')
app.PROXY_SETTING = check_setting_str(app.CFG, 'General', 'proxy_setting', '')
+ app.PROXY_PROVIDERS = bool(check_setting_int(app.CFG, 'General', 'proxy_providers', 1))
app.PROXY_INDEXERS = bool(check_setting_int(app.CFG, 'General', 'proxy_indexers', 1))
+ app.PROXY_CLIENTS = bool(check_setting_int(app.CFG, 'General', 'proxy_clients', 1))
+ app.PROXY_OTHERS = bool(check_setting_int(app.CFG, 'General', 'proxy_others', 1))
# attempt to help prevent users from breaking links by using a bad url
if not app.ANON_REDIRECT.endswith('?'):
@@ -1585,7 +1588,10 @@ def save_config():
new_config['General']['trash_rotate_logs'] = int(app.TRASH_ROTATE_LOGS)
new_config['General']['sort_article'] = int(app.SORT_ARTICLE)
new_config['General']['proxy_setting'] = app.PROXY_SETTING
+ new_config['General']['proxy_providers'] = int(app.PROXY_PROVIDERS)
new_config['General']['proxy_indexers'] = int(app.PROXY_INDEXERS)
+ new_config['General']['proxy_clients'] = int(app.PROXY_CLIENTS)
+ new_config['General']['proxy_others'] = int(app.PROXY_OTHERS)
new_config['General']['use_listview'] = int(app.USE_LISTVIEW)
new_config['General']['metadata_kodi'] = app.METADATA_KODI
diff --git a/medusa/app.py b/medusa/app.py
index 7806d0fb28..260ba90f95 100644
--- a/medusa/app.py
+++ b/medusa/app.py
@@ -172,7 +172,11 @@ def __init__(self):
self.HANDLE_REVERSE_PROXY = False
self.PROXY_SETTING = None
+ self.PROXY_PROVIDERS = True
self.PROXY_INDEXERS = True
+ self.PROXY_CLIENTS = True
+ self.PROXY_OTHERS = True
+
self.SSL_VERIFY = True
self.SSL_CA_BUNDLE = None
diff --git a/medusa/clients/nzb/sab.py b/medusa/clients/nzb/sab.py
index 711b76de38..84f2efd9a2 100644
--- a/medusa/clients/nzb/sab.py
+++ b/medusa/clients/nzb/sab.py
@@ -16,14 +16,14 @@
from medusa import app
from medusa.helper.common import sanitize_filename
from medusa.logger.adapters.style import BraceAdapter
-from medusa.session.core import MedusaSafeSession
+from medusa.session.core import ClientSession
from requests.compat import urljoin
log = BraceAdapter(logging.getLogger(__name__))
log.logger.addHandler(logging.NullHandler())
-session = MedusaSafeSession()
+session = ClientSession()
def send_nzb(nzb):
diff --git a/medusa/clients/torrent/generic.py b/medusa/clients/torrent/generic.py
index f1a60fe94f..313abfae54 100644
--- a/medusa/clients/torrent/generic.py
+++ b/medusa/clients/torrent/generic.py
@@ -17,7 +17,7 @@
from medusa import app, db
from medusa.helper.common import http_code_description
from medusa.logger.adapters.style import BraceAdapter
-from medusa.session.core import MedusaSession
+from medusa.session.core import ClientSession
import requests
@@ -49,7 +49,7 @@ def __init__(self, name, host=None, username=None, password=None):
self.response = None
self.auth = None
self.last_time = time.time()
- self.session = MedusaSession()
+ self.session = ClientSession()
self.session.auth = (self.username, self.password)
def _request(self, method='get', params=None, data=None, files=None, cookies=None):
diff --git a/medusa/indexers/config.py b/medusa/indexers/config.py
index d43ebc68c6..864a0c0ea8 100644
--- a/medusa/indexers/config.py
+++ b/medusa/indexers/config.py
@@ -9,7 +9,7 @@
from medusa.indexers.tmdb.api import Tmdb
from medusa.indexers.tvdbv2.api import TVDBv2
from medusa.indexers.tvmaze.api import TVmaze
-from medusa.session.core import MedusaSession
+from medusa.session.core import IndexerSession
from six import iteritems
@@ -77,7 +77,7 @@
'api_params': {
'language': 'en',
'use_zip': True,
- 'session': MedusaSession(cache_control={'cache_etags': False}),
+ 'session': IndexerSession(cache_control={'cache_etags': False}),
},
'xem_origin': 'tvdb',
'icon': 'thetvdb16.png',
@@ -95,7 +95,7 @@
'api_params': {
'language': 'en',
'use_zip': True,
- 'session': MedusaSession(cache_control={'cache_etags': False}),
+ 'session': IndexerSession(cache_control={'cache_etags': False}),
},
'xem_mapped_to': INDEXER_TVDBV2,
'icon': 'tvmaze16.png',
@@ -113,7 +113,7 @@
'api_params': {
'language': 'en',
'use_zip': True,
- 'session': MedusaSession(cache_control={'cache_etags': False}),
+ 'session': IndexerSession(cache_control={'cache_etags': False}),
},
'icon': 'tmdb16.png',
'scene_loc': '{base_url}/scene_exceptions/scene_exceptions_tmdb.json'.format(base_url=app.BASE_PYMEDUSA_URL),
diff --git a/medusa/providers/generic_provider.py b/medusa/providers/generic_provider.py
index 0b668a9679..84fe59d7bc 100644
--- a/medusa/providers/generic_provider.py
+++ b/medusa/providers/generic_provider.py
@@ -44,7 +44,7 @@
NameParser,
)
from medusa.search import FORCED_SEARCH, PROPER_SEARCH
-from medusa.session.core import MedusaSafeSession
+from medusa.session.core import ProviderSession
from medusa.show.show import Show
from pytimeparse import parse
@@ -80,7 +80,7 @@ def __init__(self, name):
self.public = False
self.search_fallback = False
self.search_mode = None
- self.session = MedusaSafeSession(cloudflare=True)
+ self.session = ProviderSession(cloudflare=True)
self.session.headers.update(self.headers)
self.series = None
self.supports_absolute_numbering = False
diff --git a/medusa/server/api/v2/config.py b/medusa/server/api/v2/config.py
index eda55ee579..3aa30477a4 100644
--- a/medusa/server/api/v2/config.py
+++ b/medusa/server/api/v2/config.py
@@ -133,7 +133,10 @@ class ConfigHandler(BaseRequestHandler):
'calendarUnprotected': BooleanField(app, 'CALENDAR_UNPROTECTED'),
'calendarIcons': BooleanField(app, 'CALENDAR_ICONS'),
'proxySetting': StringField(app, 'PROXY_SETTING'),
+ 'proxyProviders': BooleanField(app, 'PROXY_PROVIDERS'),
'proxyIndexers': BooleanField(app, 'PROXY_INDEXERS'),
+ 'proxyClients': BooleanField(app, 'PROXY_CLIENTS'),
+ 'proxyOthers': BooleanField(app, 'PROXY_OTHERS'),
'skipRemovedFiles': BooleanField(app, 'SKIP_REMOVED_FILES'),
'epDefaultDeletedStatus': IntegerField(app, 'EP_DEFAULT_DELETED_STATUS'),
@@ -673,8 +676,13 @@ def data_main():
section_data['encryptionVersion'] = bool(app.ENCRYPTION_VERSION)
section_data['calendarUnprotected'] = bool(app.CALENDAR_UNPROTECTED)
section_data['calendarIcons'] = bool(app.CALENDAR_ICONS)
+
section_data['proxySetting'] = app.PROXY_SETTING
+ section_data['proxyProviders'] = bool(app.PROXY_PROVIDERS)
section_data['proxyIndexers'] = bool(app.PROXY_INDEXERS)
+ section_data['proxyClients'] = bool(app.PROXY_CLIENTS)
+ section_data['proxyOthers'] = bool(app.PROXY_OTHERS)
+
section_data['skipRemovedFiles'] = bool(app.SKIP_REMOVED_FILES)
section_data['epDefaultDeletedStatus'] = app.EP_DEFAULT_DELETED_STATUS
section_data['developer'] = bool(app.DEVELOPER)
diff --git a/medusa/session/core.py b/medusa/session/core.py
index 7135718f79..6ef2ae6011 100644
--- a/medusa/session/core.py
+++ b/medusa/session/core.py
@@ -9,15 +9,18 @@
import certifi
import medusa.common
-from medusa import app
+from medusa.app import app
+from medusa.logger.adapters.style import BraceAdapter
from medusa.session import factory, handlers, hooks
import requests
from six.moves import collections_abc
+from six.moves.urllib.parse import urlparse
-log = logging.getLogger(__name__)
-log.addHandler(logging.NullHandler())
+
+log = BraceAdapter(logging.getLogger(__name__))
+log.logger.addHandler(logging.NullHandler())
class BaseSession(requests.Session):
@@ -86,9 +89,6 @@ def __init__(self, proxies=None, **kwargs):
if cache_control:
factory.add_cache_control(self, cache_control)
- # add proxies
- self.proxies = proxies or factory.add_proxies()
-
# Configure global session hooks
self.hooks['response'].append(hooks.log_url)
@@ -98,8 +98,36 @@ def __init__(self, proxies=None, **kwargs):
# Set default headers.
self.headers.update(self.default_headers)
+ def _add_proxies(self):
+ """As we're dependent on medusa app config. We need to set the proxy before the classes are initialized."""
+
+ def get_proxy_setting():
+ config = {
+ 'ProviderSession': app.PROXY_PROVIDERS,
+ 'IndexerSession': app.PROXY_INDEXERS,
+ 'ClientSession': app.PROXY_CLIENTS
+ }
+ if (isinstance(self, (ProviderSession, IndexerSession, ClientSession))):
+ return config[self.__class__.__name__]
+
+ return app.PROXY_OTHERS
+
+ if app.PROXY_SETTING and get_proxy_setting():
+ log.debug('Using proxy: {proxy} for {class}', {'proxy': app.PROXY_SETTING, 'class': self.__class__.__name__})
+ proxy = urlparse(app.PROXY_SETTING)
+ address = app.PROXY_SETTING if proxy.scheme else 'http://' + app.PROXY_SETTING
+ self.proxies = {
+ 'http': address,
+ 'https': address,
+ }
+ else:
+ self.proxies = None
+
def request(self, method, url, data=None, params=None, headers=None, timeout=30, verify=True, **kwargs):
+ """Medusa session request method."""
ssl_cert = self._get_ssl_cert(verify)
+ self._add_proxies()
+
response = super(MedusaSession, self).request(method, url, data=data, params=params, headers=headers,
timeout=timeout, verify=ssl_cert, **kwargs)
if self.cloudflare:
@@ -145,7 +173,7 @@ class MedusaSafeSession(MedusaSession):
"""
def __init__(self, *args, **kwargs):
- # Initialize request.session
+ """Initialize request.session."""
super(MedusaSafeSession, self).__init__(**kwargs)
def request(self, method, url, data=None, params=None, headers=None, timeout=30, verify=True, **kwargs):
@@ -163,8 +191,8 @@ def request(self, method, url, data=None, params=None, headers=None, timeout=30,
log.debug(u'Error requesting url {url} Error: {err_msg}', url=url, err_msg=error)
return resp or error.response
except Exception as error:
- if ((isinstance(error, collections_abc.Iterable) and u'ECONNRESET' in error) or
- (hasattr(error, u'errno') and error.errno == errno.ECONNRESET)):
+ if ((isinstance(error, collections_abc.Iterable) and u'ECONNRESET' in error)
+ or (hasattr(error, u'errno') and error.errno == errno.ECONNRESET)):
log.warning(
u'Connection reset by peer accessing url {url} Error: {err_msg}'.format(url=url, err_msg=error)
)
@@ -174,3 +202,30 @@ def request(self, method, url, data=None, params=None, headers=None, timeout=30,
return None
return resp
+
+
+class ProviderSession(MedusaSafeSession):
+ """Requests session for providers."""
+
+ def __init__(self, **kwargs):
+ """Init super and hook in the proxy if configured for providers."""
+ # Initialize request.session
+ super(ProviderSession, self).__init__(**kwargs)
+
+
+class IndexerSession(MedusaSafeSession):
+ """Requests session for indexers."""
+
+ def __init__(self, **kwargs):
+ """Init super and hook in the proxy if configured for indexers."""
+ # Initialize request.session
+ super(IndexerSession, self).__init__(**kwargs)
+
+
+class ClientSession(MedusaSafeSession):
+ """Requests session for clients."""
+
+ def __init__(self, **kwargs):
+ """Init super and hook in the proxy if configured for clients."""
+ # Initialize request.session
+ super(ClientSession, self).__init__(**kwargs)
diff --git a/medusa/session/factory.py b/medusa/session/factory.py
index b369d275d9..6dd5067bab 100644
--- a/medusa/session/factory.py
+++ b/medusa/session/factory.py
@@ -6,10 +6,6 @@
from cachecontrol import CacheControlAdapter
from cachecontrol.cache import DictCache
-from medusa import app
-
-from six.moves.urllib.parse import urlparse
-
log = logging.getLogger(__name__)
log.addHandler(logging.NullHandler())
@@ -25,17 +21,3 @@ def add_cache_control(session, cache_control_config):
session.mount('http://', adapter)
session.mount('https://', adapter)
session.cache_controller = adapter.controller
-
-
-def add_proxies():
- # request session proxies
- if app.PROXY_SETTING:
- log.debug('Using global proxy: ' + app.PROXY_SETTING)
- proxy = urlparse(app.PROXY_SETTING)
- address = app.PROXY_SETTING if proxy.scheme else 'http://' + app.PROXY_SETTING
- return {
- 'http': address,
- 'https': address,
- }
- else:
- return None
diff --git a/requirements.txt b/requirements.txt
index ff6b2e6f52..84bb6e7d41 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -33,7 +33,7 @@ requests==2.25.0
requests-oauthlib==1.3.0
six==1.15.0
subliminal==2.1.0
-tmdbsimple==2.2.11
+tmdbsimple==2.7.0
tornado==5.1.1
tornroutes==0.5.1
ttl-cache==1.6
diff --git a/tests/apiv2/test_config.py b/tests/apiv2/test_config.py
index 209c472c14..256215e12f 100644
--- a/tests/apiv2/test_config.py
+++ b/tests/apiv2/test_config.py
@@ -125,7 +125,10 @@ def config_main(monkeypatch, app_config):
section_data['calendarUnprotected'] = bool(app.CALENDAR_UNPROTECTED)
section_data['calendarIcons'] = bool(app.CALENDAR_ICONS)
section_data['proxySetting'] = app.PROXY_SETTING
+ section_data['proxyProviders'] = bool(app.PROXY_PROVIDERS)
section_data['proxyIndexers'] = bool(app.PROXY_INDEXERS)
+ section_data['proxyClients'] = bool(app.PROXY_CLIENTS)
+ section_data['proxyOthers'] = bool(app.PROXY_OTHERS)
section_data['skipRemovedFiles'] = bool(app.SKIP_REMOVED_FILES)
section_data['epDefaultDeletedStatus'] = app.EP_DEFAULT_DELETED_STATUS
section_data['developer'] = bool(app.DEVELOPER)
diff --git a/themes-default/slim/src/components/config-general.vue b/themes-default/slim/src/components/config-general.vue
index 282065b01c..f9af9b7bee 100644
--- a/themes-default/slim/src/components/config-general.vue
+++ b/themes-default/slim/src/components/config-general.vue
@@ -362,8 +362,20 @@
blank to disable or proxy to use when connecting to providers
+
+
use proxy host for connecting to providers (torrent & nzb)
+
+
-
use proxy host for connecting to indexers (thetvdb)
+
use proxy host for connecting to indexers (thetvdb, tmdb or tvmaze)
+
+
+
+
use proxy host for connecting torrent or usenet clients (nzbGet excluded)