forked from Frameio/custom-actions-app-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
88 lines (76 loc) · 2.99 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
from flask import Flask, jsonify, request
from lib.video_handler import render_and_upload_slate
from multiprocessing import Pool, Process
from pprint import pprint
from redis import Redis, StrictRedis
import os
import json
app = Flask(__name__)
try:
redis_conn = StrictRedis(host=os.getenv("REDIS_HOSTNAME", default="localhost"), port=6379, charset="utf-8", decode_responses=True)
except Exception as e:
print(e)
redis_conn = StrictRedis(host=os.getenv("REDIS_HOSTNAME", default="redis"), port=6379, charset="utf-8", decode_responses=True)
# GET is not used with custom actions, but tools like Glitch or Postman are often set to try a GET request.
# This is provided so you don't receive a 'Can't GET' notification.
@app.route('/', methods=['GET', 'POST'])
def hello_www():
return "Hello World!"
# Send a POST request to /actions to create a form in the Frame.io web app
@app.route('/new', methods=['POST'])
def callback():
data = request.json
pprint(data)
interaction_id = data['interaction_id']
## WIP load and pass resource ID on to the encoder so that we can download the correct asset and metadata and get to work.
try:
resource_id = data['resource']['id']
if resource_id:
# Save the resource ID to the redis with the interaction id so we can call it back in a few seconds when the form is submitted
redis_conn.hset("interaction_ids", interaction_id, resource_id)
except KeyError:
resource_id = redis_conn.hget("interaction_ids", interaction_id)
if "data" in data.keys():
if data['type'] == "slate.generate":
# pprint(data)
# Grab relevant data
try:
timecode_burnin = data['data']['timecode']
except KeyError:
timecode_burnin = None
client = data['data']['client']
project = data['data']['project']
# Pass it to the rendering function so that we can return our response saying the job has started
p = Process(target=render_and_upload_slate, kwargs={"client": client, "project": project, "timecode_burnin": timecode_burnin, "resource_id": resource_id, "interaction_id": interaction_id})
p.start()
return jsonify({
'title': 'Submitted for rendering!',
'description': 'Your slate is being generated and added to your video',
'resource_id': resource_id, # remove this before going live
'interaction_id': interaction_id # remove this before going live
})
else:
return jsonify({
'title': 'Bad request',
'description': 'You hit the endpoint with the wrong info'
})
return jsonify({
'title': 'Add a slate!',
'description': 'Fill out the following to add a slate to your video!',
'fields': [
{
'type': 'text',
'name': 'client',
'label': 'Client',
'value': 'Placeholder Client'
},
{
'type': 'text',
'name': 'project',
'label': 'Project',
'value': 'Placeholder Project'
},
]
})
if __name__ =="__main__":
app.run(host="0.0.0.0", debug=True,port=80)