-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
47 lines (33 loc) · 1.02 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
'''TubeLoad server'''
import os
import traceback
from flask import Flask, request, send_from_directory
from downloader import Downloader
app = Flask(__name__)
downloader = Downloader()
@app.route('/')
def root():
return app.send_static_file('index.html')
@app.route('/static/<path:path>')
def static_folder(path):
return app.send_static_file(path)
@app.route('/images/<path:path>')
def images(path):
return app.send_static_file('images/' + path)
@app.route('/version')
def get_version():
with open ('static/version.txt', 'r') as version_file:
return version_file.read()
@app.route('/download')
def download():
song_id = request.args['id']
if song_id.find('.') == -1:
try:
downloader.download(song_id)
except Exception as e:
return traceback.format_exc(), 500
return send_from_directory(downloader.songs_path, song_id + '.mp3', as_attachment=True)
else:
return 'Invalid id', 400
if __name__ == '__main__':
app.run(host='0.0.0.0')