-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
83 lines (70 loc) · 2.31 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
from flask import Flask,render_template,request,flash,redirect,url_for,jsonify
import subprocess
from flask import after_this_request
from wtforms import Form, TextField, TextAreaField, validators, StringField, SubmitField
import json
import os
import audio
app = Flask(__name__)
@app.route("/download/<var>")
def hello(var):
cmd = ['spotdl','--song',var,'-f','./','--avconv']
p = subprocess.Popen(cmd,stdout = subprocess.PIPE,
stderr = subprocess.PIPE,
stdin = subprocess.PIPE)
out,err = p.communicate()
if out:
return redirect(url_for('convert'))
else:
return "Failure"
@app.route('/',methods=['GET','POST'])
def index():
return render_template('index.html')
@app.route('/result',methods=['GET','POST'])
def result():
if request.method=='POST':
result = request.form.to_dict()
# @after_this_request
# def removefile(response):
# os.remove('./converted.tta')
# os.remove('./converted_audio.wav')
return redirect(url_for('hello',var=result['query']))
@app.route('/conv')
def convert():
os.system('ls | grep \.m4a$ > m.txt')
for line in open('m.txt'):
var = line.split('\n')[0]
cmd4 = ['ffmpeg','-i',var,'converted.tta']
p = subprocess.Popen(cmd4,stdout = subprocess.PIPE,
stderr = subprocess.PIPE,
stdin = subprocess.PIPE)
out,err = p.communicate()
@after_this_request
def removefile(response):
os.remove('./' + var)
os.remove('./m.txt')
return response
return redirect(url_for('extract'))
# else :
# return err
@app.route('/extract')
def extract():
# check()
# cmd = ['python','audio.py']
# p = subprocess.Popen(cmd,stdout = subprocess.PIPE,
# stderr = subprocess.PIPE,
# stdin = subprocess.PIPE)
# out,err = p.communicate()
# return "I am here"
var = json.dumps(audio.dunc())
print(var)
return render_template('piano.html',name=var)
@app.route('/dump')
def dump(msg):
return(jsonify(msg))
@app.route('/check')
def check():
# dump(audio.dunc())
return render_template('piano.html',name = json.dumps(audio.dunc()))
if __name__ == '__main__':
app.run(debug=True)