You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

510 lines
15 KiB

Change core system to improve performance and facilitate multi TV info sources. Change migrate core objects TVShow and TVEpisode and everywhere that these objects affect. Add message to logs and disable ui backlog buttons when no media provider has active and/or scheduled searching enabled. Change views for py3 compat. Change set default runtime of 5 mins if none is given for layout Day by Day. Add OpenSubtitles authentication support to config/Subtitles/Subtitles Plugin. Add "Enforce media hash match" to config/Subtitles Plugin/Opensubtitles for accurate subs if enabled, but if disabled, search failures will fallback to use less reliable subtitle results. Add Apprise 0.8.0 (6aa52c3). Add hachoir_py3 3.0a6 (5b9e05a). Add sgmllib3k 1.0.0 Update soupsieve 1.9.1 (24859cc) to soupsieve_py2 1.9.5 (6a38398) Add soupsieve_py3 2.0.0.dev (69194a2). Add Tornado_py3 Web Server 6.0.3 (ff985fe). Add xmlrpclib_to 0.1.1 (c37db9e). Remove ancient Growl lib 0.1 Remove xmltodict library. Change requirements.txt for Cheetah3 to minimum 3.2.4 Change update sabToSickBeard. Change update autoProcessTV. Change remove Twitter notifier. Update NZBGet Process Media extension, SickGear-NG 1.7 → 2.4 Update Kodi addon 1.0.3 → 1.0.4 Update ADBA for py3. Update Beautiful Soup 4.8.0 (r526) to 4.8.1 (r531). Update Send2Trash 1.3.0 (a568370) to 1.5.0 (66afce7). Update soupsieve 1.9.1 (24859cc) to 1.9.5 (6a38398). Change use GNTP (Growl Notification Transport Protocol) from Apprise. Change add multi host support to Growl notifier. Fix Growl notifier when using empty password. Change update links for Growl notifications. Change deprecate confg/Notifications/Growl password field as these are now stored with host setting. Fix prevent infinite memoryError from a particular jpg data structure. Change subliminal for py3. Change enzyme for py3. Change browser_ua for py3. Change feedparser for py3 (sgmlib is no longer available on py3 as standardlib so added ext lib) Fix Guessit. Fix parse_xml for py3. Fix name parser with multi eps for py3. Fix tvdb_api fixes for py3 (search show). Fix config/media process to only display "pattern is invalid" qtip on "Episode naming" tab if the associated field is actually visible. Also, if the field becomes hidden due to a setting change, hide any previously displayed qtip. Note for Javascript::getelementbyid (or $('tag[id="<name>"')) is required when an id is being searched in the dom due to ":" used in a shows id name. Change download anidb xml files to main cache folder and use adba lib folder as a last resort. Change create get anidb show groups as centralised helper func and consolidate dupe code. Change move anidb related functions to newly renamed anime.py (from blacklistandwhitelist.py). Change str encode hex no longer exits in py3, use codecs.encode(...) instead. Change fix b64decode on py3 returns bytestrings. Change use binary read when downloading log file via browser to prevent any encoding issues. Change add case insensitive ordering to anime black/whitelist. Fix anime groups list not excluding whitelisted stuff. Change add Windows utf8 fix ... see: ytdl-org/youtube-dl#820 Change if no qualities are wanted, exit manual search thread. Fix keepalive for py3 process media. Change add a once a month update of tvinfo show mappings to the daily updater. Change autocorrect ids of new shows by updating from -8 to 31 days of the airdate of episode one. Add next run time to Manage/Show Tasks/Daily show update. Change when fetching imdb data, if imdb id is an episode id then try to find and use real show id. Change delete diskcache db in imdbpie when value error (due to change in Python version). Change during startup, cleanup any _cleaner.pyc/o to prevent issues when switching python versions. Add .pyc cleaner if python version is switched. Change replace deprecated gettz_db_metadata() and gettz. Change rebrand "SickGear PostProcessing script" to "SickGear Process Media extension". Change improve setup guide to use the NZBGet version to minimise displayed text based on version. Change NZBGet versions prior to v17 now told to upgrade as those version are no longer supported - code has actually exit on start up for some time but docs were outdated. Change comment out code and unused option sg_base_path. Change supported Python version 2.7.9-2.7.18 inclusive expanded to 3.7.1-3.8.1 inclusive. Change pidfile creation under Linux 0o644. Make logger accept lists to output continuously using the log_lock instead of split up by other processes. Fix long path issues with Windows process media.
6 years ago
# -*- coding: utf-8 -*-
"""
tmdbsimple.account
~~~~~~~~~~~~~~~~~~
This module implements the Account, Authentication, and Lists functionality
of tmdbsimple.
Created by Celia Oakley on 2013-10-31.
:copyright: (c) 2013-2020 by Celia Oakley
Change core system to improve performance and facilitate multi TV info sources. Change migrate core objects TVShow and TVEpisode and everywhere that these objects affect. Add message to logs and disable ui backlog buttons when no media provider has active and/or scheduled searching enabled. Change views for py3 compat. Change set default runtime of 5 mins if none is given for layout Day by Day. Add OpenSubtitles authentication support to config/Subtitles/Subtitles Plugin. Add "Enforce media hash match" to config/Subtitles Plugin/Opensubtitles for accurate subs if enabled, but if disabled, search failures will fallback to use less reliable subtitle results. Add Apprise 0.8.0 (6aa52c3). Add hachoir_py3 3.0a6 (5b9e05a). Add sgmllib3k 1.0.0 Update soupsieve 1.9.1 (24859cc) to soupsieve_py2 1.9.5 (6a38398) Add soupsieve_py3 2.0.0.dev (69194a2). Add Tornado_py3 Web Server 6.0.3 (ff985fe). Add xmlrpclib_to 0.1.1 (c37db9e). Remove ancient Growl lib 0.1 Remove xmltodict library. Change requirements.txt for Cheetah3 to minimum 3.2.4 Change update sabToSickBeard. Change update autoProcessTV. Change remove Twitter notifier. Update NZBGet Process Media extension, SickGear-NG 1.7 → 2.4 Update Kodi addon 1.0.3 → 1.0.4 Update ADBA for py3. Update Beautiful Soup 4.8.0 (r526) to 4.8.1 (r531). Update Send2Trash 1.3.0 (a568370) to 1.5.0 (66afce7). Update soupsieve 1.9.1 (24859cc) to 1.9.5 (6a38398). Change use GNTP (Growl Notification Transport Protocol) from Apprise. Change add multi host support to Growl notifier. Fix Growl notifier when using empty password. Change update links for Growl notifications. Change deprecate confg/Notifications/Growl password field as these are now stored with host setting. Fix prevent infinite memoryError from a particular jpg data structure. Change subliminal for py3. Change enzyme for py3. Change browser_ua for py3. Change feedparser for py3 (sgmlib is no longer available on py3 as standardlib so added ext lib) Fix Guessit. Fix parse_xml for py3. Fix name parser with multi eps for py3. Fix tvdb_api fixes for py3 (search show). Fix config/media process to only display "pattern is invalid" qtip on "Episode naming" tab if the associated field is actually visible. Also, if the field becomes hidden due to a setting change, hide any previously displayed qtip. Note for Javascript::getelementbyid (or $('tag[id="<name>"')) is required when an id is being searched in the dom due to ":" used in a shows id name. Change download anidb xml files to main cache folder and use adba lib folder as a last resort. Change create get anidb show groups as centralised helper func and consolidate dupe code. Change move anidb related functions to newly renamed anime.py (from blacklistandwhitelist.py). Change str encode hex no longer exits in py3, use codecs.encode(...) instead. Change fix b64decode on py3 returns bytestrings. Change use binary read when downloading log file via browser to prevent any encoding issues. Change add case insensitive ordering to anime black/whitelist. Fix anime groups list not excluding whitelisted stuff. Change add Windows utf8 fix ... see: ytdl-org/youtube-dl#820 Change if no qualities are wanted, exit manual search thread. Fix keepalive for py3 process media. Change add a once a month update of tvinfo show mappings to the daily updater. Change autocorrect ids of new shows by updating from -8 to 31 days of the airdate of episode one. Add next run time to Manage/Show Tasks/Daily show update. Change when fetching imdb data, if imdb id is an episode id then try to find and use real show id. Change delete diskcache db in imdbpie when value error (due to change in Python version). Change during startup, cleanup any _cleaner.pyc/o to prevent issues when switching python versions. Add .pyc cleaner if python version is switched. Change replace deprecated gettz_db_metadata() and gettz. Change rebrand "SickGear PostProcessing script" to "SickGear Process Media extension". Change improve setup guide to use the NZBGet version to minimise displayed text based on version. Change NZBGet versions prior to v17 now told to upgrade as those version are no longer supported - code has actually exit on start up for some time but docs were outdated. Change comment out code and unused option sg_base_path. Change supported Python version 2.7.9-2.7.18 inclusive expanded to 3.7.1-3.8.1 inclusive. Change pidfile creation under Linux 0o644. Make logger accept lists to output continuously using the log_lock instead of split up by other processes. Fix long path issues with Windows process media.
6 years ago
:license: GPLv3, see LICENSE for more details
"""
from .base import TMDB
class Account(TMDB):
"""
Account functionality.
See: https://developers.themoviedb.org/3/account
https://www.themoviedb.org/documentation/api/sessions
"""
BASE_PATH = 'account'
URLS = {
'info': '',
'lists': '/{id}/lists',
'favorite_movies': '/{id}/favorite/movies',
'favorite_tv': '/{id}/favorite/tv',
'favorite': '/{id}/favorite',
'rated_movies': '/{id}/rated/movies',
'rated_tv': '/{id}/rated/tv',
'watchlist_movies': '/{id}/watchlist/movies',
'watchlist_tv': '/{id}/watchlist/tv',
'watchlist': '/{id}/watchlist',
}
def __init__(self, session_id):
super(Account, self).__init__()
self.session_id = session_id
def info(self, **kwargs):
"""
Get the basic information for an account.
Call this method first, before calling other Account methods.
Returns:
A dict respresentation of the JSON returned from the API.
"""
path = self._get_path('info')
kwargs.update({'session_id': self.session_id})
response = self._GET(path, kwargs)
self.id = response['id']
self._set_attrs_to_values(response)
return response
def lists(self, **kwargs):
"""
Get the lists that you have created and marked as a favorite.
Args:
page: (optional) Minimum 1, maximum 1000.
language: (optional) ISO 639-1 code.
Returns:
A dict respresentation of the JSON returned from the API.
"""
path = self._get_id_path('lists')
kwargs.update({'session_id': self.session_id})
response = self._GET(path, kwargs)
self._set_attrs_to_values(response)
return response
def favorite_movies(self, **kwargs):
"""
Get the list of favorite movies for an account.
Args:
page: (optional) Minimum 1, maximum 1000.
sort_by: (optional) 'created_at.asc' | 'created_at.desc'
language: (optional) ISO 639-1 code.
Returns:
A dict respresentation of the JSON returned from the API.
"""
path = self._get_id_path('favorite_movies')
kwargs.update({'session_id': self.session_id})
response = self._GET(path, kwargs)
self._set_attrs_to_values(response)
return response
def favorite_tv(self, **kwargs):
"""
Get the list of favorite TV series for an account.
Args:
page: (optional) Minimum 1, maximum 1000.
sort_by: (optional) 'created_at.asc' | 'created_at.desc'
language: (optional) ISO 639-1 code.
Returns:
A dict respresentation of the JSON returned from the API.
"""
path = self._get_id_path('favorite_tv')
kwargs.update({'session_id': self.session_id})
response = self._GET(path, kwargs)
self._set_attrs_to_values(response)
return response
def favorite(self, **kwargs):
"""
Add or remove a movie to an accounts favorite list.
Args:
media_type: 'movie' | 'tv'
media_id: The id of the media.
favorite: True (to add) | False (to remove).
Returns:
A dict respresentation of the JSON returned from the API.
"""
path = self._get_id_path('favorite')
kwargs.update({'session_id': self.session_id})
payload = {
'media_type': kwargs.pop('media_type', None),
'media_id': kwargs.pop('media_id', None),
'favorite': kwargs.pop('favorite', None),
}
response = self._POST(path, kwargs, payload)
self._set_attrs_to_values(response)
return response
def rated_movies(self, **kwargs):
"""
Get the list of rated movies (and associated rating) for an account.
Args:
page: (optional) Minimum 1, maximum 1000.
sort_by: (optional) 'created_at.asc' | 'created_at.desc'
language: (optional) ISO 639-1 code.
Returns:
A dict respresentation of the JSON returned from the API.
"""
path = self._get_id_path('rated_movies')
kwargs.update({'session_id': self.session_id})
response = self._GET(path, kwargs)
self._set_attrs_to_values(response)
return response
def rated_tv(self, **kwargs):
"""
Get the list of rated TV shows (and associated rating) for an account.
Args:
page: (optional) Minimum 1, maximum 1000.
sort_by: (optional) 'created_at.asc' | 'created_at.desc'
language: (optional) ISO 639-1 code.
Returns:
A dict respresentation of the JSON returned from the API.
"""
path = self._get_id_path('rated_tv')
kwargs.update({'session_id': self.session_id})
response = self._GET(path, kwargs)
self._set_attrs_to_values(response)
return response
def watchlist_movies(self, **kwargs):
"""
Get the list of movies on an account watchlist.
Args:
page: (optional) Minimum 1, maximum 1000.
sort_by: (optional) 'created_at.asc' | 'created_at.desc'
language: (optional) ISO 639-1 code.
Returns:
A dict respresentation of the JSON returned from the API.
"""
path = self._get_id_path('watchlist_movies')
kwargs.update({'session_id': self.session_id})
response = self._GET(path, kwargs)
self._set_attrs_to_values(response)
return response
def watchlist_tv(self, **kwargs):
"""
Get the list of TV series on an account watchlist.
Args:
page: (optional) Minimum 1, maximum 1000.
sort_by: (optional) 'created_at.asc' | 'created_at.desc'
language: (optional) ISO 639-1 code.
Returns:
A dict respresentation of the JSON returned from the API.
"""
path = self._get_id_path('watchlist_tv')
kwargs.update({'session_id': self.session_id})
response = self._GET(path, kwargs)
self._set_attrs_to_values(response)
return response
def watchlist(self, **kwargs):
"""
Add or remove a movie to an accounts watch list.
Args:
media_type: 'movie' | 'tv'
media_id: The id of the media.
watchlist: True (to add) | False (to remove).
Returns:
A dict respresentation of the JSON returned from the API.
"""
path = self._get_id_path('watchlist')
kwargs.update({'session_id': self.session_id})
payload = {
'media_type': kwargs.pop('media_type', None),
'media_id': kwargs.pop('media_id', None),
'watchlist': kwargs.pop('watchlist', None),
}
response = self._POST(path, kwargs, payload)
self._set_attrs_to_values(response)
return response
class Authentication(TMDB):
"""
Authentication functionality.
See: https://developers.themoviedb.org/3/authentication
https://www.themoviedb.org/documentation/api/sessions
"""
BASE_PATH = 'authentication'
URLS = {
'token_new': '/token/new',
'token_validate_with_login': '/token/validate_with_login',
'session_new': '/session/new',
'guest_session_new': '/guest_session/new',
}
def token_new(self, **kwargs):
"""
Generate a valid request token for user based authentication.
A request token is required to ask the user for permission to
access their account.
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.
Returns:
A dict respresentation of the JSON returned from the API.
"""
path = self._get_path('token_new')
response = self._GET(path, kwargs)
self._set_attrs_to_values(response)
return response
def token_validate_with_login(self, **kwargs):
"""
Authenticate a user with a TMDb username and password. The user
must have a verified email address and be registered on TMDb.
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')
response = self._GET(path, kwargs)
self._set_attrs_to_values(response)
return response
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.
Args:
request_token: The token you generated for the user to approve.
The token needs to be approved before being
used here.
Returns:
A dict respresentation of the JSON returned from the API.
"""
path = self._get_path('session_new')
response = self._GET(path, kwargs)
self._set_attrs_to_values(response)
return response
def guest_session_new(self, **kwargs):
"""
Generate a guest session id.
Returns:
A dict respresentation of the JSON returned from the API.
"""
path = self._get_path('guest_session_new')
response = self._GET(path, kwargs)
self._set_attrs_to_values(response)
return response
class GuestSessions(TMDB):
"""
Guest Sessions functionality.
See: https://developers.themoviedb.org/3/guest-sessions
"""
BASE_PATH = 'guest_session'
URLS = {
'rated_movies': '/{guest_session_id}/rated_movies',
}
def __init__(self, guest_session_id=0):
super(GuestSessions, self).__init__()
self.guest_session_id = guest_session_id
def rated_movies(self, **kwargs):
"""
Get a list of rated moview for a specific guest session id.
Args:
page: (optional) Minimum 1, maximum 1000.
sort_by: (optional) 'created_at.asc' | 'created_at.desc'
language: (optional) ISO 639-1 code.
Returns:
A dict respresentation of the JSON returned from the API.
"""
path = self._get_guest_session_id_path('rated_movies')
response = self._GET(path, kwargs)
self._set_attrs_to_values(response)
return response
class Lists(TMDB):
"""
Lists functionality.
See: https://developers.themoviedb.org/3/lists
"""
BASE_PATH = 'list'
URLS = {
'info': '/{id}',
'item_status': '/{id}/item_status',
'create_list': '',
'add_item': '/{id}/add_item',
'remove_item': '/{id}/remove_item',
'clear': '/{id}/clear',
}
def __init__(self, id=0, session_id=0):
super(Lists, self).__init__()
self.id = id
self.session_id = session_id
def info(self, **kwargs):
"""
Get a list by id.
Returns:
A dict respresentation of the JSON returned from the API.
"""
path = self._get_id_path('info')
response = self._GET(path, kwargs)
self._set_attrs_to_values(response)
return response
def item_status(self, **kwargs):
"""
Check to see if a movie id is already added to a list.
Args:
movie_id: The id of the movie.
Returns:
A dict respresentation of the JSON returned from the API.
"""
path = self._get_id_path('item_status')
response = self._GET(path, kwargs)
self._set_attrs_to_values(response)
return response
def create_list(self, **kwargs):
"""
Create a new list.
A valid session id is required.
Args:
name: Name of the list.
description: Description of the list.
language: (optional) ISO 639-1 code.
Returns:
A dict respresentation of the JSON returned from the API.
"""
path = self._get_path('create_list')
kwargs.update({'session_id': self.session_id})
payload = {
'name': kwargs.pop('name', None),
'description': kwargs.pop('description', None),
}
if 'language' in kwargs:
payload['language'] = kwargs['language']
response = self._POST(path, kwargs, payload)
self._set_attrs_to_values(response)
return response
def add_item(self, **kwargs):
"""
Add new movies to a list that the user created.
A valid session id is required.
Args:
media_id: A movie id.
Returns:
A dict respresentation of the JSON returned from the API.
"""
path = self._get_id_path('add_item')
kwargs.update({'session_id': self.session_id})
payload = {
'media_id': kwargs.pop('media_id', None),
}
response = self._POST(path, kwargs, payload)
self._set_attrs_to_values(response)
return response
def remove_item(self, **kwargs):
"""
Delete movies from a list that the user created.
A valid session id is required.
Args:
media_id: A movie id.
Returns:
A dict respresentation of the JSON returned from the API.
"""
path = self._get_id_path('remove_item')
kwargs.update({'session_id': self.session_id})
payload = {
'media_id': kwargs.pop('media_id', None),
}
response = self._POST(path, kwargs, payload)
self._set_attrs_to_values(response)
return response
def clear_list(self, **kwargs):
"""
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.
Args:
confirm: True (do it) | False (don't do it)
Returns:
A dict respresentation of the JSON returned from the API.
"""
path = self._get_id_path('clear')
kwargs.update({'session_id': self.session_id})
payload = {}
response = self._POST(path, kwargs, payload)
self._set_attrs_to_values(response)
return response