示例#1
0
def post_take_video_thumbnail(request, take_id="0"):

    if request.method == 'POST':

        # TODO Access rights

        if not request.FILES:
            return HttpResponse(status=500)

        take_id = int(take_id)
        take = Take.objects.get(pk=take_id)

        filename = 't%08d_front_%s.mp4' % (take.id, uuid_node_base36())
        filepath = full_thumb_path(filename)

        # Write file to disk
        try:
            f = request.FILES['file']
            with open(filepath, 'wb') as destination:
                for chunk in f.chunks():
                    destination.write(chunk)

            take.video_thumb = filename
            take.save()

        except Exception as e:
            client.captureException()
            print e

    return HttpResponse()
示例#2
0
def job_mesh(request, job_id="0"):

    job_id = int(job_id)
    job = FarmJob.objects.get(pk=job_id)

    if not job:
        return HttpResponse(status=404)

    if not request.FILES:
        return HttpResponse(status=500)

    ext = os.path.splitext(request.FILES['file'].name)[1]

    filename = 'j%08d_%s%s' % (job_id, uuid_node_base36(), ext)
    filepath = os.path.join(BASE_DIR, 'static', 'thumb', filename)

    # Write file to disk
    try:
        f = request.FILES['file']
        with open(filepath, 'wb') as destination:
            for chunk in f.chunks():
                destination.write(chunk)

        job.mesh_filename = filename
        job.save()

    except Exception as e:
        client.captureException()
        return JSONResponse({'message': '%s' % e}, status=500)

    return HttpResponse()
示例#3
0
def job_image(request, job_id="0"):

    job_id = int(job_id)
    job = FarmJob.objects.get(pk=job_id)

    if not job:
        return HttpResponse(status=404)

    if not request.FILES:
        return HttpResponse(status=500)

    filename = 'j%08d_%s.jpg' % (job_id, uuid_node_base36())
    filepath = os.path.join(BASE_DIR, 'static', 'thumb', filename)

    # Write file to disk
    try:
        f = request.FILES['file']
        with open(filepath, 'wb') as destination:
            for chunk in f.chunks():
                destination.write(chunk)                

        job.image_filename = filename
        job.save()

    except Exception as e:
        return HttpResponse(e, status=500)

    return HttpResponse('OK')
示例#4
0
def post_tracking_asset_thumbnail(request, asset_id="0"):

    if request.method == 'POST':

        # TODO Access rights

        if not request.FILES:
            return HttpResponse(status=500)

        asset_id = int(asset_id)
        tracking_asset = TrackingAsset.objects.get(pk=asset_id)

        filename = 'tr%08d_front_%s.mp4' % (tracking_asset.id,
                                            uuid_node_base36())
        filepath = os.path.join(BASE_DIR, 'static', 'thumb', filename)

        # Write file to disk
        try:
            f = request.FILES['file']
            with open(filepath, 'wb') as destination:
                for chunk in f.chunks():
                    destination.write(chunk)

            tracking_asset.video_thumb = filename
            tracking_asset.save()

        except Exception as e:
            print e

    return HttpResponse('Ok')
示例#5
0
def post_scan_asset_thumbnail(request, asset_id="0", asset_type="front"):

    if request.method == 'POST':

        # TODO Access rights

        if not request.FILES:
            return HttpResponse(status=500)

        asset_id = int(asset_id)
        asset = StaticScanAsset.objects.get(pk=asset_id)

        if asset_type.isdigit():
            filename = 's%08d_f%d_%s.jpg' % (asset_id, int(asset_type),
                                             uuid_node_base36())
        else:
            filename = 's%08d_%s_%s.jpg' % (asset_id, asset_type,
                                            uuid_node_base36())

        filepath = full_thumb_path(filename)

        g_logger.info('Writing %s' % filepath)

        # Write file to disk
        try:
            f = request.FILES['file']
            with open(filepath, 'wb') as destination:
                for chunk in f.chunks():
                    destination.write(chunk)

            if asset_type == 'front':
                asset.thumbnail_filename = filename
                asset.save()

        except Exception as e:
            client.captureException()
            print e

    return HttpResponse()
示例#6
0
def register_new_take(loc, summary, is_burst, is_scan):
    # Record information about this take in the database
    # Session and Shot should already be created and referenced in cur_session and cur_shot
    if loc.cur_project:
        if not loc.cur_session or not loc.cur_shot:
            print('ERROR> Session and Shot should be created')
            return

        # Create Take
        take = ArchiveTake(name='Take_%04d' % loc.cur_shot.next_take,
                           shot=loc.cur_shot,
                           sequence=loc.cur_shot.next_take,
                           is_burst=is_burst,
                           is_scan_burst=is_scan)
        take.save()

        # Add cameras to take
        for node in summary['nodes']:
            if 'summary' in node:
                if 'cameras' in node['summary']:

                    # Locate capture node and cameras
                    db_capture_nodes = CaptureNode.objects.filter(
                        location=loc, machine_name=node['machine_name'])

                    cam_index = 0
                    for cam in node['summary']['cameras']:

                        unique_id = cam['camera']['unique_id']

                        # clash (takeids are not unique across machines)
                        if 'jpeg_thumbnail' in cam:
                            filename = '%08d_%03d_%s_%s.jpg' % (
                                take.id, cam_index, unique_id,
                                uuid_node_base36())
                            filepath = os.path.join(BASE_DIR, 'static',
                                                    'thumb', filename)
                            try:
                                base64_thumbnail = b64decode(
                                    cam['jpeg_thumbnail'] + '=' * 10)
                                with open(filepath, 'wb') as f:
                                    f.write(base64_thumbnail)
                            except Exception as e:
                                print(e)

                            cam['thumb_filename'] = filename

                        all_files = []
                        if 'recorder' in cam:
                            all_files.extend(cam['recorder']['filenames'])
                        if 'meta' in cam:
                            all_files.append(cam['meta']['meta_filename'])
                        if 'audio' in cam:
                            all_files.append(cam['audio']['filename'])

                        # Find associated camera in db
                        db_cam = Camera.objects.filter(
                            node__location=loc,
                            node__machine_name=node['machine_name'],
                            unique_id=unique_id)[0]

                        if 'recorder' in cam and 'meta' in cam:

                            # New extended camar parameters
                            exposure = 0.0
                            if 'camera_params' in cam:
                                exposure = cam['camera_params'][
                                    'exposure'] / 1000.0 if 'exposure' in cam[
                                        'camera_params'] else 0.0

                            camera = ArchiveCamera(
                                take=take,
                                unique_id=unique_id,
                                machine_name=node['machine_name'],
                                model=cam['camera']['model'],
                                version=cam['camera']['version'],
                                using_sync=cam['camera']
                                ['using_hardware_sync'],
                                folder=cam['recorder']['filenames'][0],
                                thumbnail_filename=filename,
                                width=cam['camera']['width'],
                                height=cam['camera']['height'],
                                bitdepth=cam['meta']['bitdepth'],
                                exposure_ms=exposure,
                                frame_count=cam['meta']['frame_count'],
                                dropped_frames=cam['meta']['missing_frames'],
                                total_size=cam['recorder']['total_size'],
                                duration=cam['meta']['duration'],
                                framerate=cam['camera']['framerate'],
                                rotation=db_cam.rotation,
                                all_files=';'.join(all_files))
                            camera.save()

                        elif 'audio' in cam:

                            camera = ArchiveCamera(
                                take=take,
                                unique_id=unique_id,
                                machine_name=node['machine_name'],
                                model=cam['camera']['model'],
                                version=cam['camera']['version'],
                                using_sync=False,
                                folder=cam['audio']['filename'][0],
                                thumbnail_filename=None,
                                width=0,
                                height=0,
                                bitdepth=cam['audio']['bits_per_sample'],
                                frame_count=cam['audio']['recorded_samples'],
                                dropped_frames=0,
                                total_size=0,
                                duration=cam['audio']['duration'],
                                framerate=cam['audio']['sample_rate'],
                                rotation=0,
                                all_files=';'.join(all_files))
                            camera.save()

                        cam_index = cam_index + 1

        summary['project_name'] = loc.cur_project.name
        summary['session_name'] = loc.cur_session.name
        summary['shot_name'] = loc.cur_shot.name
        summary['take_index'] = take.sequence
        summary['take_id'] = take.id

        loc.cur_shot.increment_take()
        loc.save()