#! /bin/bash # VARIABLES dir="$HOME/Téléchargements/" log="/tmp/youtubedlurl_$(date +%d-%b-%Y--%H-%M).txt" youtubedlbinary="$HOME/bin/yt-dlp" # FONCTIONS f_telechcommence(){ notify-send -i youtube "yt-dlp téléchargement commencé" "$title\n$url" ; } f_iferr(){ if grep "error" $log; then notify-send -i youtube -t 30000 "yt-dlp erreur" "$title\n$url" & zenity --text-info --width 600 --height 400 --title "yt-dlp erreur" --filename "$log" --cancel-label "Valider" exit elif grep "Error" $log; then notify-send -i youtube -t 30000 "yt-dlp erreur" "$title\n$url" & zenity --text-info --width 600 --height 400 --title "yt-dlp erreur" --filename "$log" --cancel-label "Valider" exit else notify-send -i youtube "yt-dlp téléchargement terminé" "$title\n$url" fi } ZenityPulsate () { zenity --width=600 --window-icon=~/.icons/youtube.png --title=youtube-dl --text "Téléchargement en cours..." --progress --pulsate --auto-close --no-cancel } cd "$dir" || exit # GESTION DES CHOIX choix=$(zenity --height=400 --list --title=youtubedl --hide-header --hide-column=1 --column=1 --column=2 \ 1 "Télécharger une vidéo Youtube (HD)" \ 2 "Télécharger une vidéo Youtube (SD)" \ 3 "Télécharger une vidéo (original)" \ 4 "Télécharger une musique/audio" \ 5 "Mettre à jour yt-dlp") if [ "$choix" = "1" ];then url=$(zenity --width 500 --entry --title "url à télécharger (HD)") title=$($youtubedlbinary --get-title "$url") f_telechcommence $youtubedlbinary -f 'bestvideo[height<800]' --output "%(title)s.%(ext)s" "$url" | tee $log | ZenityPulsate f_iferr elif [ "$choix" = "2" ];then url=$(zenity --width 500 --entry --title "url à télécharger (SD)") title=$($youtubedlbinary --get-title "$url") f_telechcommence $youtubedlbinary -f 'bestvideo[height<=480]+bestaudio/best[height<=480]' --output "%(title)s.%(ext)s" "$url" | tee $log | ZenityPulsate f_iferr elif [ "$choix" = "3" ];then url=$(zenity --width 500 --entry --title "url à télécharger (original)") title=$($youtubedlbinary --get-title "$url") f_telechcommence $youtubedlbinary --output "%(title)s.%(ext)s" "$url" | tee $log | ZenityPulsate f_iferr elif [ "$choix" = "4" ];then url=$(zenity --width 500 --entry --title "url à télécharger (audio)") title=$($youtubedlbinary --get-title "$url") f_telechcommence $youtubedlbinary --extract-audio --audio-format mp3 --output "%(title)s.%(ext)s" --restrict-filenames "$url" | tee $log | ZenityPulsate f_iferr elif [ "$choix" = "5" ];then return=$($youtubedlbinary --update) notify-send -t 60000 -i youtube "yt-dlp" "Mise à jour terminée\n\n$return" fi