Skip to content

Instantly share code, notes, and snippets.

@eric-pommereau
Last active October 20, 2025 15:48
Show Gist options
  • Select an option

  • Save eric-pommereau/b15154ca9da5cd26d8beab7179fc9418 to your computer and use it in GitHub Desktop.

Select an option

Save eric-pommereau/b15154ca9da5cd26d8beab7179fc9418 to your computer and use it in GitHub Desktop.
YT-dlp, DL d'une liste de podcasts
#!/bin/bash
# Télécharger les podcasts sur le site de radio france (FORMAT_FILE=0)
# Nom des fichiers
CHEMIN_SORTIE="../tests/podcasts/les-odyssees"
OUTPUT_TEMPLATE="${CHEMIN_SORTIE}/%(title)s.%(ext)s"
FICHIER_TODO="${CHEMIN_SORTIE}/urls.todo.txt"
FICHIER_DONE="${CHEMIN_SORTIE}/urls.done.txt"
FORMAT_FILE=0
# Vérifie si le fichier de liens à traiter existe
if [[ ! -f "$FICHIER_TODO" ]]; then
echo "Erreur : Le fichier $FICHIER_TODO n'existe pas."
exit 1
fi
echo "--- Démarrage du téléchargement des URLs (Zsh/Bash) ---"
echo "Les URLs terminées seront ajoutées à $FICHIER_DONE"
echo "--------------------------------------------------------"
# Lecture du fichier ligne par ligne
while IFS= read -r url
do
# Nettoyage : suppression des espaces et des lignes de commentaires
url=$(echo "$url" | xargs)
if [[ -z "$url" ]] || [[ "$url" =~ ^\# ]]; then
continue
fi
echo "-> Traitement de l'URL : $url"
# Commande yt-dlp pour télécharger l'audio
# -f "ba" : meilleur débit binaire audio
# --extract-audio : extrait la piste audio
# --audio-format mp3 : convertit en MP3 (nécessite ffmpeg)
# --embed-metadata : intègre le titre, etc.
# --ignore-errors : permet au script de continuer en cas d'échec
yt-dlp -f 0 --extract-audio --audio-format mp3 --embed-metadata --ignore-errors -o "$OUTPUT_TEMPLATE" "$url"
# Vérification du code de retour de yt-dlp
if [[ $? -eq 0 ]]; then
# ➡️ Capture de l'horodatage actuel (format YYYY-MM-JJ HH:MM:SS)
TIMESTAMP=$(date +"[%Y-%m-%d %H:%M:%S]")
# Succès : ajout de l'URL AVEC l'horodatage au fichier done
echo "$TIMESTAMP $url" >> "$FICHIER_DONE"
echo " [SUCCÈS] Ajouté à $FICHIER_DONE"
else
# Échec
echo " [ÉCHEC] Le téléchargement a échoué pour $url"
fi
echo "" # Ligne vide pour la lisibilité
done < "$FICHIER_TODO"
echo "--- Opération terminée ---"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment