class Series(Element): id = Datapoint('id', initarg=1) backdrop = Datapoint('backdrop_path', handler=Backdrop, raw=False, default=None) studios = Datalist('created_by', handler=Person) runtime = Datalist('episode_run_time') genres = Datalist('genres', handler=Genre) homepage = Datapoint('homepage') in_production = Datapoint('in_production') languages = Datalist('languages') countries = Datalist('origin_country') title = Datapoint('name') originaltitle = Datapoint('original_name') number_of_episodes = Datapoint('number_of_episodes') number_of_seasons = Datapoint('number_of_seasons') overview = Datapoint('overview') popularity = Datapoint('popularity') status = Datapoint('status') userrating = Datapoint('vote_average') votes = Datapoint('vote_count') poster = Datapoint('poster_path', handler=Poster, raw=False, default=None) seasons = Datadict('seasons', attr='season_number', handler=Season, passthrough={'id': 'series_id'}) def _populate_cast(self): return Request('tv/{0}/credits'.format(self.id)) cast = Datalist('cast', handler=Cast, poller=_populate_cast, sort='order') crew = Datalist('crew', handler=Crew, poller=_populate_cast)
class Season(NameRepr, Element): season_number = Datapoint('season_number', initarg=2) series_id = Datapoint('series_id', initarg=1) id = Datapoint('id') air_date = Datapoint('air_date', handler=process_date) poster = Datapoint('poster_path', handler=Poster, raw=False, default=None) overview = Datapoint('overview') name = Datapoint('name') episodes = Datadict('episodes', attr='episode_number', handler=Episode, passthrough={'series_id': 'series_id', 'season_number': 'season_number'}) def _populate(self): return Request('tv/{0}/season/{1}'.format(self.series_id, self.season_number), language=self._locale.language) def _populate_images(self): kwargs = {} if not self._locale.fallthrough: kwargs['language'] = self._locale.language return Request('tv/{0}/season/{1}/images'.format(self.series_id, self.season_number), **kwargs) def _populate_external_ids(self): return Request('tv/{0}/season/{1}/external_ids'.format(self.series_id, self.season_number)) posters = Datalist('posters', handler=Poster, poller=_populate_images, sort=True) freebase_id = Datapoint('freebase_id', poller=_populate_external_ids) freebase_mid = Datapoint('freebase_mid', poller=_populate_external_ids) tvdb_id = Datapoint('tvdb_id', poller=_populate_external_ids) tvrage_id = Datapoint('tvrage_id', poller=_populate_external_ids)
class AppleTrailer( Element ): name = Datapoint('name') sources = Datadict('sources', handler=Trailer, attr='size') def sizes(self): return self.sources.keys() def geturl(self, size=None): if size is None: # sort assuming ###p format for now, take largest resolution size = str(sorted([int(size[:-1]) for size in self.sources])[-1])+'p' return self.sources[size].source def __repr__(self): return u"<{0.__class__.__name__} '{0.name}'>".format(self)
class Movie(Element): @classmethod def latest(cls): req = Request('latest/movie') req.lifetime = 600 return cls(raw=req.readJSON()) @classmethod def discover(cls, locale=None, **kwargs): res = MovieSearchResult(Request('discover/movie', **kwargs), locale=locale) res._name = 'Discover' return res @classmethod def nowplaying(cls, locale=None): res = MovieSearchResult(Request('movie/now_playing'), locale=locale) res._name = 'Now Playing' return res @classmethod def mostpopular(cls, locale=None): res = MovieSearchResult(Request('movie/popular'), locale=locale) res._name = 'Popular' return res @classmethod def toprated(cls, locale=None): res = MovieSearchResult(Request('movie/top_rated'), locale=locale) res._name = 'Top Rated' return res @classmethod def upcoming(cls, locale=None): res = MovieSearchResult(Request('movie/upcoming'), locale=locale) res._name = 'Upcoming' return res @classmethod def favorites(cls, session=None): if session is None: session = get_session() account = Account(session=session) res = MovieSearchResult( Request('account/{0}/favorite_movies'.format(account.id), session_id=session.sessionid)) res._name = "Favorites" return res @classmethod def ratedmovies(cls, session=None): if session is None: session = get_session() account = Account(session=session) res = MovieSearchResult( Request('account/{0}/rated_movies'.format(account.id), session_id=session.sessionid)) res._name = "Movies You Rated" return res @classmethod def watchlist(cls, session=None): if session is None: session = get_session() account = Account(session=session) res = MovieSearchResult( Request('account/{0}/movie_watchlist'.format(account.id), session_id=session.sessionid)) res._name = "Movies You're Watching" return res @classmethod def fromIMDB(cls, imdbid, locale=None): try: # assume string if not imdbid.startswith('tt'): imdbid = "tt{0:0>7}".format(imdbid) except AttributeError: # assume integer imdbid = "tt{0:0>7}".format(imdbid) if locale is None: locale = get_locale() movie = cls(imdbid, locale=locale) movie._populate() return movie id = Datapoint('id', initarg=1) title = Datapoint('title') originaltitle = Datapoint('original_title') tagline = Datapoint('tagline') overview = Datapoint('overview') runtime = Datapoint('runtime') budget = Datapoint('budget') revenue = Datapoint('revenue') releasedate = Datapoint('release_date', handler=process_date) homepage = Datapoint('homepage') imdb = Datapoint('imdb_id') originallanguage = Datapoint('original_language') status = Datapoint('status') backdrop = Datapoint('backdrop_path', handler=Backdrop, raw=False, default=None) poster = Datapoint('poster_path', handler=Poster, raw=False, default=None) popularity = Datapoint('popularity') userrating = Datapoint('vote_average') votes = Datapoint('vote_count') adult = Datapoint('adult') video = Datapoint('video') collection = Datapoint('belongs_to_collection', handler=lambda x: Collection(raw=x)) genres = Datalist('genres', handler=Genre) studios = Datalist('production_companies', handler=Studio) countries = Datalist('production_countries', handler=Country) languages = Datalist('spoken_languages', handler=Language) def _populate(self): return Request('movie/{0}'.format(self.id), language=self._locale.language) def _populate_titles(self): kwargs = {} if not self._locale.fallthrough: kwargs['country'] = self._locale.country return Request('movie/{0}/alternative_titles'.format(self.id), **kwargs) # TODO: implement changes # def _populate_changes(self): # return Request('movie/{movie_id}/changes').format(movie_id=self.id) def _populate_credits(self): return Request('movie/{0}/credits'.format(self.id)) def _populate_images(self): kwargs = {} if not self._locale.fallthrough: kwargs['language'] = self._locale.language return Request('movie/{0}/images'.format(self.id), **kwargs) def _populate_keywords(self): return Request('movie/{0}/keywords'.format(self.id)) def _populate_releases(self): return Request('movie/{0}/releases'.format(self.id)) def _populate_trailers(self): return Request('movie/{0}/trailers'.format(self.id), language=self._locale.language) def _populate_videos(self): return Request('movie/{0}/videos'.format(self.id), language=self._locale.language) def _populate_translations(self): return Request('movie/{0}/translations'.format(self.id)) alternate_titles = Datalist('titles', handler=AlternateTitle, poller=_populate_titles, sort=True) cast = Datalist('cast', handler=Cast, poller=_populate_credits, sort='order') crew = Datalist('crew', handler=Crew, poller=_populate_credits) backdrops = Datalist('backdrops', handler=Backdrop, poller=_populate_images, sort=True) posters = Datalist('posters', handler=Poster, poller=_populate_images, sort=True) keywords = Datalist('keywords', handler=Keyword, poller=_populate_keywords) releases = Datadict('countries', handler=Release, poller=_populate_releases, attr='country') youtube_trailers = Datalist('youtube', handler=YoutubeTrailer, poller=_populate_trailers) apple_trailers = Datalist('quicktime', handler=AppleTrailer, poller=_populate_trailers) videos = Datalist('results', handler=Video, poller=_populate_videos) translations = Datalist('translations', handler=Translation, poller=_populate_translations) def setFavorite(self, value): req = Request('account/{0}/favorite'.format( Account(session=self._session).id), session_id=self._session.sessionid) req.add_data({'movie_id': self.id, 'favorite': str(bool(value)).lower()}) req.lifetime = 0 req.readJSON() def setRating(self, value): if not (0 <= value <= 10): raise TMDBError("Ratings must be between '0' and '10'.") req = Request('movie/{0}/rating'.format(self.id), session_id=self._session.sessionid) req.lifetime = 0 req.add_data({'value': value}) req.readJSON() def setWatchlist(self, value): req = Request('account/{0}/movie_watchlist'.format( Account(session=self._session).id), session_id=self._session.sessionid) req.lifetime = 0 req.add_data({'movie_id': self.id, 'movie_watchlist': str(bool(value)).lower()}) req.readJSON() def getSimilar(self): return self.similar @property def similar(self): res = MovieSearchResult(Request( 'movie/{0}/similar'.format(self.id)), locale=self._locale) res._name = 'Similar to {0}'.format(self._printable_name()) return res @property def recommendations(self): res = MovieSearchResult(Request( 'movie/{0}/recommendations'.format(self.id)), locale=self._locale) res._name = 'Recommendations for {0}'.format(self._printable_name()) return res @property def lists(self): res = ListSearchResult(Request('movie/{0}/lists'.format(self.id))) res._name = "Lists containing {0}".format(self._printable_name()) return res def _printable_name(self): if self.title is not None: s = u"'{0}'".format(self.title) elif self.originaltitle is not None: s = u"'{0}'".format(self.originaltitle) else: s = u"'No Title'" if self.releasedate: s = u"{0} ({1})".format(s, self.releasedate.year) return s def __repr__(self): return u"<{0} {1}>".format(self.__class__.__name__, self._printable_name()).encode('utf-8')
class Movie(Element): id = Datapoint('id', initarg=1) title = Datapoint('title') originaltitle = Datapoint('original_title') tagline = Datapoint('tagline') overview = Datapoint('overview') runtime = Datapoint('runtime') budget = Datapoint('budget') revenue = Datapoint('revenue') releasedate = Datapoint('release_date', handler=lambda x: \ datetime.datetime.strptime(x, '%Y-%m-%d')) homepage = Datapoint('homepage') imdb = Datapoint('imdb_id') backdrop = Datapoint('backdrop_path', handler=Backdrop, raw=False) poster = Datapoint('poster_path', handler=Poster, raw=False) popularity = Datapoint('popularity') userrating = Datapoint('vote_average') votes = Datapoint('vote_count') adult = Datapoint('adult') collection = Datapoint('belongs_to_collection') #, handler=Collection) genres = Datalist('genres', handler=Genre) studios = Datalist('production_companies', handler=Studio) countries = Datalist('production_countries', handler=Country) languages = Datalist('spoken_languages', handler=Language) def _populate(self): return Request('movie/{0}'.format(self.id)).readJSON() def _populate_titles(self): return Request('movie/{0}/alternate_titles'.format(self.id)).readJSON() def _populate_cast(self): return Request('movie/{0}/casts'.format(self.id)).readJSON() def _populate_images(self): return Request('movie/{0}/images'.format(self.id)).readJSON() def _populate_keywords(self): return Request('movie/{0}/keywords'.format(self.id)).readJSON() def _populate_releases(self): return Request('movie/{0}/releases'.format(self.id)).readJSON() def _populate_trailers(self): return Request('movie/{0}/trailers'.format(self.id)).readJSON() def _populate_translations(self): return Request('movie/{0}/translations'.format(self.id)).readJSON() alternate_titles = Datalist('titles', handler=AlternateTitle, poller=_populate_titles) cast = Datalist('cast', handler=Cast, poller=_populate_cast, sort='order') crew = Datalist('crew', handler=Crew, poller=_populate_cast) backdrops = Datalist('backdrops', handler=Backdrop, poller=_populate_images) posters = Datalist('posters', handler=Poster, poller=_populate_images) keywords = Datalist('keywords', handler=Keyword, poller=_populate_keywords) releases = Datadict('countries', handler=Release, poller=_populate_releases, attr='country') youtube_trailers = Datalist('youtube', handler=Trailer, poller=_populate_trailers) apple_trailers = Datalist('quicktime', handler=Trailer, poller=_populate_trailers) translations = Datalist('translations', handler=Translation, poller=_populate_translations) def __repr__(self): if self.title is not None: s = u"'{0}'".format(self.title) elif self.originaltitle is not None: s = u"'{0}'".format(self.originaltitle) else: s = u"'No Title'" if self.releasedate: s = u"{0} ({1})".format(s, self.releasedate.year) return u"<{0} {1}>".format(self.__class__.__name__, s).encode('utf-8')
class Series(NameRepr, Element): id = Datapoint('id', initarg=1) backdrop = Datapoint('backdrop_path', handler=Backdrop, raw=False, default=None) authors = Datalist('created_by', handler=Person) episode_run_times = Datalist('episode_run_time') first_air_date = Datapoint('first_air_date', handler=process_date) last_air_date = Datapoint('last_air_date', handler=process_date) genres = Datalist('genres', handler=Genre) homepage = Datapoint('homepage') in_production = Datapoint('in_production') languages = Datalist('languages') origin_countries = Datalist('origin_country') name = Datapoint('name') original_name = Datapoint('original_name') number_of_episodes = Datapoint('number_of_episodes') number_of_seasons = Datapoint('number_of_seasons') overview = Datapoint('overview') popularity = Datapoint('popularity') status = Datapoint('status') userrating = Datapoint('vote_average') votes = Datapoint('vote_count') poster = Datapoint('poster_path', handler=Poster, raw=False, default=None) networks = Datalist('networks', handler=Network) seasons = Datadict('seasons', attr='season_number', handler=Season, passthrough={'id': 'series_id'}) def _populate(self): return Request('tv/{0}'.format(self.id), language='fr') def _populate_cast(self): return Request('tv/{0}/credits'.format(self.id)) def _populate_images(self): kwargs = {} if not self._locale.fallthrough: kwargs['language'] = 'fr' return Request('tv/{0}/images'.format(self.id), **kwargs) def _populate_external_ids(self): return Request('tv/{0}/external_ids'.format(self.id)) cast = Datalist('cast', handler=Cast, poller=_populate_cast, sort='order') crew = Datalist('crew', handler=Crew, poller=_populate_cast) backdrops = Datalist('backdrops', handler=Backdrop, poller=_populate_images, sort=True) posters = Datalist('posters', handler=Poster, poller=_populate_images, sort=True) imdb_id = Datapoint('imdb_id', poller=_populate_external_ids) freebase_id = Datapoint('freebase_id', poller=_populate_external_ids) freebase_mid = Datapoint('freebase_mid', poller=_populate_external_ids) tvdb_id = Datapoint('tvdb_id', poller=_populate_external_ids) tvrage_id = Datapoint('tvrage_id', poller=_populate_external_ids)