Ajout page erreur si toutes les url vident, création du fichier css pour habiller la page.
This commit is contained in:
parent
98f2a46afb
commit
61c61d203b
BIN
__pycache__/app.cpython-310.pyc
Normal file
BIN
__pycache__/app.cpython-310.pyc
Normal file
Binary file not shown.
95
app.py
95
app.py
@ -1,43 +1,90 @@
|
|||||||
from flask import Flask, request, redirect, url_for, send_file
|
from flask import Flask, request, redirect, url_for, send_file, render_template
|
||||||
import os
|
import os
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def upload_form():
|
def upload_form():
|
||||||
return '''
|
return render_template('upload.html')
|
||||||
<form method="POST">
|
|
||||||
<label for="url">URL:</label>
|
|
||||||
<input type="text" name="url" id="url">
|
|
||||||
<input type="submit" value="Téléchargement">
|
|
||||||
</form>
|
|
||||||
'''
|
|
||||||
|
|
||||||
@app.route('/', methods=['GET', 'POST'])
|
@app.route('/', methods=['GET', 'POST'])
|
||||||
def index():
|
def index():
|
||||||
message = None
|
message = None
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
url = request.form['url']
|
url1 = request.form['url1']
|
||||||
result = process_file(url)
|
url2 = request.form['url2']
|
||||||
return '''
|
url3 = request.form['url3']
|
||||||
<h1> Téléchargement terminé </h1>
|
url4 = request.form['url4']
|
||||||
<button onclick="window.location.href = '/';">Télécharger à nouveau</button>
|
url5 = request.form['url5']
|
||||||
'''
|
|
||||||
|
|
||||||
def process_file(url):
|
# 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')
|
||||||
|
|
||||||
|
def process_file(url1, url2, url3, url4, url5):
|
||||||
path = os.path.expanduser('~/musics')
|
path = os.path.expanduser('~/musics')
|
||||||
download_param_album = '{artist}/{album}/{artist} - {title}'
|
download_param_album = '{artist}/{album}/{artist} - {title}'
|
||||||
download_param_playlist = '{playlist}/{artists}/{album} - {title} {artist}'
|
download_param_playlist = '{playlist}/{artists}/{album} - {title} {artist}'
|
||||||
|
|
||||||
if "album" in url:
|
# Télécharger chaque URL s'il n'est pas vide
|
||||||
#os.makedirs(f"{path}")
|
if url1:
|
||||||
os.chdir(f"{path}")
|
if "album" in url1:
|
||||||
print ("album found")
|
os.chdir(f"{path}")
|
||||||
os.system(f'python3 -m spotdl {url} --output "{download_param_album}"')
|
os.system(f'python3 -m spotdl {url1} --output "{download_param_album}"')
|
||||||
elif "playlist" in url:
|
elif "playlist" in url1:
|
||||||
os.chdir(f"{path}")
|
os.chdir(f"{path}")
|
||||||
print("playlist found")
|
os.system(f'python3 -m spotdl {url1} --output "{download_param_playlist}"')
|
||||||
os.system(f'python3 -m spotdl {url} --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}"')
|
||||||
|
|
||||||
|
|
||||||
|
# def process_file(url):
|
||||||
|
# path = os.path.expanduser('~/musics')
|
||||||
|
# download_param_album = '{artist}/{album}/{artist} - {title}'
|
||||||
|
# download_param_playlist = '{playlist}/{artists}/{album} - {title} {artist}'
|
||||||
|
|
||||||
|
# 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/<path:filename>')
|
# @app.route('/download/<path:filename>')
|
||||||
|
40
static/css/style.css
Normal file
40
static/css/style.css
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
10
templates/download_complete.html
Normal file
10
templates/download_complete.html
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<link rel="stylesheet" href="{{ url_for('static', filename= 'css/style.css') }}">
|
||||||
|
<title>SpotDL Web</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1> SpotDL Web </h1>
|
||||||
|
<h2> Téléchargement Terminé </h2>
|
||||||
|
<button onclick="window.location.href = '/';">Télécharger à nouveau</button>
|
||||||
|
</body>
|
13
templates/erreur.html
Normal file
13
templates/erreur.html
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<link rel="stylesheet" href="{{ url_for('static', filename= 'css/style.css') }}">
|
||||||
|
<title>SpotDL Web</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<h1> SpotDL Web </h1>
|
||||||
|
<h2> Veuillez entrer au moins une URL ! </h2>
|
||||||
|
<button onclick="window.location.href = '/';">Télécharger à nouveau</button>
|
||||||
|
|
||||||
|
{% if message %}
|
||||||
|
<p>{{ message }}</p>
|
||||||
|
{% endif %}
|
@ -1,9 +0,0 @@
|
|||||||
<form method="POST">
|
|
||||||
<label for="url">URL:</label>
|
|
||||||
<input type="text" name="url" id="url">
|
|
||||||
<input type="submit" value="Téléchargement">
|
|
||||||
</form>
|
|
||||||
|
|
||||||
{% if message %}
|
|
||||||
<p>{{ message }}</p>
|
|
||||||
{% endif %}
|
|
45
templates/upload.html
Normal file
45
templates/upload.html
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<link rel="stylesheet" href="{{ url_for('static', filename= 'css/style.css') }}">
|
||||||
|
<title>SpotDL Web</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<h1>SpotDL Web</h1>
|
||||||
|
<div class="url">
|
||||||
|
<form method="POST">
|
||||||
|
<!-- <label for="url">URL:</label>
|
||||||
|
<input type="text" name="url" id="url"> -->
|
||||||
|
|
||||||
|
<div style="margin-top: 10px;">
|
||||||
|
<label for="url1">URL 1:</label>
|
||||||
|
<input type="text" name="url1" id="url1">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="margin-top: 10px;">
|
||||||
|
<label for="url2">URL 2:</label>
|
||||||
|
<input type="text" name="url2" id="url2">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="margin-top: 10px;">
|
||||||
|
<label for="url3">URL 3:</label>
|
||||||
|
<input type="text" name="url3" id="url3">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="margin-top: 10px;">
|
||||||
|
<label for="url4">URL 4:</label>
|
||||||
|
<input type="text" name="url4" id="url4">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="margin-top: 10px;">
|
||||||
|
<label for="url5">URL 5:</label>
|
||||||
|
<input type="text" name="url5" id="url5">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="margin-top: 10px;">
|
||||||
|
<input type="submit" value="Téléchargement">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user