From 11a6770eb2ce7b3007e1f2a9e0c35d683d11874f Mon Sep 17 00:00:00 2001 From: James Seward Date: Thu, 15 Feb 2018 09:55:30 +0000 Subject: [PATCH] Support video uploads --- lambda/lambda_function.py | 16 ++++++++++++++-- s3-files/inc/style.css | 5 +++++ s3-files/template/template.html | 8 ++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/lambda/lambda_function.py b/lambda/lambda_function.py index dec44b0..637f19a 100644 --- a/lambda/lambda_function.py +++ b/lambda/lambda_function.py @@ -2,6 +2,7 @@ import pystache import urllib import os +import os.path from aws_xray_sdk.core import xray_recorder from aws_xray_sdk.core import patch_all @@ -14,6 +15,15 @@ def lambda_handler(event, context): bucket = record['s3']['bucket']['name'] key = urllib.unquote_plus(record['s3']['object']['key']) key_filename = key.split('/')[1] + + is_image = True + is_video = False + (_, key_extension) = os.path.splitext(key_filename) + key_extension = key_extension.lower() + if key_extension.lower() in ['.mp4']: + is_image = False + is_video = True + print('Downloading template') template_body_response = s3.get_object( Bucket=bucket, @@ -23,7 +33,7 @@ def lambda_handler(event, context): target_filename = record['s3']['object']['eTag'][0:8] target_object = 'v/{}'.format(target_filename) labels = [] - if CLOUD_BUCKET_REGION is not None: + if is_image and CLOUD_BUCKET_REGION is not None: try: response = rekognition.detect_labels(Image={'S3Object': { 'Bucket': bucket, @@ -50,7 +60,9 @@ def lambda_handler(event, context): 'target_object': target_object, 'twitter': CLOUD_TWITTER, 'has_twitter': CLOUD_TWITTER is not None, - 'description': description + 'description': description, + 'is_image': is_image, + 'is_video': is_video })) xray_recorder.end_subsegment() print('Writing rendered template to {}'.format(target_object)) diff --git a/s3-files/inc/style.css b/s3-files/inc/style.css index a2fc51a..2211888 100644 --- a/s3-files/inc/style.css +++ b/s3-files/inc/style.css @@ -14,3 +14,8 @@ body { box-shadow: 0px 0px 5px 6px #101010; } +#asset_video { + max-width: 95vw; + max-height: 95vh; + box-shadow: 0px 0px 5px 6px #101010; +} diff --git a/s3-files/template/template.html b/s3-files/template/template.html index 80f7b99..3245413 100644 --- a/s3-files/template/template.html +++ b/s3-files/template/template.html @@ -20,7 +20,15 @@
+ {{#is_image}} {{description}} + {{/is_image}} + {{#is_video}} + + {{/is_video}}