예제 #1
0
def index(page):
    count = db.query(Video).count()
    start = (page - 1) * PER_PAGE
    num_pages = ((count - 1) / PER_PAGE) + 1

    prev_url = None
    if page > 1:
        prev_url = "/page/{}".format(page - 1)
    next_url = None
    if count > start + PER_PAGE:
        next_url = "/page/{}".format(page + 1)

    videos = db.query(Video).order_by(desc(Video.id))
    if page > 1:
        videos = videos.offset(start)
    videos = videos.limit(PER_PAGE)
    vid_urls = []
    for vid in videos:
        vid_urls.append(helper.get_s3url(vid.key))
    return render_template(
        "index.html",
        aws_access_key=AWS_ACCESS_KEY,
        bucket=BUCKET,
        accepted_extensions=",".join(MIME_TYPES.keys()),
        mime_types=json.dumps(MIME_TYPES),
        videos=videos,
        vid_urls=vid_urls,
        prev_url=prev_url,
        next_url=next_url,
        page=page,
        num_pages=num_pages,
        page_list=range(1, num_pages + 1),
    )
예제 #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)