Exemplo n.º 1
0
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))
Exemplo n.º 2
0
 def post(self, session=None):
     """ Create a new list """
     data = request.json
     name = data.get('name')
     try:
         movie_list = ml.get_list_by_exact_name(name=name, session=session)
     except NoResultFound:
         movie_list = None
     if movie_list:
         raise Conflict('list with name \'%s\' already exists' % name)
     movie_list = ml.MovieListList(name=name)
     session.add(movie_list)
     session.commit()
     resp = jsonify(movie_list.to_dict())
     resp.status_code = 201
     return resp
Exemplo n.º 3
0
 def post(self, session=None):
     """ Create a new list """
     data = request.json
     name = data.get('name')
     try:
         movie_list = ml.get_list_by_exact_name(name=name, session=session)
     except NoResultFound:
         movie_list = None
     if movie_list:
         return {'status': 'error',
                 'message': "list with name '%s' already exists" % name}, 500
     movie_list = ml.MovieListList(name=name)
     session.add(movie_list)
     session.commit()
     resp = jsonify(movie_list.to_dict())
     resp.status_code = 201
     return resp