def getSuggestions(self, movies=None, ignore=None): if not ignore: ignore = [] if not movies: movies = [] suggestions = self.getJsonData(self.urls['suggest'], data={ 'movies': ','.join(movies), 'ignore': ','.join(ignore), }, headers=self.getRequestHeaders()) log.info('Found suggestions for %s movies, %s ignored', (len(movies), len(ignore))) x = 0 for item in suggestions: movie = tmdb3.Movie(item['imdb']) try: suggestions[x]['plot'] = movie.overview suggestions[x]['titles'][0] = movie.title suggestions[x]['images']['poster'][ 0] = suggestions[x]['images']['poster_original'][ 0][:suggestions[x]['images']['poster_original'][0]. rfind('/') + 1] + movie.posters[0].filename except: x += 1 continue x += 1 return suggestions
def automationView(self, force_update=False, **kwargs): if force_update: charts = self.updateViewCache() else: charts = self.getCache('charts_cached') if not charts: charts = self.updateViewCache() y = 0 for chart in charts: x = 0 for item in chart['list']: movie = tmdb3.Movie(item['imdb']) try: charts[y]['list'][x]['plot'] = movie.overview charts[y]['list'][x]['titles'][0] = movie.title charts[y]['list'][x]['images']['poster'][ 0] = charts[y]['list'][x]['images']['poster_original'][ y][:charts[y]['list'][x]['images'] ['poster_original'][0].rfind('/') + 1] + movie.posters[0].filename except: x += 1 continue x += 1 y += 1 return {'success': True, 'count': len(charts), 'charts': charts}
def getInfo(self, identifier=None, extended=True): if not identifier: return {} cache_key = 'tmdb.cache.%s%s' % (identifier, '.ex' if extended else '') result = self.getCache(cache_key) if not result: try: log.debug('Getting info: %s', cache_key) # noinspection PyArgumentList movie = tmdb3.Movie(identifier) try: exists = movie.title is not None except: exists = False if exists: result = self.parseMovie(movie, extended=extended) self.setCache(cache_key, result) else: result = {} except: log.error('Failed getting info for %s: %s', (identifier, traceback.format_exc())) return result
def get_tmdb_movie_for(title): """ Title can be either one of: • The 'Title' (string) • The 'Title (year)' (string) • tmdb id (integer) """ if type(title) == types.IntType or tmdb_id_re.match(title) is not None: try: return tmdb.Movie(int(title)) except KeyError: raise Exception("Movie with tmdb %i not found." % int(title)) else: return search_tmdb_for_movie(title)
def getInfo(self, identifier = None): if not identifier: return {} cache_key = 'tmdb.cache.%s' % identifier result = self.getCache(cache_key) if not result: try: log.debug('Getting info: %s', cache_key) movie = tmdb3.Movie(identifier) result = self.parseMovie(movie) self.setCache(cache_key, result) except: pass return result
def get_movie_details(movie, session, result=None): """Populate details for this :movie: from TMDb""" if not result and not movie.id: raise LookupError('Cannot get tmdb details without tmdb id') if not result: try: result = tmdb3.Movie(movie.id) except tmdb3.TMDBError: raise LookupError('No results for tmdb_id: %s (%s)' % (movie.id, sys.exc_info()[1])) try: movie.update_from_object(result) except tmdb3.TMDBRequestInvalid as e: log.debug('Error updating tmdb info: %s' % e) raise LookupError('Error getting tmdb info') posters = result.posters if posters: # Add any posters we don't already have # TODO: There are quite a few posters per movie, do we need to cache them all? poster_urls = [p.url for p in movie.posters] for item in posters: for size in item.sizes(): url = item.geturl(size) if url not in poster_urls: poster_data = { "movie_id": movie.id, "size": size, "url": url, "file": item.filename } movie.posters.append(TMDBPoster(poster_data)) genres = result.genres if genres: for genre in genres: if not genre.id: continue db_genre = session.query(TMDBGenre).filter( TMDBGenre.id == genre.id).first() if not db_genre: db_genre = TMDBGenre(genre) if db_genre not in movie.genres: movie.genres.append(db_genre) movie.updated = datetime.now()
def getInfo(self, identifier=None, extended=True): if not identifier: return {} cache_key = 'tmdb.cache.%s%s' % (identifier, '.ex' if extended else '') result = self.getCache(cache_key) if not result: try: log.debug('Getting info: %s', cache_key) # noinspection PyArgumentList movie = tmdb3.Movie(identifier) try: exists = movie.title is not None except: exists = False if exists: result = self.parseMovie(movie, extended=extended) self.setCache(cache_key, result) else: result = {} except: log.error('Failed getting info for %s: %s', (identifier, traceback.format_exc())) # Get extra artwork via Fanart.TV and merge into images dict try: extra_art = fireEvent('movie.extra_art', identifier)[0] result['images'] = dict(result['images'].items() + extra_art.items()) except IndexError: pass return result
def __init__(self, api_key, movie_id): tmbd.set_key(api_key) tmbd.set_cache('null') tmbd.set_locale('en', 'US') self.movie = tmbd.Movie(movie_id)