diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..361ae0f --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +downloads/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7db156e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,30 @@ +FROM alpine:latest +LABEL authors="Guillaume" +# set the working directory in the container +WORKDIR /app + +# copy the dependencies file to the working directory +COPY requirements.txt . + +# Update packages +RUN apk update + +# Install python3 et pip +RUN apk add python3 py3-pip + +# install dependencies +RUN pip install -r requirements.txt + +# install ffmpeg for SpotDL +RUN spotdl --download-ffmpeg + +# install zip +RUN apk update && apk add zip + +# copy the content of the local src directory to the working directory +COPY static . +COPY templates . +COPY app.py . + +# command to run on container start +CMD [ "python", "./app.py" ] diff --git a/app.py b/app.py index 66d2d84..bf603f1 100644 --- a/app.py +++ b/app.py @@ -1,15 +1,51 @@ -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): + download_param_album = '{artist}/{album}/{artist} - {title}' + download_param_playlist = '{playlist}/{artists}/{album} - {title} {artist}' + download_param_track = '{artist}/{album}/{artist} - {title}' + + 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]) + # os.system(f'zip -r musics.zip ./downloads') + # run(['zip', '-r', 'musics.zip', '.']) + os.chdir('../') + @app.route('/', methods=['GET', 'POST']) -def index(): - message = None +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'] @@ -17,79 +53,27 @@ def index(): url4 = request.form['url4'] url5 = request.form['url5'] + urls = [url1, url2, url3, url4, 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') - result = process_file(url1, url2, url3, url4, url5) - return render_template('download_complete.html') + # Créer le dossier 'downloads' s'il n'existe pas + if not os.path.exists('downloads'): + os.makedirs('downloads') -def process_file(url1, url2, url3, url4, url5): - path = os.path.expanduser('~/musics') - download_param_album = '{artist}/{album}/{artist} - {title}' - download_param_playlist = '{playlist}/{artists}/{album} - {title} {artist}' + process_file(urls) - # Télécharger chaque URL s'il n'est pas vide - if url1: - if "album" in url1: - os.chdir(f"{path}") - os.system(f'python3 -m spotdl {url1} --output "{download_param_album}"') - elif "playlist" in url1: - os.chdir(f"{path}") - os.system(f'python3 -m spotdl {url1} --output "{download_param_playlist}"') - - if url2: - if "album" in url2: - os.chdir(f"{path}") - os.system(f'python3 -m spotdl {url2} --output "{download_param_album}"') - elif "playlist" in url2: - os.chdir(f"{path}") - os.system(f'python3 -m spotdl {url2} --output "{download_param_playlist}"') - - if url3: - if "album" in url3: - os.chdir(f"{path}") - os.system(f'python3 -m spotdl {url3} --output "{download_param_album}"') - elif "playlist" in url3: - os.chdir(f"{path}") - os.system(f'python3 -m spotdl {url3} --output "{download_param_playlist}"') - - if url4: - if "album" in url4: - os.chdir(f"{path}") - os.system(f'python3 -m spotdl {url4} --output "{download_param_album}"') - elif "playlist" in url4: - os.chdir(f"{path}") - os.system(f'python3 -m spotdl {url4} --output "{download_param_playlist}"') - - if url5: - if "album" in url5: - os.chdir(f"{path}") - os.system(f'python3 -m spotdl {url5} --output "{download_param_album}"') - elif "playlist" in url5: - os.chdir(f"{path}") - os.system(f'python3 -m spotdl {url5} --output "{download_param_playlist}"') + # path = "downloads/musics.zip" + # return send_file(path, as_attachment=True) + return render_template('finish.html') -# def process_file(url): -# path = os.path.expanduser('~/musics') -# download_param_album = '{artist}/{album}/{artist} - {title}' -# download_param_playlist = '{playlist}/{artists}/{album} - {title} {artist}' +@app.errorhandler(404) +def page_not_found(error): # error est necessaire + return render_template('404.html'), 404 -# if "album" in url: -# #os.makedirs(f"{path}") -# os.chdir(f"{path}") -# print ("album found") -# os.system(f'python3 -m spotdl {url} --output "{download_param_album}"') -# elif "playlist" in url: -# os.chdir(f"{path}") -# print("playlist found") -# os.system(f'python3 -m spotdl {url} --output "{download_param_playlist}"') - - -# @app.route('/download/') -# def download_file(filename): -# return send_file(filename, attachment_filename=filename, as_attachment=True) if __name__ == '__main__': - app.run(debug=True, port=3000) + app.run(host='0.0.0.0', debug=True, port=3000) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..f68fb14 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +Flask==2.3.2 +spotdl==4.1.10 diff --git a/static/css/style.css b/static/css/style.css index 4e8fcd1..7ae446e 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -1,40 +1,100 @@ - body { - background-color: black; -} - -h1 { - /* border: 2px #eee solid; */ - color: rgb(24,216,96); - background-color: black; - text-align: center; - padding: 10px; -} - -h2 { - text-align: center; - margin: auto; - padding: 10px; - color: white; -} - -.url { - display: flex; - justify-content: center; - align-items: center; - /* min-height:100%; */ - background-color: black; - color: white -} - - -input[type="submit"] { - display: block; - margin: auto; -} - -button { - display: block; - margin: 10px auto; + 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; + } + + .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) { + .container { + padding: 10px; + } \ No newline at end of file diff --git a/static/js/script.js b/static/js/script.js new file mode 100644 index 0000000..c2d5ff0 --- /dev/null +++ b/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/templates/404.html b/templates/404.html new file mode 100644 index 0000000..3e0fddc --- /dev/null +++ b/templates/404.html @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + +{% extends 'layout.html' %} + +{% 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/templates/download_complete.html b/templates/download_complete.html deleted file mode 100644 index 8641e78..0000000 --- a/templates/download_complete.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - SpotDL Web - - -

SpotDL Web

-

Téléchargement Terminé

- - diff --git a/templates/erreur.html b/templates/erreur.html index f1ac2d1..95c346a 100644 --- a/templates/erreur.html +++ b/templates/erreur.html @@ -1,13 +1,37 @@ - - - - SpotDL Web - + + + + + -

SpotDL Web

-

Veuillez entrer au moins une URL !

- + + + + + -{% if message %} -

{{ message }}

-{% endif %} \ No newline at end of file + + + + + + + +{% extends 'layout.html' %} + +{% block body %} + + +
+

SpotDL Web

+

Veuillez entrer au moins une URL !

+ + + {% if message %} +

{{ message }}

+ {% endif %} +
+ + + +{% endblock body %} \ No newline at end of file diff --git a/templates/finish.html b/templates/finish.html new file mode 100644 index 0000000..986cf00 --- /dev/null +++ b/templates/finish.html @@ -0,0 +1,18 @@ +{% extends 'layout.html' %} + +{% block body %} + + +
+

SpotDL Web

+

Téléchargement terminé

+ + + {% if message %} +

{{ message }}

+ {% endif %} +
+ + + +{% endblock body %} \ No newline at end of file diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..6b5b51d --- /dev/null +++ b/templates/index.html @@ -0,0 +1,47 @@ + + + + + + + + SpotDL Web + + + +
+

SpotDL Web

+
+

+

Procédure

+
    +
  • Se rendre sur Spotify en cliquant ici
  • +
  • Chercher un Album ou une Playlist
  • +
  • Sur Ordinateur : À 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
  • +
+

+

+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+ + +
+
+ + + \ No newline at end of file diff --git a/templates/layout.html b/templates/layout.html new file mode 100644 index 0000000..ca69ddc --- /dev/null +++ b/templates/layout.html @@ -0,0 +1,16 @@ + + + + + + + + SpotDL Web + + + + + {% block body %}{% endblock body %} + + + \ No newline at end of file diff --git a/templates/modele.html b/templates/modele.html new file mode 100644 index 0000000..7e84aa9 --- /dev/null +++ b/templates/modele.html @@ -0,0 +1,7 @@ +{% extends 'layout.html' %} + +{% block body %} + + + +{% endblock body %} \ No newline at end of file diff --git a/templates/upload.html b/templates/upload.html deleted file mode 100644 index 307753a..0000000 --- a/templates/upload.html +++ /dev/null @@ -1,45 +0,0 @@ - - - - SpotDL Web - - -

SpotDL Web

-
-
- - -
- - -
- -
- - -
- -
- - -
- -
- - -
- -
- - -
- -
- -
- -
-
- -