forked from p0n1/epub_to_audiobook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wsgi.py
36 lines (26 loc) · 921 Bytes
/
wsgi.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
from flask import request, render_template, Flask
from os import remove, path, mkdir
import main
app = Flask(__name__)
# Show index page when accessed through browser
@app.route('/', methods=['GET'])
def index():
return render_template('index.html')
# Handle POST upload request
@app.route('/', methods=['POST'])
def upload_ebook():
f = request.files['ebook']
# Save e-book file
work_folder = '../books/' + path.splitext(f.filename)[0]
input_path = work_folder + "/" + f.filename
try:
mkdir(work_folder)
except FileExistsError:
pass # Ignore if folder already exists
f.save(input_path)
try:
# Convert audio book and get base file name
main.main(input_path, work_folder)
except:
return '<script>alert("Conversion failed! See terminal for more details.");</script>'
return '<script>alert("Conversion successful!");</script>'