from flask import Flask, request, redirect, url_for, send_file
import os
app = Flask(__name__)
@app.route('/')
def upload_form():
return '''
'''
@app.route('/', methods=['GET', 'POST'])
def index():
message = None
if request.method == 'POST':
url = request.form['url']
result = process_file(url)
return '''
Téléchargement terminé
'''
def process_file(url):
path = os.path.expanduser('~/musics')
download_param_album = '{artist}/{album}/{artist} - {title}'
download_param_playlist = '{playlist}/{artists}/{album} - {title} {artist}'
if "album" in url:
#os.makedirs(f"{path}")
os.chdir(f"{path}")
print ("album found")
os.system(f'python3 -m spotdl {url} --output "{download_param_album}"')
elif "playlist" in url:
os.chdir(f"{path}")
print("playlist found")
os.system(f'python3 -m spotdl {url} --output "{download_param_playlist}"')
# @app.route('/download/')
# def download_file(filename):
# return send_file(filename, attachment_filename=filename, as_attachment=True)
if __name__ == '__main__':
app.run(debug=True, port=3000)