Modification de app.py
This commit is contained in:
parent
b750014b76
commit
e98349f6f9
38
app.py
38
app.py
@ -1,12 +1,28 @@
|
|||||||
from flask import Flask, render_template, request
|
from flask import Flask, request, redirect, url_for, send_file
|
||||||
import os
|
import os
|
||||||
import time
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
def download_music(url):
|
@app.route('/')
|
||||||
|
def upload_form():
|
||||||
|
return '''
|
||||||
|
<form method="POST">
|
||||||
|
<label for="url">URL:</label>
|
||||||
|
<input type="text" name="url" id="url">
|
||||||
|
<input type="submit" value="Téléchargement">
|
||||||
|
</form>
|
||||||
|
'''
|
||||||
|
|
||||||
path = os.path.expanduser('~')
|
@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_album = '{artist}/{album}/{artist} - {title}'
|
||||||
download_param_playlist = '{playlist}/{artists}/{album} - {title} {artist}'
|
download_param_playlist = '{playlist}/{artists}/{album} - {title} {artist}'
|
||||||
|
|
||||||
@ -19,11 +35,11 @@ def download_music(url):
|
|||||||
os.chdir(f"{path}")
|
os.chdir(f"{path}")
|
||||||
print("playlist found")
|
print("playlist found")
|
||||||
os.system(f'python3 -m spotdl {url} --output "{download_param_playlist}"')
|
os.system(f'python3 -m spotdl {url} --output "{download_param_playlist}"')
|
||||||
|
|
||||||
|
|
||||||
@app.route('/', methods=['GET', 'POST'])
|
# @app.route('/download/<path:filename>')
|
||||||
def index():
|
# def download_file(filename):
|
||||||
message = None
|
# return send_file(filename, attachment_filename=filename, as_attachment=True)
|
||||||
if request.method == 'POST':
|
|
||||||
url = request.form['url']
|
if __name__ == '__main__':
|
||||||
message = download_music(url)
|
app.run(debug=True, port=3000)
|
||||||
return render_template('index.html', message=message)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user