def getMovieData(self, movieId): """From a given TVDBPy movie object, return a graph containing its information.""" m = self.tmdb.Movies(movieId) resp = m.info({'language': self.tmdb.lang}) result = MemoryObjectGraph() movie = result.Movie(title=unicode(resp['title'])) movie.original_title = resp['original_title'] if resp.get('release_date'): movie.set( 'year', datetime.datetime.strptime(resp['release_date'], '%Y-%m-%d').year) movie.set('genres', [unicode(g['name']) for g in resp['genres']]) movie.set('rating', resp['vote_average']) movie.set('plot', [unicode(resp['overview'])]) resp = m.credits() movie.set('director', [ unicode(c['name']) for c in resp['crew'] if c['job'] == 'Director' ]) movie.set( 'writer', [unicode(c['name']) for c in resp['crew'] if c['job'] == 'Author']) try: movie.cast = [ unicode(actor['name']) + ' -- ' + unicode(actor['character']) for actor in resp['cast'] ] except KeyError: movie.cast = [] return result
def perform(self, query): self.checkValid(query) log.debug('MovieTvdb: finding more info on %s' % u(query.find_one(Movie))) movie = query.find_one(Movie) try: mdprovider = TVDBMetadataProvider() result = mdprovider.startMovie(movie.title) except SmewtException: # movie could not be found, return a dummy Unknown movie instead so we can group them somewhere log.warning('Could not find info for movie: %s' % u(query.find_one(Media).filename)) noposter = '/static/images/noposter.png' result = MemoryObjectGraph() result.Movie(title = 'Unknown', loresImage = noposter, hiresImage = noposter) result = foundMetadata(query, result.find_one(Movie)) return result