Skip to content

Commit

Permalink
Add Genre list and associated Movie search
Browse files Browse the repository at this point in the history
  • Loading branch information
wagnerrp committed Jun 21, 2012
1 parent c2bb6ae commit 6e7725d
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 5 deletions.
10 changes: 9 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ on-demand as used, rather than when the object is created.
>>> Studio(1)
<Studio 'Lucasfilm'>

The Genre class cannot be called by id directly, however it does have a getAll
classmethod, capable of returning all available genres for a specified
language.

## Image Behavior

TheMovieDb currently offers three types of artwork: backdrops, posters, and
Expand Down Expand Up @@ -220,7 +224,7 @@ Movie:
list(Translation) translations
list(Movie) getSimilar()

Movie classmethods
Movie classmethods:
Movie fromIMDB(imdbid) special constructor for use with IMDb codes
Movie latest() gets latest movie added to database
list(Movie) nowplaying() content currently in theater
Expand Down Expand Up @@ -287,6 +291,10 @@ Translation:
Genre:
integer id
string name
list(Movie) movies

Genre classmethods:
list(Genre) getAll(language) returns list of all genres

Studio:
integer id
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

setup(
name='tmdb3',
version='0.6.3',
version='0.6.4',
description='TheMovieDB.org APIv3 interface',
long_description="Object-oriented interface to TheMovieDB.org's v3 API.",
packages=['tmdb3']
Expand Down
2 changes: 1 addition & 1 deletion tmdb3/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python

from tmdb_api import Configuration, searchMovie, searchPerson, searchStudio, \
Studio, Person, Movie, Collection, __version__
Studio, Person, Movie, Collection, Genre, __version__
from request import set_key, set_cache
from locales import get_locale, set_locale
from tmdb_auth import get_session, set_session
Expand Down
25 changes: 24 additions & 1 deletion tmdb3/tmdb_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
Preliminary API specifications can be found at
http://help.themoviedb.org/kb/api/about-3"""

__version__="v0.6.2"
__version__="v0.6.4"
# 0.1.0 Initial development
# 0.2.0 Add caching mechanism for API queries
# 0.2.1 Temporary work around for broken search paging
Expand All @@ -46,6 +46,7 @@
# 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

from request import set_key, Request
from util import Datapoint, Datalist, Datadict, Element, NameRepr, SearchRepr
Expand Down Expand Up @@ -286,6 +287,28 @@ class Genre( NameRepr, Element ):
id = Datapoint('id')
name = Datapoint('name')

def _populate_movies(self):
return Request('genre/{0}/movies'.format(self.id), \
language=self._locale.language)

@property
def movies(self):
if 'movies' not in self._data:
search = MovieSearchResult(self._populate_movies(), \
locale=self._locale)
search._name = "{0.name} Movies".format(self)
self._data['movies'] = search
return self._data['movies']

@classmethod
def getAll(cls, locale=None):
class GenreList( Element ):
genres = Datalist('genres', handler=Genre)
def _populate(self):
return Request('genre/list', language=self._locale.language)
return GenreList(locale=locale).genres


class Studio( NameRepr, Element ):
id = Datapoint('id', initarg=1)
name = Datapoint('name')
Expand Down
2 changes: 1 addition & 1 deletion tmdb3/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def __new__(mcs, name, bases, attrs):

def __call__(cls, *args, **kwargs):
obj = cls.__new__(cls)
if 'locale' in kwargs:
if ('locale' in kwargs) and (kwargs['locale'] is not None):
obj._locale = kwargs['locale']
else:
obj._locale = get_locale()
Expand Down

0 comments on commit 6e7725d

Please sign in to comment.