Changes to be committed:
Some checks reported errors
continuous-integration/drone/push Build encountered an error
Some checks reported errors
continuous-integration/drone/push Build encountered an error
modified: .drone.yml modified: app.py new file: docker-compose.yaml modified: static/js/script.js new file: templates/finish_local.html renamed: templates/finish.html -> templates/finish_server.html modified: templates/index.html Il est maintenant possible de choisir entre télécharger sur le server ou en local.
This commit is contained in:
parent
0696c81a83
commit
74e936c0f8
39
.drone.yml
39
.drone.yml
@ -41,6 +41,7 @@ steps:
|
||||
commands:
|
||||
- curl -d "La pipeline a réussi" $NOTIFY_URL
|
||||
when:
|
||||
branch: main
|
||||
status: [ success ]
|
||||
|
||||
- name: notify_failure
|
||||
@ -51,4 +52,42 @@ steps:
|
||||
commands:
|
||||
- curl -d "La pipeline a échoué" $NOTIFY_URL
|
||||
when:
|
||||
branch: main
|
||||
status: [failure]
|
||||
|
||||
- name: docker_gitea
|
||||
image: plugins/docker
|
||||
settings:
|
||||
username:
|
||||
from_secret: docker_username
|
||||
password:
|
||||
from_secret: docker_password
|
||||
repo: git.netpowa.fr/guillaume/spotdlweb
|
||||
# auto_tag: true
|
||||
registry: git.netpowa.fr
|
||||
tags:
|
||||
- beta
|
||||
when:
|
||||
branch: dev
|
||||
|
||||
- name: notify_success
|
||||
image: curlimages/curl
|
||||
environment:
|
||||
NOTIFY_URL:
|
||||
from_secret: ntfy_url
|
||||
commands:
|
||||
- curl -d "La pipeline dev a réussi" $NOTIFY_URL
|
||||
when:
|
||||
branch: dev
|
||||
status: [ success ]
|
||||
|
||||
- name: notify_failure
|
||||
image: curlimages/curl
|
||||
environment:
|
||||
NOTIFY_URL:
|
||||
from_secret: ntfy_url
|
||||
commands:
|
||||
- curl -d "La pipeline dev a échoué" $NOTIFY_URL
|
||||
when:
|
||||
branch: dev
|
||||
status: [failure]
|
60
app.py
60
app.py
@ -28,6 +28,27 @@ def process_file(urls):
|
||||
os.chdir('../')
|
||||
|
||||
|
||||
def process_file_local(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('temp')
|
||||
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('../')
|
||||
|
||||
|
||||
@app.route('/', methods=['GET', 'POST'])
|
||||
def upload_form():
|
||||
return render_template('index.html')
|
||||
@ -41,34 +62,43 @@ def upload_form():
|
||||
|
||||
@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':
|
||||
action = request.form.get('action')
|
||||
url1 = request.form['url1']
|
||||
url2 = request.form['url2']
|
||||
url3 = request.form['url3']
|
||||
url4 = request.form['url4']
|
||||
url5 = request.form['url5']
|
||||
|
||||
urls = [url1, url2, url3, url4, url5]
|
||||
urls = [url1, url2, url3]
|
||||
|
||||
# Vérifier si au moins un champ est vide
|
||||
if not url1 and not url2 and not url3 and not url4 and not url5:
|
||||
if not url1 and not url2 and not url3 :
|
||||
return render_template('erreur.html')
|
||||
|
||||
if action == 'download':
|
||||
# Créer le dossier 'downloads' s'il n'existe pas
|
||||
if not os.path.exists('downloads'):
|
||||
os.makedirs('downloads')
|
||||
if not os.path.exists('downloads'):
|
||||
os.makedirs('downloads')
|
||||
|
||||
process_file(urls)
|
||||
process_file(urls)
|
||||
|
||||
# path = "downloads/musics.zip"
|
||||
# return send_file(path, as_attachment=True)
|
||||
return render_template('finish.html')
|
||||
# path = "downloads/musics.zip"
|
||||
# return send_file(path, as_attachment=True)
|
||||
return render_template('finish_server.html')
|
||||
|
||||
if action == 'downloadlocal':
|
||||
|
||||
# Créer le dossier 'downloads' s'il n'existe pas
|
||||
if not os.path.exists('temp'):
|
||||
os.makedirs('temp')
|
||||
|
||||
process_file_local(urls)
|
||||
|
||||
return render_template('finish_local.html')
|
||||
|
||||
@app.route('/zip', methods=['GET', 'POST'])
|
||||
def zip():
|
||||
path = "temp/musics.zip"
|
||||
return send_file(path, as_attachment=True)
|
||||
|
||||
@app.errorhandler(404)
|
||||
def page_not_found(error): # error est necessaire
|
||||
|
11
docker-compose.yaml
Normal file
11
docker-compose.yaml
Normal file
@ -0,0 +1,11 @@
|
||||
version: '3.3'
|
||||
services:
|
||||
spotdlweb:
|
||||
image: gu1llaum3/spotdlweb:latest
|
||||
container_name: spotdlweb
|
||||
hostname: spotdlweb
|
||||
ports:
|
||||
- 3000:3000
|
||||
volumes:
|
||||
- ./musics:/app/downloads
|
||||
restart: unless-stopped
|
@ -1,6 +1,9 @@
|
||||
function startDownload() {
|
||||
document.getElementById('download-button').innerHTML = 'Téléchargement en cours...';
|
||||
}
|
||||
function startLocalDownload() {
|
||||
document.getElementById('downloadlocal-button').innerHTML = 'Téléchargement en cours...';
|
||||
}
|
||||
function refreshPage() {
|
||||
window.location.reload();
|
||||
}
|
19
templates/finish_local.html
Normal file
19
templates/finish_local.html
Normal file
@ -0,0 +1,19 @@
|
||||
{% extends 'layout.html' %}
|
||||
|
||||
{% block body %}
|
||||
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1 class="title"> SpotDL Web </h1>
|
||||
<h2>Votre musique est prête à être téléchargée</h2>
|
||||
<button class="btn" onclick="window.location.href = '/zip';">Télécharger</button>
|
||||
<button class="btn" onclick="window.location.href = '/';">Accueil</button>
|
||||
|
||||
{% if message %}
|
||||
<p>{{ message }}</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
||||
{% endblock body %}
|
@ -38,8 +38,9 @@
|
||||
<div class="form-group">
|
||||
<input type="text" class="form-control" name="url5" id="url5" pattern="^https://open\.spotify\.com/(?:album|playlist|track)/[\w-]+(?:\?si=[\w-]+)?$" placeholder="Entrez l'URL d'une Piste, d'un Album ou d'une Playlist">
|
||||
</div> -->
|
||||
<button type="submit" class="btn" id="download-button" onclick="startDownload()">Télécharger</button>
|
||||
<button type="reset" class="btn" id="refresh-button" onclick="refreshPage()">Rafraîchir</button>
|
||||
<button type="submit" class="btn" id="download-button" onclick="startDownload()" name="action" value="download">Télécharger sur le serveur</button>
|
||||
<button type="submit" class="btn" id="downloadlocal-button" onclick="startLocalDownload()" name="action" value="downloadlocal">Télécharger en local</button>
|
||||
<!-- <button type="reset" class="btn" id="refresh-button" onclick="refreshPage()">Rafraîchir</button> -->
|
||||
</form>
|
||||
</div>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user