-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
86 lines (65 loc) · 2.06 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
from flask import Flask,send_file,send_from_directory
from flask import request, redirect, url_for,jsonify
import subprocess
from werkzeug.utils import secure_filename
import os
import urllib.request
import ssl
# make it unsafe
ssl._create_default_https_context = ssl._create_unverified_context
app = Flask(__name__)
app.config['CLIENT_RESULT'] = "./result.mp4"
@app.route("/check")
def check():
return "OK"
@app.route("/")
def base():
try:
url = request.args.get('url')
text = request.args.get('text')
with open('input.txt', 'w') as f:
f.write(text)
# input written
# find video
try:
urllib.request.urlretrieve(url, 'input.mp4')
except:
return "Failed, no active url!"
subprocess.call(['sh', './run.sh'])
return send_from_directory(directory=app.root_path, path="./result.mp4", as_attachment=True)
# now take input video and run python file on it
except TypeError:
return "provide url and text!!!!"
@app.route('/get',methods = ['GET','POST'])
def get_csv():
try:
return send_from_directory(directory=app.root_path, path="./result.mp4", as_attachment=True)
except FileNotFoundError:
abort(404)
ALLOWED_EXTENSIONS = set(['mp4'])
def allowed_file(filename):
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
@app.route('/file-upload', methods=['POST'])
def upload_file():
# check if the post request has the file part
if 'file' not in request.files:
resp = jsonify({'message' : 'No file part in the request'})
resp.status_code = 400
return resp
file = request.files['file']
if file.filename == '':
resp = jsonify({'message' : 'No file selected for uploading'})
resp.status_code = 400
return resp
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file.save("./input.mp4")
resp = jsonify({'message' : 'File successfully uploaded'})
resp.status_code = 201
return resp
else:
resp = jsonify({'message' : 'Allowed file types are mp4'})
resp.status_code = 400
return resp
if __name__ == '__main__':
app.run(host='0.0.0.0', port=3000)