-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
48 lines (34 loc) · 975 Bytes
/
app.py
File metadata and controls
48 lines (34 loc) · 975 Bytes
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
from flask import Flask, render_template, request
from threading import Thread
from flask.helpers import send_file, url_for
from downloader import downloader
from flask import after_this_request
import os
import io
app = Flask('')
@app.route('/')
def home():
return render_template("index.html")
@app.route('/result', methods=['POST'])
def result():
playlist = request.form['playlist']
file_path = downloader(playlist)
return_data = io.BytesIO()
with open(file_path, 'rb') as fo:
return_data.write(fo.read())
return_data.seek(0)
os.remove(file_path)
return send_file(return_data, mimetype='application/zip',
attachment_filename='songs.zip')
@app.errorhandler(404)
def not_found(e):
return render_template("404.html")
@app.errorhandler(500)
def error(e):
return render_template("500.html")
def run():
app.run(host='0.0.0.0')
def show_site():
t = Thread(target=run)
t.start()
run()