Пример #1
0
def insert_movie(the_movie):
    movie = Movie.from_tmdb(the_movie, True)
    db_session.add(movie)
    try:
        db_session.commit()
        return movie.movieid
    except:
        db_session.rollback()
        raise
Пример #2
0
 def update_database(self):
     """Download again info from TMDB for the movies in the db."""
     tmdb_ID_list = [movie.tmdbID for movie in db_session.query(Movie).all() if movie.tmdbID > 0]
     for tmdb_ID in tmdb_ID_list:
         try:
             the_movie = tmdb3.Movie(tmdb_ID)
             movie = Movie.from_tmdb(the_movie, download_poster=False)
             db_methods.update_movie(tmdb_ID, movie)
         except tmdb3.tmdb_exceptions.TMDBHTTPError as e:
             logging.error("Movie not updated.")
             logging.error("HTTP error({0}): {1}".format(e.httperrno, e.response))
         except:
             logging.error("Unexpected error: %s", sys.exc_info()[0])
             raise
     try:
         db_session.commit()
     except:
         db_session.rollback()
         logging.error('Error updating movies in the database.')
         raise
Пример #3
0
def insert_movie_file(the_movie, path, movie_name):
    """
    Checks if movie and file are already in the database and updates relationship, else it adds new ones.
    """
    try:
        movie = db_session.query(Movie).filter(Movie.tmdbID == the_movie.id).one()
    except NoResultFound:
        movie = Movie.from_tmdb(the_movie)
        db_session.add(movie)
        db_session.commit()
    try:
        file = db_session.query(File).filter(File.filepath == path).one()
    except NoResultFound:
        file = File(filepath=path, name=movie_name, movieid=movie.movieid)
        db_session.add(file)
    else:
        file.movieid = movie.movieid
    try:
        db_session.commit()
        return movie.movieid
    except:
        db_session.rollback()
    return None