diff --git a/app.py b/app.py
index 0db886a..21f1fcf 100644
--- a/app.py
+++ b/app.py
@@ -152,27 +152,43 @@ def download_video():
output_template = str(DOWNLOAD_DIR / f'%(title)s_{timestamp}.%(ext)s')
# Construction de la commande yt-dlp
- cmd = [
- 'yt-dlp',
- '-f', format_string,
- '--merge-output-format', output_container,
- '-o', output_template
- ]
-
- # Pour l'audio seulement, on peut aussi extraire l'audio
- if audio_only and output_container in ['mp3', 'm4a']:
- cmd.extend(['-x', '--audio-format', output_container.replace('m4a', 'aac')])
-
- # Ajout des arguments de post-processing pour l'audio
- postproc_added = False
- if audio_codec and audio_codec != 'copy' and not (audio_only and output_container in ['mp3', 'm4a']):
- postproc_args = f"-c:a {audio_codec}"
- if audio_bitrate:
- postproc_args += f" -b:a {audio_bitrate}"
- cmd.extend(['--postprocessor-args', f'ffmpeg:{postproc_args}'])
- postproc_added = True
- # Si copy est sélectionné, on ne réencode pas du tout
- # Le bitrate est ignoré car on ne peut pas changer le bitrate sans réencoder
+ cmd = ['yt-dlp', '-f', format_string, '-o', output_template]
+
+ # Pour l'audio seulement, utiliser -x pour extraction
+ if audio_only:
+ cmd.extend(['-x']) # Extraire l'audio
+
+ # Spécifier le format audio de sortie
+ if output_container == 'mp3':
+ cmd.extend(['--audio-format', 'mp3'])
+ elif output_container == 'm4a':
+ cmd.extend(['--audio-format', 'm4a'])
+ else:
+ cmd.extend(['--audio-format', 'best'])
+
+ # Gérer la qualité audio
+ if audio_codec == 'copy':
+ # En mode copy, utiliser la meilleure qualité (0)
+ cmd.extend(['--audio-quality', '0'])
+ else:
+ # Convertir le bitrate en format approprié pour --audio-quality
+ # --audio-quality accepte soit 0-10 (VBR) soit un bitrate spécifique comme "128K"
+ if audio_bitrate:
+ cmd.extend(['--audio-quality', audio_bitrate.upper()]) # Ex: "192K"
+ else:
+ cmd.extend(['--audio-quality', '0']) # Meilleure qualité par défaut
+ postproc_added = True
+ else:
+ # Mode vidéo + audio : utiliser merge-output-format
+ cmd.extend(['--merge-output-format', output_container])
+
+ # Ajout des arguments de post-processing pour l'audio
+ if audio_codec and audio_codec != 'copy':
+ postproc_args = f"-c:a {audio_codec}"
+ if audio_bitrate:
+ postproc_args += f" -b:a {audio_bitrate}"
+ cmd.extend(['--postprocessor-args', f'ffmpeg:{postproc_args}'])
+ postproc_added = True
# Ajout de l'URL à la fin
cmd.append(url)
@@ -190,7 +206,12 @@ def download_video():
}), 400
# Recherche du fichier téléchargé
- downloaded_files = list(DOWNLOAD_DIR.glob(f'*.{output_container}'))
+ if audio_only and output_container in ['mp3', 'm4a']:
+ # Chercher spécifiquement les fichiers audio
+ downloaded_files = list(DOWNLOAD_DIR.glob(f'*.{output_container}'))
+ else:
+ downloaded_files = list(DOWNLOAD_DIR.glob(f'*.{output_container}'))
+
if not downloaded_files:
downloaded_files = list(DOWNLOAD_DIR.glob('*'))
diff --git a/templates/index.html b/templates/index.html
index 4fe029f..ffa9cc6 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -377,6 +377,8 @@
const outputContainer = document.getElementById('outputContainer');
const outputContainerGroup = document.getElementById('outputContainerGroup');
const outputLabel = outputContainerGroup.querySelector('label');
+ const audioCodec = document.getElementById('audioCodec');
+ const audioCodecLabel = audioCodec.previousElementSibling;
if (audioOnly) {
// Griser le format vidéo
@@ -385,13 +387,23 @@
videoFormat.style.cursor = 'not-allowed';
videoLabel.style.opacity = '0.5';
- // Passer automatiquement à un format audio
- if (!['m4a', 'mp3'].includes(outputContainer.value)) {
- outputContainer.value = 'm4a';
- }
+ // Adapter le conteneur pour formats audio seulement
+ outputContainer.innerHTML = `
+
+
+
+
+
+
+ `;
+ outputLabel.innerHTML = 'Format Audio de sortie';
- // Griser aussi le conteneur (optionnel, mais on garde le choix)
- outputLabel.innerHTML = 'Format de sortie (Audio)';
+ // Le codec devient moins pertinent en mode audio-only (géré par --audio-format)
+ audioCodec.disabled = true;
+ audioCodec.style.opacity = '0.5';
+ audioCodec.style.cursor = 'not-allowed';
+ audioCodecLabel.style.opacity = '0.5';
+ audioCodecLabel.innerHTML = 'Codec Audio (géré par format)';
} else {
// Réactiver le format vidéo
videoFormat.disabled = false;
@@ -399,14 +411,24 @@
videoFormat.style.cursor = 'pointer';
videoLabel.style.opacity = '1';
- // Rétablir le label normal
+ // Rétablir les conteneurs vidéo
+ outputContainer.innerHTML = `
+
+
+
+ `;
outputLabel.innerHTML = 'Conteneur';
- // Si un format audio était sélectionné, revenir à mp4
- if (['m4a', 'mp3'].includes(outputContainer.value)) {
- outputContainer.value = 'mp4';
- }
+ // Réactiver le codec audio
+ audioCodec.disabled = false;
+ audioCodec.style.opacity = '1';
+ audioCodec.style.cursor = 'pointer';
+ audioCodecLabel.style.opacity = '1';
+ audioCodecLabel.innerHTML = 'Codec Audio';
}
+
+ // Toujours permettre le contrôle du bitrate
+ toggleBitrateInput();
}
function toggleBitrateInput() {