示例#1
0
def search_movies(search_text, page, size):
    movie_repo = MovieRepository(get_db())
    if search_text is None:
        movies = movie_repo.find_all(page, size)
    else:
        movies = movie_repo.find_by_keyword(search_text, page, size)

    return jsonify(movies)
示例#2
0
def load_logged_in_user():
    user_repository = UserRepository(get_db())
    user_id = session.get('user_id')

    if user_id is None:
        g.user = None
    else:
        g.user = user_repository.find_by_id(user_id)
示例#3
0
def screen_it(movie_id):
    movie_repo = MovieRepository(get_db())
    movie = movie_repo.find_by_id(movie_id)
    if movie is None:
        flash('Requested movie not found')
        return redirect(request.url)

    return render_template('watch/index.html', movie=movie)
示例#4
0
def hsl_fragment(movie_id, file_name):
    movie_repo = MovieRepository(get_db())
    movie = movie_repo.find_by_id(movie_id)

    if movie is None:
        abort(404, "Movie could not be found")

    if movie.is_mp4:
        abort(404,
              "Could not find an HSL converted movie with the provided id")

    file_dir = os.path.join(current_app.config['HLS_DIR'], movie.blob_id)
    return send_from_directory(file_dir, file_name)
示例#5
0
def mp4_video(movie_id):
    movie_repo = MovieRepository(get_db())
    movie = movie_repo.find_by_id(movie_id)

    if movie is None:
        abort(404, "Movie could not be found")

    if not movie.is_mp4:
        abort(404, "Could not find an MP4 movie with the provided id")

    file_path = os.path.join(current_app.config['UPLOAD_FOLDER'],
                             movie.blob_id)
    start, end = get_range(request)
    return partial_response(file_path, start, end)
示例#6
0
def app():
    db_fd, db_path = tempfile.mkstemp()

    app = create_app({'TESTING': True, 'MONGO_DB': 'flixdb_test'})

    with app.app_context():
        dbConfig = get_db()
        dbConfig.flix_db.drop_collection('users')
        dbConfig.flix_db.drop_collection('users')

    yield app

    os.close(db_fd)
    os.unlink(db_path)
示例#7
0
def login():
    if request.method == 'POST':
        user_repository = UserRepository(get_db())
        username = request.form['username']
        password = request.form['password']
        error = None
        user = user_repository.find_by_username(username)

        if user is None:
            error = 'Incorrect username.'
        elif not check_password_hash(user.password, password):
            error = 'Incorrect password.'

        if error is None:
            return redirect_home_asnew(user.id)

        flash(error)

    return render_template('auth/login.html')
示例#8
0
def _upload_secured_movie(filename, force_replace, movie_title):
    movie_repo = MovieRepository(get_db())
    filepath = os.path.join(current_app.config['UPLOAD_FOLDER'], filename)
    movie_id = ''
    if 'convert' in request.form:
        model = vidconvert.make_default_req(filename, filepath)
        conversion = vidconvert.convert_mp4(model, force_replace)

        if conversion["succeeded"]:
            new_movie = Movie(title=movie_title,
                              blob_id=filename,
                              is_mp4=False)
            movie_id = movie_repo.insert(new_movie)
        else:
            os.remove(filepath)
            flash(conversion['reason'])
            return redirect(request.url)
    else:
        new_movie = Movie(title=movie_title, blob_id=filename, is_mp4=True)
        movie_id = movie_repo.insert(new_movie)
    return redirect(url_for('upload.uploaded_movie', movie_id=movie_id))
示例#9
0
def register():
    if request.method == 'POST':
        user_repository = UserRepository(get_db())
        username = request.form['username']
        password = request.form['password']
        error = None

        if not username:
            error = 'Username is required.'
        elif not password:
            error = 'Password is required.'
        elif user_repository.find_by_username(username) is not None:
            error = 'User {} is already registered.'.format(username)

        if error is None:
            user_id = user_repository.insert(
                User(username=username,
                     password=generate_password_hash(password)))
            return redirect_home_asnew(user_id)

        flash(error)

    return render_template('auth/register.html')
示例#10
0
def index():
    # todo: grab "featured" movies
    movie_repo = MovieRepository(get_db())
    movies = movie_repo.find_all(1, 10)
    return render_template('home/index.html', movies=movies)
示例#11
0
def uploaded_movie(movie_id):
    movie_repo = MovieRepository(get_db())
    movie = movie_repo.find_by_id(movie_id)
    return render_template('upload/movie_uploaded.html', movie=movie)