Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing properties #71

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# GVIM stuff #
##############
# Editor stuff #
################
.*.swp
.idea

# Python stuff #
################
Expand Down
74 changes: 72 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,17 +225,20 @@ List of Available Data
| string | tagline | |
| string | overview | |
| integer | runtime | |
| string | status | |
| integer | budget | |
| integer | revenue | |
| datetime | releasedate | |
| string | originallanguage | |
| string | homepage | |
| string | IMDB reference id | 'ttXXXXXXX' |
| string | imdb | imdb reference: 'ttXXXXXXX' |
| Backdrop | backdrop | |
| Poster | poster | |
| float | popularity | |
| float | userrating | |
| integer | votes | |
| boolean | adult | |
| boolean | video | |
| Collection | collection | |
| list(Genre) | genres | |
| list(Studio) | studios | |
Expand All @@ -246,12 +249,14 @@ List of Available Data
| list(Crew) | crew | |
| list(Backdrop) | backdrops | |
| list(Poster) | posters | |
| list(Video) | videos | |
| list(Keyword) | keywords | |
| dict(Release) | releases | indexed by country |
| dict(ReleaseDate) | release_dates | indexed by country |
| list(Translation) | translations | |
| list(Movie) | similar | |
| list(List) | lists | |
| list(Movie) | getSimilar() | |
| list(Movie) | recommendations | |
| None | setFavorite(bool) | mark favorite status for current user |
| None | setRating(int) | rate movie by current user |
| None | setWatchlist(bool) | mark watchlist status for current user |
Expand All @@ -268,6 +273,7 @@ List of Available Data
| list(Movie) | favorites() | current user's favorite movies |
| list(Movie) | ratedmovies() | movies rated by current user |
| list(Movie) | watchlist() | movies marked to watch by current user |
| list(Movie) | discover() | discover movies by different types of data |

#### Series:
| type | name |
Expand Down Expand Up @@ -374,6 +380,9 @@ List of Available Data
| string | homepage |
| Profile | profile |
| boolean | adult |
| integer | gender |
| string | imdb |
| float | popularity |
| list(string) | aliases |
| list(ReverseCast) | roles |
| list(ReverseCrew) | crew |
Expand Down Expand Up @@ -517,3 +526,64 @@ Logo (derived from `Image`)
| dict(Trailer) | sources | indexed by size |
| list(string) | sizes() | |
| string | geturl(size=None) | |


Changelog
---------
- 0.1.0 Initial development
- 0.2.0 Add caching mechanism for API queries
- 0.2.1 Temporary work around for broken search paging
- 0.3.0 Rework backend machinery for managing OO interface to results
- 0.3.1 Add collection support
- 0.3.2 Remove MythTV key from results.py
- 0.3.3 Add functional language support
- 0.3.4 Re-enable search paging
- 0.3.5 Add methods for grabbing current, popular, and top rated movies
- 0.3.6 Rework paging mechanism
- 0.3.7 Generalize caching mechanism, and allow controllability
- 0.4.0 Add full locale support (language and country) and optional fall through
- 0.4.1 Add custom classmethod for dealing with IMDB movie IDs
- 0.4.2 Improve cache file selection for Windows systems
- 0.4.3 Add a few missed Person properties
- 0.4.4 Add support for additional Studio information
- 0.4.5 Add locale fallthrough for images and alternate titles
- 0.4.6 Add slice support for search results
- 0.5.0 Rework cache framework and improve file cache performance
- 0.6.0 Add user authentication support
- 0.6.1 Add adult filtering for people searches
- 0.6.2 Add similar movie search for Movie objects
- 0.6.3 Add Studio search
- 0.6.4 Add Genre list and associated Movie search
- 0.6.5 Prevent data from being blanked out by subsequent queries
- 0.6.6 Turn date processing errors into mutable warnings
- 0.6.7 Add support for searching by year
- 0.6.8 Add support for collection images
- 0.6.9 Correct Movie image language filtering
- 0.6.10 Add upcoming movie classmethod
- 0.6.11 Fix URL for top rated Movie query
- 0.6.12 Add support for Movie watchlist query and editing
- 0.6.13 Fix URL for rating Movies
- 0.6.14 Add support for Lists
- 0.6.15 Add ability to search Collections
- 0.6.16 Make absent primary images return None (previously u'')
- 0.6.17 Add userrating/votes to Image, add overview to Collection, remove
releasedate sorting from Collection Movies
- 0.7.0 Add support for television series data
- 0.7.1 Add rate limiter to cache engine
- 0.7.2 Add similar and keywords to TV Series,
Fix unicode issues with search result object names,
Temporary fix for youtube videos with malformed URLs.
- 0.7.3 Added a few more missing Person properties:
(gender, imdb, popularity),
Added Video element,
Added Movie class method discover,
Added missing Movie properties and methods:
(status, originallanguage, video, videos, recommendations),
Updated API statuses (from https://github.com/pawel-zet),
Added Series methods (from https://github.com/alanjds):
(latest, discover, ontheair, airingtoday, mostpopular, toprated),
PEP8 fixes and some typos,
Updated readme.
- 0.7.4 Added experimental sizes to profiles,
Fixed process_date to handle input dates like "1987-04-03T00:00:00.000Z",
Replaced Movie.releases with Movie.release_dates, following the API.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

setup(
name='tmdb3',
version='0.7.2',
version='0.7.4',
description='TheMovieDB.org APIv3 interface',
long_description=long_description,
author='Raymond Wagner',
Expand Down
10 changes: 7 additions & 3 deletions tmdb3/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

DEBUG = False


class Cache(object):
"""
This class implements a cache framework, allowing selecting of a
Expand Down Expand Up @@ -81,10 +82,13 @@ def get(self, key):
# wait to ensure proper rate limiting
if len(self._rate_limiter) == 30:
w = 10 - (time.time() - self._rate_limiter.pop(0))
if (w > 0):
if w > 0:
if DEBUG:
print "rate limiting - waiting {0} seconds".format(w)
time.sleep(w)
try:
time.sleep(w)
except IOError:
pass
return None

def cached(self, callback):
Expand All @@ -94,7 +98,7 @@ def cached(self, callback):
"""
return self.Cached(self, callback)

class Cached( object ):
class Cached(object):
def __init__(self, cache, callback, func=None, inst=None):
self.cache = cache
self.callback = callback
Expand Down
6 changes: 4 additions & 2 deletions tmdb3/cache_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def _donothing(*args, **kwargs):

try:
import fcntl

class Flock(object):
"""
Context manager to flock file for the duration the object
Expand Down Expand Up @@ -96,7 +97,8 @@ def parse_filename(filename):

except ImportError:
import msvcrt
class Flock( object ):

class Flock(object):
LOCK_EX = msvcrt.LK_LOCK
LOCK_SH = msvcrt.LK_LOCK

Expand Down Expand Up @@ -207,7 +209,7 @@ def dumpdata(self, fd):
fd.write(self._buff.getvalue())


class FileEngine( CacheEngine ):
class FileEngine(CacheEngine):
"""Simple file-backed engine."""
name = 'file'
_struct = struct.Struct('HH') # two shorts for version and count
Expand Down
71 changes: 43 additions & 28 deletions tmdb3/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ def __init__(self, url, **kwargs):
kwargs = {}
for k, v in self._kwargs.items():
kwargs[k] = locale.encode(v)
url = '{0}{1}?{2}'\
.format(self._base_url, self._url, urlencode(kwargs))
url = '{0}{1}?{2}'.format(self._base_url, self._url, urlencode(kwargs))

urllib2.Request.__init__(self, url)
self.add_header('Accept', 'application/json')
Expand Down Expand Up @@ -135,33 +134,49 @@ def readJSON(self):
return data

status_handlers = {
1: None,
2: TMDBRequestInvalid('Invalid service - This service does not exist.'),
3: TMDBRequestError('Authentication Failed - You do not have ' +
'permissions to access this service.'),
4: TMDBRequestInvalid("Invalid format - This service doesn't exist " +
'in that format.'),
5: TMDBRequestInvalid('Invalid parameters - Your request parameters ' +
'are incorrect.'),
6: TMDBRequestInvalid('Invalid id - The pre-requisite id is invalid ' +
'or not found.'),
7: TMDBKeyInvalid('Invalid API key - You must be granted a valid key.'),
8: TMDBRequestError('Duplicate entry - The data you tried to submit ' +
'already exists.'),
9: TMDBOffline('This service is tempirarily offline. Try again later.'),
10: TMDBKeyRevoked('Suspended API key - Access to your account has been ' +
'suspended, contact TMDB.'),
11: TMDBError('Internal error - Something went wrong. Contact TMDb.'),
12: None,
13: None,
14: TMDBRequestError('Authentication Failed.'),
15: TMDBError('Failed'),
16: TMDBError('Device Denied'),
17: TMDBError('Session Denied')}
1: None, # Success
2: TMDBRequestInvalid, # Invalid service
3: TMDBRequestError, # Authentication failed
4: TMDBRequestInvalid, # Invalid format
5: TMDBRequestInvalid, # Invalid parameters
6: TMDBRequestInvalid, # Invalid id
7: TMDBKeyInvalid, # Invalid API key
8: TMDBRequestError, # Duplicate entry
9: TMDBOffline, # Service offline
10: TMDBKeyRevoked, # Suspended API key
11: TMDBError, # Internal error
12: None, # Item update success
13: None, # Item delete success
14: TMDBRequestError, # Authentication failed
15: TMDBError, # Failed
16: TMDBError, # Device denied
17: TMDBError, # Session denied
18: TMDBRequestError, # Validation denied
19: TMDBRequestInvalid, # Invalid accept header
20: TMDBRequestInvalid, # Invalid date range
21: TMDBRequestError, # Entry not found
22: TMDBPagingIssue, # Invalid page
23: TMDBRequestInvalid, # Invalud date
24: TMDBError, # Request time out
25: TMDBRequestError, # Request limit reached
26: TMDBRequestInvalid, # Missing usernam and password
27: TMDBRequestError, # Too many append
28: TMDBRequestInvalid, # Invalud timezone
29: TMDBRequestInvalid, # Action confirmation required
30: TMDBRequestError, # Invalid username or password
31: TMDBRequestError, # Accound disabled
32: TMDBRequestError, # Email not verified,
33: TMDBKeyInvalid, # Invalud request token
34: TMDBRequestError # Resource could not be found
}


def handle_status(data, query):
status = status_handlers[data.get('status_code', 1)]
if status is not None:
status.tmdberrno = data['status_code']
status_code = data.get('status_code', 1)
exception_class = status_handlers[status_code]
if exception_class is not None:
status_message = data.get('status_message', None)
status = exception_class(status_message)
status.tmdberrno = status_code
status.query = query
raise status
Loading