def post(self, list_id, session=None): """ Add movies to list by ID """ try: ml.get_list_by_id(list_id=list_id, session=session) except NoResultFound: raise NotFoundError("list_id %d does not exist" % list_id) data = request.json movie_identifiers = data.get("movie_identifiers", []) # Validates ID type based on allowed ID for id_name in movie_identifiers: if list(id_name)[0] not in MovieListBase().supported_ids: raise BadRequest("movie identifier %s is not allowed" % id_name) title, year = data["movie_name"], data.get("movie_year") movie = ml.get_movie_by_title_and_year(list_id=list_id, title=title, year=year, session=session) if movie: raise Conflict('movie with name "%s" already exist in list %d' % (title, list_id)) movie = ml.MovieListMovie() movie.title = title movie.year = year movie.ids = ml.get_db_movie_identifiers(identifier_list=movie_identifiers, session=session) movie.list_id = list_id session.add(movie) session.commit() response = jsonify(movie.to_dict()) response.status_code = 201 return response
def post(self, list_id, session=None): """ Add movies to list by ID """ try: ml.get_list_by_id(list_id=list_id, session=session) except NoResultFound: raise NotFoundError('list_id %d does not exist' % list_id) data = request.json movie_identifiers = data.get('movie_identifiers', []) # Validates ID type based on allowed ID for id_name in movie_identifiers: if list(id_name)[0] not in MovieListBase().supported_ids: raise BadRequest('movie identifier %s is not allowed' % id_name) title, year = data['movie_name'], data.get('movie_year') movie = ml.get_movie_by_title_and_year(list_id=list_id, title=title, year=year, session=session) if movie: raise Conflict('movie with name "%s" already exist in list %d' % (title, list_id)) movie = ml.MovieListMovie() movie.title = title movie.year = year movie.ids = ml.get_db_movie_identifiers( identifier_list=movie_identifiers, session=session) movie.list_id = list_id session.add(movie) session.commit() response = jsonify(movie.to_dict()) response.status_code = 201 return response
def movie_list_del(options): with Session() as session: try: movie_list = plugin_movie_list.get_list_by_exact_name( options.list_name) except NoResultFound: console('Could not find movie list with name {}'.format( options.list_name)) return try: movie_exist = plugin_movie_list.get_movie_by_id( list_id=movie_list.id, movie_id=int(options.movie), session=session) except NoResultFound: console('Could not find movie with ID {} in list `{}`'.format( int(options.movie), options.list_name)) return except ValueError: title, year = split_title_year(options.movie) movie_exist = plugin_movie_list.get_movie_by_title_and_year( list_id=movie_list.id, title=title, year=year, session=session) if not movie_exist: console('Could not find movie with title {} in list {}'.format( options.movie, options.list_name)) return else: console('Removing movie {} from list {}'.format( movie_exist.title, options.list_name)) session.delete(movie_exist)
def movie_list_add(options): with Session() as session: try: movie_list = get_list_by_exact_name(options.list_name, session=session) except NoResultFound: console('Could not find movie list with name {}, creating'.format( options.list_name)) movie_list = MovieListList(name=options.list_name) session.add(movie_list) session.commit() title, year = split_title_year(options.movie_title) console('Trying to lookup movie title: `{}`'.format(title)) movie_lookup = lookup_movie(title=title, session=session, identifiers=options.identifiers) if not movie_lookup: console('ERROR: movie lookup failed for movie {}, aborting'.format( options.movie_title)) return title = movie_lookup['movie_name'] movie = get_movie_by_title_and_year(list_id=movie_list.id, title=title, year=year, session=session) if not movie: console("Adding movie with title {} to list {}".format( title, movie_list.name)) movie = MovieListMovie(title=title, year=year, list_id=movie_list.id) else: console("Movie with title {} already exist in list {}".format( title, movie_list.name)) id_list = [] if options.identifiers: id_list = options.identifiers else: for _id in MovieListBase().supported_ids: if movie_lookup.get(_id): id_list.append({_id: movie_lookup.get(_id)}) if id_list: console('Setting movie identifiers:') for ident in id_list: for key in ident: console('{}: {}'.format(key, ident[key])) movie.ids = get_db_movie_identifiers(identifier_list=id_list, session=session) session.merge(movie) console('Successfully added movie {} to movie list {} '.format( title, movie_list.name))
def movie_list_del(options): with Session() as session: try: movie_list = get_list_by_exact_name(options.list_name) except NoResultFound: console('Could not find movie list with name {}'.format(options.list_name)) return title, year = split_title_year(options.movie_title) movie_exist = get_movie_by_title_and_year(list_id=movie_list.id, title=title, year=year, session=session) if movie_exist: console('Removing movie %s from list %s' % (options.movie_title, options.list_name)) session.delete(movie_exist) else: console('Could not find movie with title %s in list %s' % (options.movie_title, options.list_name)) return
def movie_list_add(options): with Session() as session: try: movie_list = get_list_by_exact_name(options.list_name, session=session) except NoResultFound: console('Could not find movie list with name {}, creating'.format(options.list_name)) movie_list = MovieListList(name=options.list_name) session.add(movie_list) session.commit() title, year = split_title_year(options.movie_title) console('Trying to lookup movie title: `{}`'.format(title)) movie_lookup = lookup_movie(title=title, session=session, identifiers=options.identifiers) if not movie_lookup: console('ERROR: movie lookup failed for movie {}, aborting'.format(options.movie_title)) return title = movie_lookup['movie_name'] movie = get_movie_by_title_and_year(list_id=movie_list.id, title=title, year=year, session=session) if not movie: console("Adding movie with title {} to list {}".format(title, movie_list.name)) movie = MovieListMovie(title=title, year=year, list_id=movie_list.id) else: console("Movie with title {} already exist in list {}".format(title, movie_list.name)) id_list = [] if options.identifiers: id_list = options.identifiers else: for _id in MovieListBase().supported_ids: if movie_lookup.get(_id): id_list.append({_id: movie_lookup.get(_id)}) if id_list: console('Setting movie identifiers:') for ident in id_list: for key in ident: console('{}: {}'.format(key, ident[key])) movie.ids = get_db_movie_identifiers(identifier_list=id_list, session=session) session.merge(movie) console('Successfully added movie {} to movie list {} '.format(title, movie_list.name))
def movie_list_del(options): with Session() as session: try: movie_list = get_list_by_exact_name(options.list_name) except NoResultFound: console('Could not find movie list with name {}'.format(options.list_name)) return try: movie_exist = get_movie_by_id(list_id=movie_list.id, movie_id=int(options.movie), session=session) except NoResultFound: console('Could not find movie with ID {} in list `{}`'.format(int(options.movie), options.list_name)) return except ValueError: title, year = split_title_year(options.movie) movie_exist = get_movie_by_title_and_year(list_id=movie_list.id, title=title, year=year, session=session) if not movie_exist: console('Could not find movie with title {} in list {}'.format(options.movie, options.list_name)) return else: console('Removing movie {} from list {}'.format(movie_exist.title, options.list_name)) session.delete(movie_exist)