Пример #1
0
    def post(self):
        parse_args = video_parser.parse_args()

        new_video = Video()
        new_video.title = parse_args['title']
        new_video.type = 'LIVE'
        new_video.status = 'EMPTY'
        new_video.created_at = datetime.now()
        new_video.segment_count = -1
        new_video.segment_duration = 3000
        new_video.repr_1 = Reprs.HIGH
        new_video.repr_2 = Reprs.MEDIUM
        new_video.repr_3 = Reprs.LOW
        new_video.uri_mpd = None
        new_video.uri_m3u8 = None

        try:
            session.add(new_video)
            session.commit()

        except:
            session.rollback()
            raise

        return new_video, 201
Пример #2
0
    def post(self, video_id):
        parse_args = video_end_parser.parse_args()

        last_segment_id = parse_args['last_segment_id']
        if not last_segment_id:
            abort(400, message="Expecting last_segment_id")
            return None

        # check the video
        video = session \
            .query(Video) \
            .filter(Video.video_id == video_id) \
            .first()

        if not video:
            abort(404, message="Video (%s) doesn't exist" % video_id)
            return None

        video.segment_count = last_segment_id + 1
        video.status = 'OK'

        # generate the thumbnail
        thumbnail_segment_id = int(video.segment_count / 2)
        enqueue_segment_task('thumbnail', video.video_id, thumbnail_segment_id)

        try:
            session.add(video)
            session.commit()

        except:
            session.rollback()
            logger.error("Error persistent data: %s" % traceback.format_exc())
            raise

        return video
Пример #3
0
 def commit():
     try:
         current_session.commit()
     except Exception as e:
         current_session.rollback()
         raise e
     finally:
         current_session.close()
Пример #4
0
 def save_task(self):
     try:
         current_session.add(self)
         current_session.commit()
     except (Exception, ) as e:
         current_session.rollback()
         raise Exception(e)
     return True
Пример #5
0
    def put(self, video_id):
        logger.info("Updating video [%s]" % video_id)
        parsed_args = video_parser.parse_args()

        video = session \
            .query(Video) \
            .filter(Video.video_id == video_id) \
            .first()

        video.title = parsed_args['title']

        try:
            session.add(video)
            session.commit()
            logger.info("Updated video [%s]" % video_id)

        except:
            session.rollback()
            logger.error("Error persistent data: %s" % traceback.format_exc())
            raise

        return video, 201
Пример #6
0
    def delete(self, video_id):
        logger.info("Deleting video [%s]" % video_id)

        video = session \
            .query(Video) \
            .filter(Video.video_id == video_id) \
            .first()

        if not video:
            abort(404, message="Video {} doesn't exist".format(video_id))

        try:
            session.delete(video)
            session.commit()
            logger.info("Deleted video [%s]" % video_id)

        except:
            session.rollback()
            logger.error("Error persistent data: %s" % traceback.format_exc())
            raise

        return {}, 204
Пример #7
0
    def post(self, video_id):
        parse_args = segment_parser.parse_args()

        segment = VideoSegment()
        segment.video_id = video_id
        segment.segment_id = parse_args['segment_id']
        segment.status = 'NIL'
        segment.repr_1_status = 'NIL'
        segment.repr_2_status = 'NIL'
        segment.repr_3_status = 'NIL'

        # check the video ID
        video = session \
            .query(Video) \
            .filter(Video.video_id == video_id) \
            .first()

        if not video:
            abort(404, message="Video (%s) doesn't exist" % segment.video_id)
            return

        segment.uri_mpd = None
        segment.uri_m3u8 = None

        segment.original_extension = parse_args["original_extension"]
        segment.original_path = "%s/%s/%s.%s" % (
            upload_path,
            segment.video_id,
            segment.segment_id,
            segment.original_extension
        )

        upload_success = True

        try:
            # processing the uploaded file

            # creating the directory
            dir_path = os.path.dirname(segment.original_path)
            if not os.path.exists(dir_path) \
                    or not os.path.isdir(dir_path):
                os.mkdir(dir_path)

            uploaded_file = parse_args['data']
            uploaded_file.save(dst=segment.original_path, buffer_size=524288)

        except:
            upload_success = False
            logger.error("Error processing segment upload: %r" % traceback.format_exc())
            segment.repr_1_status = 'ERROR'
            segment.repr_2_status = 'ERROR'
            segment.repr_3_status = 'ERROR'

        try:
            session.add(segment)
            session.commit()

        except:
            session.rollback()

            # clean up the uploaded file
            if os.path.exists(segment.original_path):
                os.remove(segment.original_path)

            logger.error("Error persistent data: %s" % traceback.format_exc())
            raise

        if upload_success:
            # generate the thumbnail for the first segment, for live streamings
            if (segment.segment_id == 0):
                enqueue_segment_task('thumbnail', video.video_id, 0)

            enqueue_segment_task('transcode', segment.video_id, segment.segment_id)

        return segment, 201
Пример #8
0
def internal_error(error):
    log.info('505')
    current_session.rollback()
    return render_template('500.html', title='Error'), 500