diff --git a/.old/app.py b/.old/app.py new file mode 100644 index 0000000..b28c70c --- /dev/null +++ b/.old/app.py @@ -0,0 +1,82 @@ +from flask import Flask, request, redirect, url_for, send_file, render_template +from subprocess import run +import os +import logging + +app = Flask(__name__) + +@app.route('/') +def upload_form(): + return render_template('upload.html') + +def process_file(urls): + # path = os.path.expanduser('~/musics/downloads') + #path = '/home/gu1ll4um3/github/SpotDL_Web/downloads' + #path = 'downloads/' + download_param_album = '{artist}/{album}/{artist} - {title}' + download_param_playlist = '{playlist}/{artists}/{album} - {title} {artist}' + + os.chdir('downloads') + #os.system(f'rm -rf *') + + logs = [] # Créer une liste vide pour stocker les logs + for url in urls: + if url: + if "album" in url: + #os.system(f'python3 -m spotdl {url} --output "{download_param_album}"') + run(['python3', '-m', 'spotdl', url, '--output', download_param_album]) + logs.append(f'Téléchargement de l album à l\'adresse {url}') + elif "playlist" in url: + os.system(f'python3 -m spotdl {url} --output "{download_param_playlist}"') + logs.append(f'Téléchargement de la playlist à l\'adresse {url}') + + # os.system(f'zip -r musics.zip ./downloads') + run(['zip', '-r', 'musics.zip', '.']) + logs.append(f'Création du fichier ZIP musics.zip') + + return logs # Retourner la liste des logs + +@app.route('/', methods=['GET', 'POST']) +def index(): + message = None + if request.method == 'POST': + url1 = request.form['url1'] + url2 = request.form['url2'] + url3 = request.form['url3'] + url4 = request.form['url4'] + url5 = request.form['url5'] + + # Vérifier si au moins un champ est vide + if not url1 and not url2 and not url3 and not url4 and not url5: + return render_template('erreur.html') + + urls = [url1, url2, url3, url4, url5] + logs = process_file(urls) + #process_file(urls) + #print(resultProcessFile) + + with open('/home/gu1ll4um3/github/SpotDL_Web/logs/erreurs.log', 'r') as f: + result2 = f.readlines() + return render_template('download_complete.html', logs=logs) + #return render_template('download_complete.html', result2=result2) + +@app.route('/download', methods=['GET']) +def download(): + # PATH='/home/gu1ll4um3/musics/downloads/musics.zip' + #os.chdir('downloads') + PATH='downloads/musics.zip' + return send_file(PATH,as_attachment=True) + +# @app.route('/errors') +# def errors(): +# with open('erreurs.txt', 'r') as f: +# lines = f.readlines() +# return render_template('logs.html', lines=lines) + +@app.route('/test') +def test(): + return render_template('test.html') + + +if __name__ == '__main__': + app.run(debug=True, port=3000) diff --git a/logs/erreurs.log b/.old/logs/erreurs.log similarity index 100% rename from logs/erreurs.log rename to .old/logs/erreurs.log diff --git a/.old/static/css/style.css b/.old/static/css/style.css new file mode 100644 index 0000000..0defc8c --- /dev/null +++ b/.old/static/css/style.css @@ -0,0 +1,72 @@ +body{ + display: flex; + justify-content: center; + align-items: center; + + background-color: black; +} + +.erreur { + display: flex; + justify-content: center; + align-items: center; + flex-direction: column; +} + +.download_complete { + display: flex; + justify-content: center; + align-items: center; + flex-direction: column; +} + +.all { + align-items: center; + flex-direction: column; +} + +.titre{ + display: flex; + justify-content: center; + color: rgb(24,216,96); + /* align-items: center; */ +} + +.procedure { + display: flex; + justify-content: center; + flex-direction: column; + text-align: center; +} + +h2, a { + color: white; +} + +.url { + display: block; + justify-content:center; + width: auto; + flex: 1 1 0; + /* align-items: center; */ +} + +.urlbox { + display: block; + /* align-items: flex-start; */ + flex: 1 1 0; + width: 225; +} + +form { + display: flex ; + justify-content: center; + align-items: center; + flex-direction: column; + width : auto ; +} + +button { + display: block; + margin: 10px auto; + } \ No newline at end of file diff --git a/static/css/style.css.old b/.old/static/css/style.css.old similarity index 100% rename from static/css/style.css.old rename to .old/static/css/style.css.old diff --git a/static/css/style.css.old2 b/.old/static/css/style.css.old2 similarity index 100% rename from static/css/style.css.old2 rename to .old/static/css/style.css.old2 diff --git a/templates/download_complete.html b/.old/templates/download_complete.html similarity index 100% rename from templates/download_complete.html rename to .old/templates/download_complete.html diff --git a/templates/erreur.html b/.old/templates/erreur.html similarity index 100% rename from templates/erreur.html rename to .old/templates/erreur.html diff --git a/templates/logs.html b/.old/templates/logs.html similarity index 100% rename from templates/logs.html rename to .old/templates/logs.html diff --git a/templates/test.html b/.old/templates/test.html similarity index 100% rename from templates/test.html rename to .old/templates/test.html diff --git a/templates/upload.html b/.old/templates/upload.html similarity index 100% rename from templates/upload.html rename to .old/templates/upload.html diff --git a/app.py b/app.py index b28c70c..fb44ab7 100644 --- a/app.py +++ b/app.py @@ -1,45 +1,48 @@ -from flask import Flask, request, redirect, url_for, send_file, render_template +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__) -@app.route('/') -def upload_form(): - return render_template('upload.html') - def process_file(urls): - # path = os.path.expanduser('~/musics/downloads') - #path = '/home/gu1ll4um3/github/SpotDL_Web/downloads' - #path = 'downloads/' download_param_album = '{artist}/{album}/{artist} - {title}' download_param_playlist = '{playlist}/{artists}/{album} - {title} {artist}' os.chdir('downloads') - #os.system(f'rm -rf *') + os.system(f'rm -rf *') + #run(['rm', '-rf', '*']) ne fonctionne pas ... ?? - logs = [] # Créer une liste vide pour stocker les logs for url in urls: if url: if "album" in url: - #os.system(f'python3 -m spotdl {url} --output "{download_param_album}"') run(['python3', '-m', 'spotdl', url, '--output', download_param_album]) - logs.append(f'Téléchargement de l album à l\'adresse {url}') elif "playlist" in url: - os.system(f'python3 -m spotdl {url} --output "{download_param_playlist}"') - logs.append(f'Téléchargement de la playlist à l\'adresse {url}') + run(['python3', '-m', 'spotdl', url, '--output', download_param_playlist]) - # os.system(f'zip -r musics.zip ./downloads') + #os.system(f'zip -r musics.zip ./downloads') run(['zip', '-r', 'musics.zip', '.']) - logs.append(f'Création du fichier ZIP musics.zip') - - return logs # Retourner la liste des logs + os.chdir('../') @app.route('/', methods=['GET', 'POST']) -def index(): - message = None - if request.method == 'POST': +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'] url3 = request.form['url3'] @@ -51,32 +54,10 @@ def index(): return render_template('erreur.html') urls = [url1, url2, url3, url4, url5] - logs = process_file(urls) - #process_file(urls) - #print(resultProcessFile) - - with open('/home/gu1ll4um3/github/SpotDL_Web/logs/erreurs.log', 'r') as f: - result2 = f.readlines() - return render_template('download_complete.html', logs=logs) - #return render_template('download_complete.html', result2=result2) - -@app.route('/download', methods=['GET']) -def download(): - # PATH='/home/gu1ll4um3/musics/downloads/musics.zip' - #os.chdir('downloads') - PATH='downloads/musics.zip' - return send_file(PATH,as_attachment=True) - -# @app.route('/errors') -# def errors(): -# with open('erreurs.txt', 'r') as f: -# lines = f.readlines() -# return render_template('logs.html', lines=lines) - -@app.route('/test') -def test(): - return render_template('test.html') + process_file(urls) + PATH = "downloads/musics.zip" + return send_file(PATH, as_attachment=True) if __name__ == '__main__': - app.run(debug=True, port=3000) + app.run(debug=True, port=3000) \ No newline at end of file diff --git a/static/css/style.css b/static/css/style.css index 0defc8c..cb9f837 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -1,72 +1,85 @@ -body{ +body { + margin: 0; + font-family: Arial, Helvetica, sans-serif; + background-color: #131313; + color: #ffffff; + } + + .container { + max-width: 700px; + margin: 0 auto; + padding: 20px; + box-sizing: border-box; + } + + .form-group { display: flex; - justify-content: center; - align-items: center; - - background-color: black; -} - -.erreur { - display: flex; - justify-content: center; - align-items: center; flex-direction: column; -} + margin-bottom: 20px; + } -.download_complete { - display: flex; - justify-content: center; - align-items: center; - flex-direction: column; -} + .form-group label { + font-weight: bold; + margin-bottom: 5px; + } -.all { - align-items: center; - flex-direction: column; -} + .form-control { + background-color: #232323; + border: none; + border-radius: 5px; + padding: 10px; + color: #ffffff; + } -.titre{ - display: flex; - justify-content: center; - color: rgb(24,216,96); - /* align-items: center; */ -} + /* .form-control:focus { + outline: none; + box-shadow: 0 0 0 2px rgb(24,216,96); + } */ + .form-control:valid:not(:placeholder-shown) { + outline: none; + border: 2px solid rgb(24,216,96); + } + .form-control:invalid { + outline: none; + border: 2px solid red; + } -.procedure { - display: flex; - justify-content: center; - flex-direction: column; - text-align: center; -} -h2, a { - color: white; -} -.url { - display: block; - justify-content:center; - width: auto; - flex: 1 1 0; - /* align-items: center; */ -} + .btn { + background-color: rgb(24,216,96); + border: none; + border-radius: 5px; + padding: 10px 20px; + color: #131313; + font-weight: bold; + cursor: pointer; + text-decoration:none + } -.urlbox { - display: block; - /* align-items: flex-start; */ - flex: 1 1 0; - width: 225; -} + .btn2 { + margin-top: 10px; + background-color: rgb(24,216,96); + border: none; + border-radius: 5px; + padding: 10px 20px; + color: #131313; + font-weight: bold; + cursor: pointer; + text-decoration:none + } -form { - display: flex ; - justify-content: center; - align-items: center; - flex-direction: column; - width : auto ; -} + .btn:hover { + background-color: rgb(24,216,96); + color: whitesmoke + } -button { - display: block; - margin: 10px auto; + .title { + color: rgb(24,216,96); + } + + @media (max-width: 600px) { + .container { + padding: 10px; + } } \ No newline at end of file diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..5d2a086 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,42 @@ + + + + + + + SpotDL Web + + + +
+

SpotDL Web

+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+ +
+ +
+ + +