Esempio n. 1
0
def upload_to_s3(local_path, key=None):
    if key is None:
        key = os.path.basename(local_path)
    bucket = helper.get_bucket()
    k = Key(bucket)
    k.key = key
    k.set_contents_from_filename(local_path)
    k.set_canned_acl('public-read')
    k.set_metadata('Content-Type', helper.get_mimetype(k.key))
    return k
Esempio n. 2
0
def _process_fullcopy(key):

    # Set the content-type correctly
    bucket = helper.get_bucket()
    k = bucket.lookup(key)
    k.copy(k.bucket, k.name, preserve_acl=True, metadata={'Content-Type': helper.get_mimetype(k.name)})

    orig_video = Video(key=key, status='downloading')
    db.add(orig_video)
    db.commit()
    url = helper.get_s3url(key)
    orig_path = download_url(url)

    orig_video.update(get_video_attrs(orig_path))
    orig_video.status = 'done'

    for preset in FFMPEG_PRESETS.iterkeys():

        # Transcode/Upload based on ffmpeg preset
        iphone_path = os.path.splitext(orig_path)[0] + preset
        iphone_video = Video(key=os.path.basename(iphone_path), status='transcoding')
        db.add(iphone_video)
        db.commit()

        try:
            make_iphone(orig_path, iphone_path, preset)
            iphone_video.update(get_video_attrs(iphone_path))
        except:
            iphone_video.status = 'transcoding error'
        else:
            iphone_video.status = 'uploading'

        db.commit()

        if iphone_video.status == 'uploading':
            upload_to_s3(iphone_path)
            iphone_video.status = 'done'
            db.commit()
            os.remove(iphone_path)

    os.remove(orig_path)