From 76f96060e5f382ed73a1f83b051def6d164c715b Mon Sep 17 00:00:00 2001 From: Gu1llaum-3 Date: Sun, 14 May 2023 08:30:26 +0200 Subject: [PATCH] MAJ dossier docker --- .idea/.gitignore | 3 + Docker/requirements.txt | 2 +- Docker/src/.old/app.py | 68 +++++++++ Docker/src/.old/static/css/style.css | 193 ++++++++++++++++++++++++++ Docker/src/.old/templates/404.html | 15 ++ Docker/src/.old/templates/erreur.html | 18 +++ Docker/src/.old/templates/index.html | 56 ++++++++ Docker/src/app.py | 77 +++++----- Docker/src/static/js/script.js | 6 + Docker/src/templates/404.html | 23 ++- Docker/src/templates/erreur.html | 30 ++-- Docker/src/templates/index.html | 39 ++---- Docker/src/templates/layout.html | 16 +++ Docker/src/templates/modele.html | 7 + identifiants.json | 3 - 15 files changed, 455 insertions(+), 101 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 Docker/src/.old/app.py create mode 100644 Docker/src/.old/static/css/style.css create mode 100644 Docker/src/.old/templates/404.html create mode 100644 Docker/src/.old/templates/erreur.html create mode 100644 Docker/src/.old/templates/index.html create mode 100644 Docker/src/static/js/script.js create mode 100644 Docker/src/templates/layout.html create mode 100644 Docker/src/templates/modele.html delete mode 100644 identifiants.json diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/Docker/requirements.txt b/Docker/requirements.txt index 6dc362b..52f8112 100644 --- a/Docker/requirements.txt +++ b/Docker/requirements.txt @@ -1,2 +1,2 @@ -spotdl flask +spotdl \ No newline at end of file diff --git a/Docker/src/.old/app.py b/Docker/src/.old/app.py new file mode 100644 index 0000000..045fbcc --- /dev/null +++ b/Docker/src/.old/app.py @@ -0,0 +1,68 @@ +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__) + +def process_file(urls): + download_param_album = '{artist}/{album}/{artist} - {title}' + download_param_playlist = '{playlist}/{artists}/{album} - {title} {artist}' + + os.chdir('downloads') + os.system(f'rm -rf *') + #run(['rm', '-rf', '*']) ne fonctionne pas ... ?? + + for url in urls: + if url: + if "album" in url: + run(['python3', '-m', 'spotdl', url, '--output', download_param_album]) + elif "playlist" in url: + run(['python3', '-m', 'spotdl', url, '--output', download_param_playlist]) + + #os.system(f'zip -r musics.zip ./downloads') + run(['zip', '-r', 'musics.zip', '.']) + os.chdir('../../') + +@app.route('/', methods=['GET', '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'] + 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] + + process_file(urls) + PATH = "downloads/musics.zip" + return send_file(PATH, as_attachment=True) + +@app.errorhandler(404) +def page_not_found(error): + return render_template('404.html'), 404 + + +if __name__ == '__main__': + app.run(host='0.0.0.0', debug=True, port=3000) \ No newline at end of file diff --git a/Docker/src/.old/static/css/style.css b/Docker/src/.old/static/css/style.css new file mode 100644 index 0000000..0e36080 --- /dev/null +++ b/Docker/src/.old/static/css/style.css @@ -0,0 +1,193 @@ + body { + margin: 0; + font-family: Arial, Helvetica, sans-serif; + background-color: #131313; + color: #ffffff; + } + + .container { + max-width: 900px; + margin: 0 auto; + padding: 20px; + box-sizing: border-box; + } + + .bordered { + border: 1px solid rgb(24,216,96); + border-radius: 5px; + padding: 20px; + margin-bottom: 20px; + } + + li { + font-weight: bold; + } + + a { + text-decoration-color: rgb(24,216,96); + color: rgb(24,216,96); + } + + + .form-group { + display: flex; + flex-direction: column; + margin-bottom: 20px; + } + + .form-group label { + font-weight: bold; + margin-bottom: 5px; + } + + .form-control { + background-color: #232323; + border: none; + border-radius: 5px; + padding: 10px; + color: #ffffff; + } + + /* .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; + } + + + + .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 + } + + .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 + } + + .btn:hover { + background-color: rgb(24,216,96); + color: whitesmoke + } + + h1 { + color: rgb(24,216,96); + } + + @media (max-width: 600px) { + body { + margin: 0; + font-family: Arial, Helvetica, sans-serif; + background-color: #131313; + color: #ffffff; + } + + .container { + max-width: 100%; + margin: 0; + padding: 10px; + box-sizing: border-box; + } + + .bordered { + border: 1px solid rgb(24,216,96); + border-radius: 5px; + padding: 10px; + margin-bottom: 10px; + } + + li { + font-weight: bold; + } + + a { + text-decoration-color: rgb(24,216,96); + color: rgb(24,216,96); + } + + .form-group { + display: flex; + flex-direction: column; + margin-bottom: 10px; + } + + .form-group label { + font-weight: bold; + margin-bottom: 5px; + } + + .form-control { + background-color: #232323; + border: none; + border-radius: 5px; + padding: 10px; + color: #ffffff; + } + + /* .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; + } + + .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 + } + + .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 + } + + .btn:hover { + background-color: rgb(24,216,96); + color: whitesmoke + } + + h1 { + color: rgb(24,216,96); + } +} + diff --git a/Docker/src/.old/templates/404.html b/Docker/src/.old/templates/404.html new file mode 100644 index 0000000..8382b12 --- /dev/null +++ b/Docker/src/.old/templates/404.html @@ -0,0 +1,15 @@ + + + + SpotDL Web + + + +
+

Error 404

+

Il semble que vous soyez perdu. Revenez à la page d'accueil

+ +
+ + + diff --git a/Docker/src/.old/templates/erreur.html b/Docker/src/.old/templates/erreur.html new file mode 100644 index 0000000..fee662d --- /dev/null +++ b/Docker/src/.old/templates/erreur.html @@ -0,0 +1,18 @@ + + + + SpotDL Web + + + +
+

SpotDL Web

+

Veuillez entrer au moins une URL !

+ + + {% if message %} +

{{ message }}

+ {% endif %} +
+ + diff --git a/Docker/src/.old/templates/index.html b/Docker/src/.old/templates/index.html new file mode 100644 index 0000000..4a98c25 --- /dev/null +++ b/Docker/src/.old/templates/index.html @@ -0,0 +1,56 @@ + + + + + + + SpotDL Web + + + +
+

SpotDL Web

+
+

+

Procédure

+
    +
  • Se rendre sur Spotify en cliquant ici
  • +
  • Chercher un Album ou une Playlist
  • +
  • Sur Ordinateur : A droite du coeur, cliquez sur ... puis Partager et Copier le lien vers (Album ou Playlist)
  • +
  • Sur Smartphone : Cliquez sur le logo de partage puis Copier le lien
  • +
+

+
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+ + +
+ + +
+ + + +') -# 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': + 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'] url2 = request.form['url2'] url3 = request.form['url3'] @@ -55,14 +27,35 @@ def download_file(): urls = [url1, url2, url3, url4, url5] - process_file(urls) - PATH = "downloads/musics.zip" - return send_file(PATH, as_attachment=True) + # Créer le dossier 'downloads' s'il n'existe pas + if not os.path.exists('downloads'): + os.makedirs('downloads') + + os.chdir('downloads') + os.system(f'rm -rf *') + + for url in urls: + if url: + if "album" in url: + 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) + + 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(host='0.0.0.0', debug=True, port=3000) \ No newline at end of file + app.run(debug=True, port=3000) diff --git a/Docker/src/static/js/script.js b/Docker/src/static/js/script.js new file mode 100644 index 0000000..c2d5ff0 --- /dev/null +++ b/Docker/src/static/js/script.js @@ -0,0 +1,6 @@ +function startDownload() { + document.getElementById('download-button').innerHTML = 'Téléchargement en cours...'; + } +function refreshPage() { + window.location.reload(); + } \ No newline at end of file diff --git a/Docker/src/templates/404.html b/Docker/src/templates/404.html index 8382b12..6a1a0cb 100644 --- a/Docker/src/templates/404.html +++ b/Docker/src/templates/404.html @@ -1,15 +1,14 @@ - - - - SpotDL Web - +{% extends 'layout.html' %} - -
-

Error 404

-

Il semble que vous soyez perdu. Revenez à la page d'accueil

- -
+{% block body %} - + +
+

Error 404

+

Il semble que vous soyez perdu. Revenez à la page d'accueil

+ +
+ + +{% endblock body %} \ No newline at end of file diff --git a/Docker/src/templates/erreur.html b/Docker/src/templates/erreur.html index fee662d..34d1246 100644 --- a/Docker/src/templates/erreur.html +++ b/Docker/src/templates/erreur.html @@ -1,18 +1,18 @@ - - - - SpotDL Web - +{% extends 'layout.html' %} - -
-

SpotDL Web

-

Veuillez entrer au moins une URL !

- +{% block body %} - {% if message %} -

{{ message }}

- {% endif %} -
+ +
+

SpotDL Web

+

Veuillez entrer au moins une URL !

+ - + {% if message %} +

{{ message }}

+ {% endif %} +
+ + + +{% endblock body %} \ No newline at end of file diff --git a/Docker/src/templates/index.html b/Docker/src/templates/index.html index 4a98c25..b3dd93d 100644 --- a/Docker/src/templates/index.html +++ b/Docker/src/templates/index.html @@ -1,13 +1,7 @@ - - - - - - - SpotDL Web - +{% extends 'layout.html' %} + +{% block body %} -

SpotDL Web

@@ -21,36 +15,25 @@

-
+
- +
- +
- +
- +
- +
- -
- - - - + + + + + + + SpotDL Web + + + + + {% block body %}{% endblock body %} + + + \ No newline at end of file diff --git a/Docker/src/templates/modele.html b/Docker/src/templates/modele.html new file mode 100644 index 0000000..7e84aa9 --- /dev/null +++ b/Docker/src/templates/modele.html @@ -0,0 +1,7 @@ +{% extends 'layout.html' %} + +{% block body %} + + + +{% endblock body %} \ No newline at end of file diff --git a/identifiants.json b/identifiants.json deleted file mode 100644 index c5e4fda..0000000 --- a/identifiants.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "guillaume": "password" - } \ No newline at end of file