diff --git a/app.py b/app.py index bf603f1..675c6e5 100644 --- a/app.py +++ b/app.py @@ -1,8 +1,6 @@ from flask import Flask, request, redirect, url_for, send_file, render_template, send_from_directory from subprocess import run -from datetime import datetime import os -import logging app = Flask(__name__) @@ -13,7 +11,7 @@ def process_file(urls): download_param_track = '{artist}/{album}/{artist} - {title}' os.chdir('downloads') - # os.system(f'rm -rf *') + os.system(f'rm -rf *') for url in urls: if url: @@ -23,8 +21,7 @@ def process_file(urls): run(['python3', '-m', 'spotdl', url, '--output', download_param_playlist]) elif "track" in url: run(['python3', '-m', 'spotdl', url, '--output', download_param_track]) - # os.system(f'zip -r musics.zip ./downloads') - # run(['zip', '-r', 'musics.zip', '.']) + run(['zip', '-r', 'musics.zip', '.']) os.chdir('../') @@ -32,20 +29,9 @@ def process_file(urls): def upload_form(): return render_template('index.html') -# Fonctionne -# @app.route('/download/') -# def download_file(filename): -# PATH='file.txt' -# return send_file(PATH, as_attachment=True) - @app.route('/download', methods=['POST']) def download_file(): - # votre code de téléchargement ici - # now = datetime.now() - # date_time = now.strftime("%Y-%m-%d %H-%M-%S") - # with open(f"file.txt", "w") as file: - # file.write(date_time) if request.method == 'POST': url1 = request.form['url1'] url2 = request.form['url2'] @@ -69,6 +55,10 @@ def download_file(): # return send_file(path, as_attachment=True) return render_template('finish.html') +@app.route('/zip', methods=['GET', 'POST']) +def zip(): + path = "downloads/musics.zip" + return send_file(path, as_attachment=True) @app.errorhandler(404) def page_not_found(error): # error est necessaire diff --git a/templates/finish.html b/templates/finish.html index 986cf00..ff989f6 100644 --- a/templates/finish.html +++ b/templates/finish.html @@ -5,7 +5,8 @@

SpotDL Web

-

Téléchargement terminé

+

Votre musique est prête à être téléchargée

+ {% if message %} diff --git a/templates/index.html b/templates/index.html index 6b5b51d..f093fb6 100644 --- a/templates/index.html +++ b/templates/index.html @@ -38,7 +38,7 @@
- +