From 1c47cf5f94244199dacd3f44a9cf8ffa69b81a38 Mon Sep 17 00:00:00 2001 From: Gu1llaum-3 Date: Sat, 13 May 2023 23:29:32 +0200 Subject: [PATCH] =?UTF-8?q?Diverses=20corrections=20sur=20app.py=20et=20aj?= =?UTF-8?q?out=20de=20la=20possibilit=C3=A9=20de=20t=C3=A9l=C3=A9charger?= =?UTF-8?q?=20des=20pistes=20en=20plus=20des=20albums=20et=20des=20playlis?= =?UTF-8?q?ts.=20Modification=20du=20fichier=20index.html=20afin=20d'accep?= =?UTF-8?q?ter=20les=20liens=20avec=20"track"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.py | 20 +++++++++++++------- templates/index.html | 10 +++++----- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/app.py b/app.py index 54b159f..ccb302f 100644 --- a/app.py +++ b/app.py @@ -1,16 +1,18 @@ -from flask import Flask, request, redirect, url_for, send_file, render_template, send_from_directory, jsonify +from flask import Flask, request, send_file, render_template from subprocess import run -from datetime import datetime -import os, logging, json, secrets +import os +import secrets app = Flask(__name__) app.secret_key = secrets.token_hex(16) + @app.route('/', methods=['GET', 'POST']) def download_file(): session_id = secrets.token_hex(16) download_param_album = '{artist}/{album}/{artist} - {title}' download_param_playlist = '{playlist}/{artists}/{album} - {title} {artist}' + download_param_track = '{artist}/{album}/{artist} - {title}' if request.method == 'POST': url1 = request.form['url1'] @@ -38,18 +40,22 @@ def download_file(): run(['python3', '-m', 'spotdl', url, '--output', download_param_album]) elif "playlist" in url: run(['python3', '-m', 'spotdl', url, '--output', download_param_playlist]) + elif "track" in url: + run(['python3', '-m', 'spotdl', url, '--output', download_param_track]) run(['zip', '-r', 'musics.zip', '.']) os.chdir('../') - PATH = "downloads/musics.zip" - return send_file(PATH, as_attachment=True) + path = "downloads/musics.zip" + return send_file(path, as_attachment=True) return render_template('index.html') + @app.errorhandler(404) -def page_not_found(error): +def page_not_found(): return render_template('404.html'), 404 + if __name__ == '__main__': - app.run(debug=True, port=3000) \ No newline at end of file + app.run(debug=True, port=3000) diff --git a/templates/index.html b/templates/index.html index 0c1ce83..b3dd93d 100644 --- a/templates/index.html +++ b/templates/index.html @@ -17,19 +17,19 @@
- +
- +
- +
- +
- +