def add_movie(movie, full_metadata=False): ''' Adds movie to Wanted list. movie (dict): movie info to add to database. full_metadata (bool): if data is complete and ready for write movie MUST inlcude tmdb id as data['id'] Writes data to MOVIES table. If full_metadata is False, searches tmdb for data['id'] and updates data full_metadata should only be True when passing movie as data pulled directly from a tmdbid search If Search on Add enabled, searches for movie immediately in separate thread. If Auto Grab enabled, will snatch movie if found. Returns dict ajax-style response ''' logging.info('Adding {} to library.'.format(movie.get('title'))) response = {} tmdbid = movie['id'] if not full_metadata: logging.debug( 'More information needed, searching TheMovieDB for {}'.format( tmdbid)) tmdb_data = TheMovieDatabase._search_tmdbid(tmdbid) if not tmdb_data: response['error'] = _('Unable to find {} on TMDB.').format( tmdbid) return response else: tmdb_data = tmdb_data[0] tmdb_data.pop('status') movie.update(tmdb_data) if core.sql.row_exists('MOVIES', imdbid=movie['imdbid']): logging.info('{} already exists in library.'.format( movie['title'])) response['response'] = False response['error'] = _('{} already exists in library.').format( movie['title']) return response if not movie.get('category', None) and movie.get( 'finished_file', None): movie['category'] = Metadata.get_category_from_path( (movie['finished_file'])) movie.setdefault('quality', 'Default') movie.setdefault('category', 'Default') movie.setdefault('status', 'Waiting') movie.setdefault('origin', 'Search') poster_path = movie.get('poster_path') movie = Metadata.convert_to_db(movie) if not core.sql.write('MOVIES', movie): response['response'] = False response['error'] = _('Could not write to database.') else: if poster_path: poster_url = 'http://image.tmdb.org/t/p/w300/{}'.format( poster_path) threading.Thread(target=Poster.save, args=(movie['imdbid'], poster_url)).start() response['response'] = True response['message'] = _('{} {} added to library.').format( movie['title'], movie['year']) plugins.added(movie['title'], movie['year'], movie['imdbid'], movie['quality']) return response
def add_movie(self, movie, full_metadata=False): ''' Adds movie to Wanted list. movie (dict): movie info to add to database. full_metadata (bool): if data is complete and ready for write movie MUST inlcude tmdb id as data['id'] Writes data to MOVIES table. If full_metadata is False, searches tmdb for data['id'] and updates data full_metadata should only be True when passing movie as data pulled directly from a tmdbid search If Search on Add enabled, searches for movie immediately in separate thread. If Auto Grab enabled, will snatch movie if found. Returns dict ajax-style response ''' logging.info('Adding {} to library.'.format(movie.get('title'))) response = {} tmdbid = movie['id'] poster_path = movie.get('poster_path') if not full_metadata: logging.debug('More information needed, searching TheMovieDB for {}'.format(tmdbid)) tmdb_data = self.tmdb._search_tmdbid(tmdbid) if not tmdb_data: response['error'] = 'Unable to find {} on TMDB.'.format(tmdbid) return response else: tmdb_data = tmdb_data[0] tmdb_data.pop('status') movie.update(tmdb_data) if core.sql.row_exists('MOVIES', imdbid=movie['imdbid']): logging.info('{} already exists in library.'.format(movie['title'])) response['response'] = False response['error'] = '{} already exists in library.'.format(movie['title']) return response movie['quality'] = movie.get('quality', 'Default') movie['status'] = movie.get('status', 'Waiting') movie['origin'] = movie.get('origin', 'Search') movie = self.metadata.convert_to_db(movie) if not core.sql.write('MOVIES', movie): response['response'] = False response['error'] = 'Could not write to database.' return response else: if poster_path: poster_path = "http://image.tmdb.org/t/p/w300{}".format(poster_path) threading.Thread(target=self.poster.save_poster, args=(movie['imdbid'], poster_path)).start() if movie['status'] != 'Disabled' and movie['year'] != 'N/A': # disable immediately grabbing new release for imports threading.Thread(target=self.searcher._t_search_grab, args=(movie,)).start() response['response'] = True response['message'] = '{} {} added to library.'.format(movie['title'], movie['year']) plugins.added(movie['title'], movie['year'], movie['imdbid'], movie['quality']) return response