Ejemplo n.º 1
0
def list_session_videos(session_id):
    """
    Endpoint for listing all the user videos of a session.

    :param session_id: Id of the session
    :return:
        - HTTP 200, if the videos could be successfully retrieved. The list of videos are returned
        in the body of the response with json format.
        - HTTP 400, if the given session id is not a valid session id.
        - HTTP 404, if the session does not exist.
    """
    user_id = session['user_id']
    LOGGER.info(
        "Received request for listing session videos. [session_id={}, user_id={}]"
        .format(session_id, user_id))
    try:
        videos = VideoManager.get_instance().list_session_videos(
            user_id=user_id, session_id=session_id)
        LOGGER.info("Listing session videos sucessfully finished.")
        return jsonify(videos), 200
    except ValueError as ve:
        LOGGER.exception(
            "Listing session videos request finished with errors: ")
        raise BadRequest(ve)
    except NotExistingResource as ne:
        LOGGER.exception(
            "Listing session videos request finished with errors: ")
        raise NotFound(ne)
Ejemplo n.º 2
0
def get_video_initial_ts(video_id):
    """
    HTTP endpoint for retrieving the initial TS of a video, in seconds.
    :param video_id: Id of the video.
    :return:
        - HTTP 200 with the timestamp in the body.
        - HTTP 400, if the provided parameter is not a valid id.
        - HTTP 404, if there's no video with the provided id.
    """
    LOGGER.info("Received request for getting the video initial ts.")
    try:
        ts = VideoManager.get_instance().get_initial_ts(video_id)
        LOGGER.info(
            "Request for getting the initial ts of a video sucessfully finished."
        )
        return jsonify({"timestamp": ts}), 200
    except ValueError as ve:
        LOGGER.exception(
            "Request for getting the initial ts of a video finished with errors."
        )
        raise BadRequest(ve)
    except NotExistingResource as ne:
        LOGGER.exception(
            "Request for getting the initial ts of a video finished with errors."
        )
        raise NotFound(ne)
Ejemplo n.º 3
0
def add_video_to_session(session_id):
    """
    Endpoint for adding a video to a live session.

    :param session_id: Id of the session
    :return:
        - HTTP 200, if the video could be successfully added. The id is returned in the body of the
        message.
        - HTTP 400, if the given session id is not a valid session id.
        - HTTP 404, if the session does not exist.
        - HTTP 409, if the session is no longer active.
    """
    LOGGER.info("Received request for adding a video [session_id={}]".format(
        session_id))
    try:
        user_id = session['user_id']
        video_id = VideoManager.get_instance().add_video(session_id=session_id,
                                                         user_id=user_id)
        LOGGER.info("Adding video to session request succesfully finished.")
        return jsonify({"id": video_id}), 201
    except ValueError as ve:
        LOGGER.exception(
            "Adding video to session request finished with errors: ")
        raise BadRequest(ve)
    except NotExistingResource as ne:
        LOGGER.exception(
            "Adding video to session request finished with errors: ")
        raise NotFound(ne)
    except IllegalSessionStateException as ie:
        LOGGER.exception(
            "Adding video to session request finished with errors: ")
        raise Conflict(ie)
Ejemplo n.º 4
0
def list_user_videos():
    LOGGER.info("Received request for listing user videos.")
    user_id = session['user_id']
    try:
        videos = VideoManager.get_instance().list_user_videos(user_id=user_id)
        LOGGER.info("Listing user videos sucessfully finished.")
        return jsonify(videos), 200
    except ValueError as ve:
        LOGGER.exception(
            "Listing session videos request finished with errors: ")
        raise BadRequest(ve)
    except NotExistingResource as ne:
        LOGGER.exception(
            "Listing session videos request finished with errors: ")
        raise NotFound(ne)
Ejemplo n.º 5
0
def get_video_first_thumb(video_id):
    LOGGER.info("Received request for getting video first thumb.")
    try:
        thumb_path = VideoManager.get_instance().get_video_first_thumb(
            video_id=video_id)
        LOGGER.info(
            "Request for getting video first thumb successfully finished.")
        return send_file(thumb_path, mimetype="image/jpg"), 200
    except ValueError as ve:
        LOGGER.exception(
            "Listing session videos request finished with errors: ")
        raise BadRequest(ve)
    except NotExistingResource as ne:
        LOGGER.exception(
            "Listing session videos request finished with errors: ")
        raise NotFound(ne)
Ejemplo n.º 6
0
def add_video_to_active_session():
    """
    Endpoint for adding a new video to the actives session.
    :return:
        - HTTP 201, with the id of the video in the body.
        - HTTP 409, if there's no active session.
    """
    LOGGER.info("Received request for adding a video to the active session.")
    user_id = session['user_id']
    try:
        video = VideoManager.get_instance().add_video_to_active_session(
            user_id=user_id)
        LOGGER.info(
            "Request for adding a video to the active session successfully finished."
        )
        return jsonify(video), 201
    except IllegalSessionStateException as ie:
        LOGGER.info(
            "Request for adding a video to the active session finished with errors -"
        )
        raise Conflict(ie)
Ejemplo n.º 7
0
def split_video(video_id):
    VideoManager.get_instance().split_video(video_id=video_id)
    return "", 204
Ejemplo n.º 8
0
def get_video_thumbs(video_id):
    zipbuffer = VideoManager.get_instance().zip_video_thumbs(video_id=video_id)
    return send_file(zipbuffer, mimetype='application/zip'), 200
Ejemplo n.º 9
0
def create_video_thumbs(video_id):
    VideoManager.get_instance().create_video_thumbs(video_id=video_id)
    return "", 204