From 9b04348b329e669c716e0122308e1d6186f56345 Mon Sep 17 00:00:00 2001 From: Guillaume Date: Mon, 29 May 2023 12:31:01 +0200 Subject: [PATCH] =?UTF-8?q?=20On=20branch=20ddl=20=20Changes=20to=20be=20c?= =?UTF-8?q?ommitted:=20=09modified:=20=20=20app.py=20=09modified:=20=20=20?= =?UTF-8?q?templates/finish.html=20=09modified:=20=20=20templates/index.ht?= =?UTF-8?q?ml=20T=C3=A9l=C3=A9chargement=20direct=20d'un=20fichier=20zip?= =?UTF-8?q?=20puis=20supprime=20le=20dossier.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.py | 22 ++++++---------------- templates/finish.html | 3 ++- templates/index.html | 2 +- 3 files changed, 9 insertions(+), 18 deletions(-) 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 @@
- +