-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathapp.py
56 lines (48 loc) · 1.83 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
from flask import Flask, request, render_template, request, url_for, redirect, Markup, Response, send_file, send_from_directory, make_response
from datetime import datetime
import csv
import os
import nightcore
import time
import random
import glob
app = Flask(__name__)
@app.route('/image', methods=['GET'])
def returnImage():
return send_file(random.choice(list(glob.glob("static/nightcorepics/*"))), mimetype='image/gif')
@app.route('/nightcore/', methods=['POST'])
def song():
a = nightcore.nightcore()
content = request.get_json()
a.song(content['artist'], content['song'])
file = a.genVideos()
os.system("rm -r {}".format(file.replace('.mp4', '')))
os.system("rm {}".format(file.replace('.mp4', '.mp3')))
return send_from_directory(directory="", filename=file)
# @app.route('/downloadFile/<fileName>', methods=["GET"])
def downloadFile(fileName=None):
if fileName == None:
return "<h1>Invalid File</h1>"
return send_file("static/"+fileName, attachment_filename=fileName, as_attachment=True)
@app.route('/download/', methods=["GET"])
def download():
exp = "ERROR PLEASE TRY AGAIN LATER"
for i in range(1,4):
try:
artist = request.args.get("artist")
song = request.args.get("song")
fileName = nightcore.createYoutubeCLI(artist, song)
fileNameNew = fileName[::-1].partition("/")[0][::-1]
os.system("mv {} static/{}".format(fileName, fileNameNew))
return redirect(url_for('index', fileName=fileNameNew))
except Exception as exp:
print(exp)
time.sleep(i*2)
return "<h1>{}</h1>".format(exp)
@app.route('/<fileName>', methods=['GET'])
def index(fileName="final8.mp3"):
if request.args.get("download", False) != False:
return downloadFile(fileName)
return render_template("viz.html", fileURL='http://127.0.0.1:5000/static/{}'.format(fileName))
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000, debug=True)