def movie_list_add(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 {}, creating'.format(options.list_name)) movie_list = MovieListList(name=options.list_name) session.add(movie_list) session.merge(movie_list) title, year = split_title_year(options.movie_title) movie_exist = get_movie_by_title(list_id=movie_list.id, title=title, session=session) if movie_exist: console("Movie with the title {} already exist with list {}. Will replace identifiers if given".format( title, movie_list.name)) output = 'Successfully updated movie {} to movie list {} '.format(title, movie_list.name) else: console("Adding movie with title {} to list {}".format(title, movie_list.name)) movie_exist = MovieListMovie(title=title, year=year, list_id=movie_list.id) session.add(movie_exist) output = 'Successfully added movie {} to movie list {} '.format(title, movie_list.name) if options.identifiers: identifiers = [parse_identifier(identifier) for identifier in options.identifiers if options.identifiers] console('Adding identifiers {} to movie {}'.format(identifiers, title)) movie_exist.ids = get_db_movie_identifiers(identifier_list=identifiers, session=session) console(output)
def movie_list_add(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 {}, creating'.format(options.list_name)) movie_list = MovieListList(name=options.list_name) session.merge(movie_list) title, year = split_title_year(options.movie_title) console('Trying to lookup movie %s title' % title) entry = lookup_movie(title=title, session=session, identifiers=options.identifiers) if not entry: console('movie lookup failed for movie %s, aborting') return title = entry['movie_name'] movie = get_movie_by_title(list_id=movie_list.id, title=title, session=session) if not movie: console("Adding movie with title {} to list {}".format(title, movie_list.name)) movie = MovieListMovie(title=entry['movie_name'], 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 entry.get(_id): id_list.append({_id: entry.get(_id)}) if id_list: console('Setting movie identifiers:', id_list) 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 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 post(self, list_id, session=None): """ Add movies to list by ID """ try: movie_list = ml.get_list_by_id(list_id=list_id, session=session) except NoResultFound: return {'status': 'error', 'message': 'list_id %d does not exist' % list_id}, 404 data = request.json # Validates ID type based on allowed ID # TODO pass this to json schema validation for id_name in data.get('movie_identifiers'): if set(id_name.keys()) & set(allowed_ids) == set([]): return {'status': 'error', 'message': 'movie identifier %s is not allowed' % id_name}, 501 if 'movie_name' in data: title, year = data['movie_name'], data.get('movie_year') else: title, year = split_title_year(data['title']) movie = ml.get_movie_by_title(list_id=list_id, title=title, session=session) if movie: return {'status': 'error', 'message': 'movie with name "%s" already exist in list %d' % (title, list_id)}, 500 movie = ml.MovieListMovie() movie.title = title movie.year = year movie.ids = ml.get_db_movie_identifiers(identifier_list=data.get('movie_identifiers'), session=session) movie.list_id = list_id session.add(movie) session.commit() response = jsonify({'movie': movie.to_dict()}) response.status_code = 201 return response
def put(self, list_id, movie_id, session=None): """ Sets movie identifiers """ try: movie = ml.get_movie_by_id(list_id=list_id, movie_id=movie_id, session=session) except NoResultFound: return { 'status': 'error', 'message': 'could not find movie with id %d in list %d' % (movie_id, list_id) }, 404 data = request.json # Validates ID type based on allowed ID # TODO pass this to json shcema validation for id_name in data: if set(id_name.keys()) & set(allowed_ids) == set([]): return { 'status': 'error', 'message': 'movie identifier %s is not allowed' % id_name }, 501 movie.ids[:] = ml.get_db_movie_identifiers(identifier_list=data, movie_id=movie_id, session=session) session.commit() return jsonify(movie.to_dict())
def post(self, list_id, session=None): """ Add movies to list by ID """ try: movie_list = ml.get_list_by_id(list_id=list_id, session=session) except NoResultFound: return {'status': 'error', 'message': 'list_id %d does not exist' % list_id}, 404 data = request.json # Validates ID type based on allowed ID # TODO pass this to json schema validation for id_name in data.get('movie_identifiers'): if set(id_name.keys()) & set(allowed_ids) == set([]): return {'status': 'error', 'message': 'movie identifier %s is not allowed' % id_name}, 501 if 'movie_name' in data: title, year = data['movie_name'], data.get('movie_year') else: title, year = split_title_year(data['title']) movie = ml.get_movie_by_title(list_id=list_id, title=title, session=session) if movie: return {'status': 'error', 'message': 'movie with name "%s" already exist in list %d' % (title, list_id)}, 500 movie = ml.MovieListMovie() movie.title = title movie.year = year movie.ids = ml.get_db_movie_identifiers(identifier_list=data.get('movie_identifiers'), session=session) movie.list_id = list_id session.add(movie) session.commit() response = jsonify({'movie': movie.to_dict()}) response.status_code = 201 return response
def movie_list_add(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 {}, creating'.format(options.list_name)) movie_list = MovieListList(name=options.list_name) session.add(movie_list) session.merge(movie_list) title, year = split_title_year(options.movie_title) movie_exist = get_movie_by_title(list_id=movie_list.id, title=title, session=session) if movie_exist: console("Movie with the title {} already exist with list {}. Will replace identifiers if given".format( title, movie_list.name)) output = 'Successfully updated movie {} to movie list {} '.format(title, movie_list.name) else: console("Adding movie with title {} to list {}".format(title, movie_list.name)) movie_exist = MovieListMovie(title=title, year=year, list_id=movie_list.id) session.add(movie_exist) output = 'Successfully added movie {} to movie list {} '.format(title, movie_list.name) if options.identifiers: identifiers = [parse_identifier(identifier) for identifier in options.identifiers if options.identifiers] console('Adding identifiers {} to movie {}'.format(identifiers, title)) movie_exist.ids = get_db_movie_identifiers(identifier_list=identifiers, session=session) console(output)
def movie_list_add(options): with Session() as session: try: movie_list = plugin_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 = plugin_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 = plugin_movie_list.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 = plugin_movie_list.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 plugin_movie_list.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 = plugin_movie_list.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 put(self, list_id, movie_id, session=None): """ Sets movie identifiers """ try: movie = ml.get_movie_by_id(list_id=list_id, movie_id=movie_id, session=session) except NoResultFound: raise NotFoundError("could not find movie with id %d in list %d" % (movie_id, list_id)) data = request.json # Validates ID type based on allowed ID for id_name in data: if list(id_name)[0] not in MovieListBase().supported_ids: raise BadRequest("movie identifier %s is not allowed" % id_name) movie.ids[:] = ml.get_db_movie_identifiers(identifier_list=data, movie_id=movie_id, session=session) session.commit() return jsonify(movie.to_dict())
def put(self, list_id, movie_id, session=None): """ Sets movie identifiers """ try: movie = ml.get_movie_by_id(list_id=list_id, movie_id=movie_id, session=session) except NoResultFound: return {'status': 'error', 'message': 'could not find movie with id %d in list %d' % (movie_id, list_id)}, 404 data = request.json # Validates ID type based on allowed ID # TODO pass this to json shcema validation for id_name in data: if set(id_name.keys()) & set(allowed_ids) == set([]): return {'status': 'error', 'message': 'movie identifier %s is not allowed' % id_name}, 501 movie.ids[:] = ml.get_db_movie_identifiers(identifier_list=data, movie_id=movie_id, session=session) session.commit() return jsonify(movie.to_dict())
def put(self, list_id, movie_id, session=None): """ Sets movie identifiers """ try: movie = ml.get_movie_by_id(list_id=list_id, movie_id=movie_id, session=session) except NoResultFound: raise NotFoundError('could not find movie with id %d in list %d' % (movie_id, list_id)) data = request.json # Validates ID type based on allowed ID for id_name in data: if list(id_name)[0] not in MovieListBase().supported_ids: raise BadRequest('movie identifier %s is not allowed' % id_name) movie.ids[:] = ml.get_db_movie_identifiers(identifier_list=data, movie_id=movie_id, session=session) session.commit() return jsonify(movie.to_dict())
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_movie(title=title, session=session, identifiers=options.identifiers) if not movie: console("ERROR: movie lookup failed for movie {}, aborting".format(options.movie_title)) return title = movie["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=movie["movie_name"], 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.get(_id): id_list.append({_id: movie.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))