Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
2924550be6 | |||
9b04348b32 |
28
app.py
28
app.py
@ -1,8 +1,6 @@
|
||||
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__)
|
||||
|
||||
@ -13,7 +11,7 @@ def process_file(urls):
|
||||
download_param_track = '{artist}/{album}/{artist} - {title}'
|
||||
|
||||
os.chdir('downloads')
|
||||
# os.system(f'rm -rf *')
|
||||
os.system(f'rm -rf *')
|
||||
|
||||
for url in urls:
|
||||
if url:
|
||||
@ -23,8 +21,7 @@ def process_file(urls):
|
||||
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', '.'])
|
||||
run(['zip', '-r', 'musics.zip', '.'])
|
||||
os.chdir('../')
|
||||
|
||||
|
||||
@ -32,31 +29,18 @@ def process_file(urls):
|
||||
def upload_form():
|
||||
return render_template('index.html')
|
||||
|
||||
# Fonctionne
|
||||
# @app.route('/download/<filename>')
|
||||
# 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']
|
||||
|
||||
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')
|
||||
|
||||
# Créer le dossier 'downloads' s'il n'existe pas
|
||||
@ -69,6 +53,10 @@ def download_file():
|
||||
# return send_file(path, as_attachment=True)
|
||||
return render_template('finish.html')
|
||||
|
||||
@app.route('/zip', methods=['GET', 'POST'])
|
||||
def zip():
|
||||
path = "downloads/musics.zip"
|
||||
return send_file(path, as_attachment=True)
|
||||
|
||||
@app.errorhandler(404)
|
||||
def page_not_found(error): # error est necessaire
|
||||
|
@ -5,7 +5,8 @@
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1 class="title"> SpotDL Web </h1>
|
||||
<h2> Téléchargement terminé </h2>
|
||||
<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 %}
|
||||
|
@ -38,7 +38,7 @@
|
||||
<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="submit" class="btn" id="download-button" onclick="startDownload()">Démarrer</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