1.2.0.0
This commit is contained in:
parent
384a10c1be
commit
e571e2e003
184
app.py
184
app.py
@ -1,129 +1,145 @@
|
|||||||
from flask import Flask, render_template, request, Response, redirect, url_for, send_file
|
|
||||||
from flask_login import LoginManager, UserMixin, login_user, login_required, logout_user, current_user
|
|
||||||
import subprocess
|
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import zipfile
|
import subprocess
|
||||||
from io import BytesIO
|
from flask import Flask, render_template, request, redirect, url_for, flash, Reponse
|
||||||
|
from flask_login import LoginManager, UserMixin, login_user, logout_user, login_required, current_user
|
||||||
|
import sys
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.secret_key = 'your_secret_key'
|
app.secret_key = 'votre_cle_secrete' # Clé secrète pour Flask
|
||||||
|
|
||||||
# Configuration Flask-Login
|
# Gestion de l'authentification
|
||||||
login_manager = LoginManager()
|
login_manager = LoginManager()
|
||||||
login_manager.init_app(app)
|
login_manager.init_app(app)
|
||||||
login_manager.login_view = 'login'
|
login_manager.login_view = 'login' # Rediriger ici si non connecté
|
||||||
|
|
||||||
# Utilisateur fictif
|
# Simuler une base de données utilisateur
|
||||||
|
USERS = {
|
||||||
|
"admin": {"password": "password123"}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Classe utilisateur
|
||||||
class User(UserMixin):
|
class User(UserMixin):
|
||||||
def __init__(self, id):
|
def __init__(self, username):
|
||||||
self.id = id
|
self.id = username
|
||||||
|
|
||||||
# Stockage simple d'utilisateurs (en production, utiliser une base de données)
|
|
||||||
users = {'garfi': {'admin': 'password123'}}
|
|
||||||
|
|
||||||
@login_manager.user_loader
|
@login_manager.user_loader
|
||||||
def load_user(user_id):
|
def load_user(user_id):
|
||||||
|
if user_id in USERS:
|
||||||
return User(user_id)
|
return User(user_id)
|
||||||
|
return None
|
||||||
|
|
||||||
|
@app.route('/')
|
||||||
|
@login_required
|
||||||
|
def index():
|
||||||
|
return render_template('index.html')
|
||||||
|
|
||||||
@app.route('/login', methods=['GET', 'POST'])
|
@app.route('/login', methods=['GET', 'POST'])
|
||||||
def login():
|
def login():
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
username = request.form['username']
|
username = request.form['username']
|
||||||
password = request.form['password']
|
password = request.form['password']
|
||||||
if username in users and users[username]['password'] == password:
|
|
||||||
|
if username in USERS and USERS[username]['password'] == password:
|
||||||
user = User(username)
|
user = User(username)
|
||||||
login_user(user)
|
login_user(user)
|
||||||
return redirect(url_for('index'))
|
flash('Connexion réussie', 'success')
|
||||||
|
return redirect(url_for('index')) # Redirection vers la page d'accueil
|
||||||
else:
|
else:
|
||||||
return "Nom d'utilisateur ou mot de passe incorrect", 401
|
flash('Nom d\'utilisateur ou mot de passe incorrect', 'danger')
|
||||||
|
return redirect(url_for('login'))
|
||||||
|
|
||||||
return render_template('login.html')
|
return render_template('login.html')
|
||||||
|
|
||||||
@app.route('/logout')
|
@app.route('/logout')
|
||||||
@login_required
|
@login_required
|
||||||
def logout():
|
def logout():
|
||||||
logout_user()
|
logout_user()
|
||||||
|
flash('Vous êtes déconnecté', 'info')
|
||||||
return redirect(url_for('login'))
|
return redirect(url_for('login'))
|
||||||
|
|
||||||
@app.route('/')
|
# Fonction pour exécuter une commande en temps réel
|
||||||
@login_required
|
def run_command_live(command, cwd=None):
|
||||||
def index():
|
process = subprocess.Popen(['stdbuf', '-oL'] + command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, cwd=cwd, bufsize=1)
|
||||||
return render_template('stream.html')
|
|
||||||
|
|
||||||
|
for stdout_line in iter(process.stdout.readline, ""):
|
||||||
|
yield stdout_line
|
||||||
|
sys.stdout.flush()
|
||||||
|
process.stdout.close()
|
||||||
|
process.wait()
|
||||||
|
|
||||||
|
# Fonction pour copier les fichiers individuellement
|
||||||
|
def copy_files(source, destination):
|
||||||
|
try:
|
||||||
|
if os.path.exists(source):
|
||||||
|
if len(os.listdir(source)) > 0: # Vérifier si le répertoire contient des fichiers
|
||||||
|
for root, dirs, files in os.walk(source):
|
||||||
|
for file in files:
|
||||||
|
file_source = os.path.join(root, file)
|
||||||
|
file_destination = os.path.join(destination, os.path.relpath(file_source, source))
|
||||||
|
os.makedirs(os.path.dirname(file_destination), exist_ok=True)
|
||||||
|
shutil.copy2(file_source, file_destination)
|
||||||
|
return f"Fichiers copiés vers {destination}\n"
|
||||||
|
else:
|
||||||
|
return f"Le répertoire source ({source}) est vide. Aucune copie effectuée.\n"
|
||||||
|
else:
|
||||||
|
return f"Le répertoire source ({source}) n'existe pas. Aucune copie effectuée.\n"
|
||||||
|
except Exception as e:
|
||||||
|
return f"Erreur lors de la copie : {str(e)}\n"
|
||||||
|
|
||||||
|
# Fonction pour gérer le téléchargement d'une seule URL
|
||||||
@app.route('/download', methods=['POST'])
|
@app.route('/download', methods=['POST'])
|
||||||
@login_required
|
@login_required
|
||||||
def download():
|
def download():
|
||||||
url = request.form['url']
|
url = request.form.get('url') # Récupérer une seule URL
|
||||||
format_choice = request.form['format']
|
format_choice = request.form.get('format', 'mp3') # Par défaut à 'mp3'
|
||||||
delete_choice = request.form['delete_choice']
|
delete_old = request.form.get('delete_old', False)
|
||||||
copy_choice = request.form['copy_choice'] # Nouvelle option pour copier ou non
|
copy_choice = request.form.get('copy_choice', 'no')
|
||||||
|
|
||||||
def generate_output():
|
if not url:
|
||||||
# Répertoires pour le téléchargement en fonction du format choisi
|
return "Aucune URL n'a été soumise.", 400 # Gérer le cas où aucune URL n'est soumise
|
||||||
output_dir = "/home/garfi/Musique/flac" if format_choice == "flac" else "/home/garfi/Musique/mp3"
|
|
||||||
|
|
||||||
# Si l'utilisateur a choisi de supprimer les anciens répertoires
|
# Déterminer le répertoire de téléchargement en fonction du format
|
||||||
if delete_choice == "1":
|
if format_choice == 'flac':
|
||||||
yield "Suppression des anciens répertoires...\n"
|
download_dir = "/home/jules/Musique/flac"
|
||||||
try:
|
format_type = 'flac'
|
||||||
if os.path.exists("/home/garfi/Musique/flac"):
|
|
||||||
shutil.rmtree("/home/garfi/Musique/flac")
|
|
||||||
yield "Le répertoire /home/garfi/Musique/flac a été supprimé.\n"
|
|
||||||
|
|
||||||
if os.path.exists("/home/garfi/Musique/mp3"):
|
|
||||||
shutil.rmtree("/home/garfi/Musique/mp3")
|
|
||||||
yield "Le répertoire /home/garfi/Musique/mp3 a été supprimé.\n"
|
|
||||||
except FileNotFoundError as e:
|
|
||||||
yield f"Erreur : {str(e)} - Le répertoire n'existe pas.\n"
|
|
||||||
except Exception as e:
|
|
||||||
yield f"Erreur inattendue lors de la suppression : {str(e)}\n"
|
|
||||||
|
|
||||||
# Créer le répertoire pour stocker les nouveaux fichiers
|
|
||||||
os.makedirs(output_dir, exist_ok=True)
|
|
||||||
|
|
||||||
# Lancer le téléchargement avec spotdl
|
|
||||||
command = f'spotdl --output "{{artist}}/{{album}}/{{track-number}} - {{title}}.{{output-ext}}" "{url}" --format={format_choice}'
|
|
||||||
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, cwd=output_dir)
|
|
||||||
|
|
||||||
for line in process.stdout:
|
|
||||||
yield line # Envoyer les lignes de la commande en temps réel
|
|
||||||
|
|
||||||
process.wait()
|
|
||||||
if process.returncode == 0:
|
|
||||||
yield "\nTéléchargement terminé avec succès.\n"
|
|
||||||
|
|
||||||
|
|
||||||
# Si l'utilisateur a choisi de copier vers /mnt/data/Musique/
|
|
||||||
if copy_choice == "1":
|
|
||||||
share_dir = "/mnt/data/Musique/"
|
|
||||||
try:
|
|
||||||
shutil.copytree(output_dir, share_dir, dirs_exist_ok=True)
|
|
||||||
yield f"\nLes fichiers ont été copiés vers {share_dir}.\n"
|
|
||||||
except Exception as e:
|
|
||||||
yield f"\nErreur lors de la copie des fichiers vers {share_dir} : {str(e)}\n"
|
|
||||||
else:
|
else:
|
||||||
yield f"\nUne erreur est survenue avec le code {process.returncode}.\n"
|
download_dir = "/home/jules/Musique/mp3"
|
||||||
|
format_type = 'mp3'
|
||||||
|
|
||||||
return Response(generate_output(), mimetype='text/plain')
|
# Supprimer les anciens répertoires si l'utilisateur a choisi
|
||||||
|
if delete_old:
|
||||||
|
if os.path.exists(download_dir):
|
||||||
|
shutil.rmtree(download_dir)
|
||||||
|
|
||||||
@app.route('/download_zip')
|
# Créer le répertoire de téléchargement s'il n'existe pas
|
||||||
@login_required
|
os.makedirs(download_dir, exist_ok=True)
|
||||||
def download_zip():
|
|
||||||
format_choice = request.args.get('format')
|
|
||||||
output_dir = "/home/garfi/Musique/flac" if format_choice == "flac" else "/home/garfi/Musique/mp3"
|
|
||||||
|
|
||||||
# Créer un fichier ZIP dans la mémoire
|
# Commande pour télécharger la musique avec spotdl dans le répertoire correct
|
||||||
memory_file = BytesIO()
|
spotdl_command = [
|
||||||
with zipfile.ZipFile(memory_file, 'w', zipfile.ZIP_DEFLATED) as zf:
|
'spotdl',
|
||||||
for root, dirs, files in os.walk(output_dir):
|
'--output', '{artist}/{album}/{track-number} - {title}.{output-ext}',
|
||||||
for file in files:
|
'--format', format_type,
|
||||||
file_path = os.path.join(root, file)
|
url
|
||||||
zf.write(file_path, arcname=os.path.relpath(file_path, output_dir))
|
]
|
||||||
|
|
||||||
memory_file.seek(0)
|
def stream():
|
||||||
|
yield f"Téléchargement en cours dans {download_dir}...\n"
|
||||||
|
for output in run_command_live(spotdl_command, cwd=download_dir):
|
||||||
|
yield output
|
||||||
|
|
||||||
# Télécharger le fichier ZIP
|
# Exécuter sacad_r pour ajouter les couvertures
|
||||||
return send_file(memory_file, mimetype='application/zip', as_attachment=True, download_name=f'musique_{format_choice}.zip')
|
sacad_command = ['sacad_r', download_dir, '900', 'cover.jpg']
|
||||||
|
yield "Ajout des couvertures...\n"
|
||||||
|
for output in run_command_live(sacad_command):
|
||||||
|
yield output
|
||||||
|
|
||||||
|
# Copier les fichiers vers /mnt/data/Musique si l'utilisateur a choisi "Oui"
|
||||||
|
if copy_choice == 'yes':
|
||||||
|
yield f"Copie des fichiers depuis {download_dir} vers /mnt/data/Musique...\n"
|
||||||
|
yield copy_files(download_dir, "/mnt/data/Musique")
|
||||||
|
|
||||||
|
return Response(stream(), mimetype='text/plain')
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(debug=True)
|
app.run(debug=True)
|
||||||
|
BIN
static/images/spotify_pirate.png
Normal file
BIN
static/images/spotify_pirate.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 261 KiB |
116
templates/index.html
Normal file
116
templates/index.html
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Downloader spotify</title>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
background-color: #121212;
|
||||||
|
color: white;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
.container {
|
||||||
|
margin-top: 50px;
|
||||||
|
}
|
||||||
|
.form-label {
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
.output-box {
|
||||||
|
background-color: #333;
|
||||||
|
padding: 20px;
|
||||||
|
border-radius: 8px;
|
||||||
|
white-space: pre-wrap;
|
||||||
|
color: lightgreen;
|
||||||
|
height: 500px;
|
||||||
|
overflow-y: auto;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
.spotify-icon {
|
||||||
|
position: absolute;
|
||||||
|
top: 10px;
|
||||||
|
right: 10px;
|
||||||
|
width: 150px;
|
||||||
|
height: 150px;
|
||||||
|
}
|
||||||
|
.d-flex {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
/* Ajuster la taille de la liste déroulante */
|
||||||
|
.format-select {
|
||||||
|
width: auto;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<!-- Ajouter l'icône Spotify pirate -->
|
||||||
|
<img src="{{ url_for('static', filename='images/spotify_pirate.png') }}" alt="Spotify Pirate Icon" class="spotify-icon">
|
||||||
|
|
||||||
|
<div class="container text-center">
|
||||||
|
<h1>Downloader spotify</h1>
|
||||||
|
<form id="downloadForm" action="/download" method="POST">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="url" class="form-label">URL Spotify</label>
|
||||||
|
<input type="text" class="form-control" id="url" name="url" placeholder="Entrez une URL Spotify" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3 d-flex">
|
||||||
|
<label for="format" class="form-label">Choisissez le format</label>
|
||||||
|
<select class="form-select format-select" id="format" name="format" required>
|
||||||
|
<option value="flac">FLAC</option>
|
||||||
|
<option value="mp3">MP3</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3 d-flex">
|
||||||
|
<input type="checkbox" class="form-check-input me-2" id="delete_old" name="delete_old">
|
||||||
|
<label class="form-check-label me-3" for="delete_old">Supprimer les anciens fichiers</label>
|
||||||
|
<button type="submit" class="btn btn-primary ms-auto">Télécharger</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="copy_choice" class="form-label">Copier vers /mnt/data/Musique ?</label><br>
|
||||||
|
<input type="radio" id="copy_yes" name="copy_choice" value="yes" required>
|
||||||
|
<label for="copy_yes">Oui</label>
|
||||||
|
<input type="radio" id="copy_no" name="copy_choice" value="no" required>
|
||||||
|
<label for="copy_no">Non</label>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<div id="output" class="output-box mt-3"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
$(document).ready(function() {
|
||||||
|
$('#downloadForm').submit(function(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
$('#output').empty(); // Clear previous output
|
||||||
|
|
||||||
|
var form = $(this);
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
xhr.open("POST", form.attr('action'), true);
|
||||||
|
|
||||||
|
var seenLines = new Set(); // Stocker les lignes déjà vues
|
||||||
|
|
||||||
|
xhr.onreadystatechange = function() {
|
||||||
|
if (xhr.readyState == 3 || xhr.readyState == 4) { // Partial or complete data received
|
||||||
|
var newOutput = xhr.responseText.split("\n"); // Diviser les lignes de l'output
|
||||||
|
newOutput.forEach(function(line) {
|
||||||
|
if (!seenLines.has(line) && line.trim() !== "") { // Vérifier si la ligne est nouvelle
|
||||||
|
seenLines.add(line); // Marquer la ligne comme vue
|
||||||
|
$('#output').append(line + "\n"); // Ajouter la nouvelle ligne
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$('#output').scrollTop($('#output')[0].scrollHeight); // Scroll to the bottom
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||||
|
xhr.send(form.serialize());
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -1,21 +1,27 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="fr">
|
<html lang="en">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Connexion</title>
|
<title>Login</title>
|
||||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
background-color: #121212;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
.container {
|
||||||
|
margin-top: 50px;
|
||||||
|
}
|
||||||
|
.form-label {
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="row justify-content-center">
|
<h1 class="text-center">Connexion</h1>
|
||||||
<div class="col-md-6">
|
<form action="/login" method="POST">
|
||||||
<div class="card mt-5">
|
|
||||||
<div class="card-body">
|
|
||||||
<h3 class="card-title text-center">Connexion</h3>
|
|
||||||
<form method="POST">
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="username" class="form-label">Nom d'utilisateur</label>
|
<label for="username" class="form-label">Nom d'utilisateur</label>
|
||||||
<input type="text" class="form-control" id="username" name="username" required>
|
<input type="text" class="form-control" id="username" name="username" required>
|
||||||
@ -24,13 +30,8 @@
|
|||||||
<label for="password" class="form-label">Mot de passe</label>
|
<label for="password" class="form-label">Mot de passe</label>
|
||||||
<input type="password" class="form-control" id="password" name="password" required>
|
<input type="password" class="form-control" id="password" name="password" required>
|
||||||
</div>
|
</div>
|
||||||
<button type="submit" class="btn btn-primary w-100">Se connecter</button>
|
<button type="submit" class="btn btn-primary">Se connecter</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
34
templates/result.html
Normal file
34
templates/result.html
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Résultats</title>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
background-color: #121212;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
.container {
|
||||||
|
margin-top: 50px;
|
||||||
|
}
|
||||||
|
.output-box {
|
||||||
|
background-color: #333;
|
||||||
|
padding: 20px;
|
||||||
|
border-radius: 8px;
|
||||||
|
white-space: pre-wrap;
|
||||||
|
color: lightgreen;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<h1 class="text-center">Résultats des commandes</h1>
|
||||||
|
<div class="output-box">
|
||||||
|
{{ output }}
|
||||||
|
</div>
|
||||||
|
<a href="{{ zip_url }}" class="btn btn-primary mt-3">Télécharger les fichiers en ZIP</a>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -1,105 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="fr">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
||||||
<title>Téléchargement en temps réel</title>
|
|
||||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
||||||
<style>
|
|
||||||
body { background-color: #f8f9fa; }
|
|
||||||
.container { margin-top: 50px; }
|
|
||||||
.card { border-radius: 10px; }
|
|
||||||
.output-container {
|
|
||||||
background-color: #f1f1f1;
|
|
||||||
padding: 20px;
|
|
||||||
border-radius: 10px;
|
|
||||||
white-space: pre-wrap;
|
|
||||||
font-family: monospace;
|
|
||||||
height: 400px;
|
|
||||||
overflow-y: scroll;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="container">
|
|
||||||
<div class="row justify-content-center">
|
|
||||||
<div class="col-md-8">
|
|
||||||
<div class="card shadow-lg p-3 mb-5 bg-white rounded">
|
|
||||||
<div class="card-body">
|
|
||||||
<h2 class="text-center mb-4">Télécharger Musique Spotify</h2>
|
|
||||||
<form id="download-form">
|
|
||||||
<div class="mb-3">
|
|
||||||
<label for="url" class="form-label">Saisir l'URL Spotify :</label>
|
|
||||||
<input type="text" class="form-control" id="url" name="url" required>
|
|
||||||
</div>
|
|
||||||
<div class="mb-3">
|
|
||||||
<label for="format" class="form-label">Choisissez le format :</label>
|
|
||||||
<select class="form-select" id="format" name="format" required>
|
|
||||||
<option value="flac">FLAC</option>
|
|
||||||
<option value="mp3">MP3</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<div class="mb-3">
|
|
||||||
<label for="delete_choice" class="form-label">Supprimer les anciens répertoires :</label>
|
|
||||||
<select class="form-select" id="delete_choice" name="delete_choice" required>
|
|
||||||
<option value="1">Oui</option>
|
|
||||||
<option value="2">Non</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<div class="mb-3">
|
|
||||||
<label for="copy_choice" class="form-label">Copier vers /mnt/data/Musique/ :</label>
|
|
||||||
<select class="form-select" id="copy_choice" name="copy_choice" required>
|
|
||||||
<option value="1">Oui</option>
|
|
||||||
<option value="2">Non</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<button type="submit" class="btn btn-primary w-100">Lancer le téléchargement</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="card mt-4">
|
|
||||||
<div class="card-body">
|
|
||||||
<h4>Output :</h4>
|
|
||||||
<div id="output" class="output-container"></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<!-- Button to download the ZIP -->
|
|
||||||
<button class="btn btn-secondary w-100 mt-3" onclick="window.location.href='/download_zip?format=' + document.getElementById('format').value">Télécharger ZIP</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<script>
|
|
||||||
document.getElementById('download-form').addEventListener('submit', function (event) {
|
|
||||||
event.preventDefault();
|
|
||||||
const url = document.getElementById('url').value;
|
|
||||||
const format = document.getElementById('format').value;
|
|
||||||
const delete_choice = document.getElementById('delete_choice').value;
|
|
||||||
const copy_choice = document.getElementById('copy_choice').value;
|
|
||||||
const formData = new URLSearchParams();
|
|
||||||
formData.append('url', url);
|
|
||||||
formData.append('format', format);
|
|
||||||
formData.append('delete_choice', delete_choice);
|
|
||||||
formData.append('copy_choice', copy_choice);
|
|
||||||
fetch('/download', {
|
|
||||||
method: 'POST',
|
|
||||||
body: formData
|
|
||||||
})
|
|
||||||
.then(response => {
|
|
||||||
const outputContainer = document.getElementById('output');
|
|
||||||
const reader = response.body.getReader();
|
|
||||||
const decoder = new TextDecoder();
|
|
||||||
function read() {
|
|
||||||
reader.read().then(({ done, value }) => {
|
|
||||||
if (done) return;
|
|
||||||
outputContainer.textContent += decoder.decode(value, { stream: true });
|
|
||||||
outputContainer.scrollTop = outputContainer.scrollHeight;
|
|
||||||
read();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
read();
|
|
||||||
})
|
|
||||||
.catch(error => console.error('Erreur:', error));
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
Loading…
Reference in New Issue
Block a user